Added the return address information in the call stack
[clinton/Virtual-Jaguar-Rx.git] / src / debugger / callstackbrowser.cpp
CommitLineData
0718b3f2
JPM
1//
2// callstackbrowser.cpp - Call Stack
3//
4// by Jean-Paul Mari
5//
6// JPM = Jean-Paul Mari <djipi.mari@gmail.com>
7//
8// Who When What
9// --- ---------- -----------------------------------------------------------
10// JPM 08/31/2018 Created this file
2b91c435 11// JPM 09/12/2018 Added a status bar and better status report
79a018fa 12// JPM 10/20/2018 Added the return address information in the call stack
0718b3f2
JPM
13
14// STILL TO DO:
2b91c435 15// To set the information display at the right
0718b3f2
JPM
16// To use DWARF frame information
17//
18
19#include "debugger/callstackbrowser.h"
20#include "memory.h"
21#include "debugger/DBGManager.h"
22#include "m68000/m68kinterface.h"
23
24
2b91c435 25//
0718b3f2 26CallStackBrowserWindow::CallStackBrowserWindow(QWidget * parent/*= 0*/) : QWidget(parent, Qt::Dialog),
2b91c435
JPM
27#ifdef CS_LAYOUTTEXTS
28text(new QTextBrowser),
29#else
30TableView(new QTableView),
31model(new QStandardItemModel),
32#endif
33statusbar(new QStatusBar),
34layout(new QVBoxLayout)
0718b3f2
JPM
35{
36 setWindowTitle(tr("Call Stack"));
37
2b91c435 38 // Set the font
0718b3f2
JPM
39 QFont fixedFont("Lucida Console", 8, QFont::Normal);
40 fixedFont.setStyleHint(QFont::TypeWriter);
0718b3f2 41
2b91c435
JPM
42#ifdef CS_LAYOUTTEXTS
43 // Set original layout
44 text->setFont(fixedFont);
0718b3f2 45 layout->addWidget(text);
2b91c435
JPM
46#else
47 // Set the new layout with proper identation and readibility
79a018fa 48 model->setColumnCount(3);
2b91c435
JPM
49 model->setHeaderData(0, Qt::Horizontal, QObject::tr("Name"));
50 model->setHeaderData(1, Qt::Horizontal, QObject::tr("Line"));
79a018fa 51 model->setHeaderData(2, Qt::Horizontal, QObject::tr("Return address"));
2b91c435
JPM
52 // Information table
53 TableView->setModel(model);
54 TableView->setEditTriggers(QAbstractItemView::NoEditTriggers);
55 TableView->setShowGrid(0);
56 TableView->setFont(fixedFont);
57 TableView->verticalHeader()->setDefaultSectionSize(TableView->verticalHeader()->minimumSectionSize());
58 TableView->verticalHeader()->setDefaultAlignment(Qt::AlignRight);
59 layout->addWidget(TableView);
60#endif
61
62 // Status bar
63 layout->addWidget(statusbar);
64 setLayout(layout);
0718b3f2
JPM
65}
66
67
2b91c435 68//
0718b3f2
JPM
69CallStackBrowserWindow::~CallStackBrowserWindow(void)
70{
71}
72
73
2b91c435 74//
0718b3f2
JPM
75void CallStackBrowserWindow::RefreshContents(void)
76{
2b91c435
JPM
77 char msg[1024];
78 size_t Error = CS_NOERROR;
0718b3f2
JPM
79 unsigned int a6, Sa6, ret;
80 char *FuncName;
2b91c435 81#ifdef CS_LAYOUTTEXTS
0718b3f2
JPM
82 QString CallStack;
83 char string[1024];
2b91c435
JPM
84#else
85 size_t NbRaw = 0;
86 QString FunctionName;
87#endif
0718b3f2
JPM
88
89 if (isVisible())
90 {
2b91c435
JPM
91#ifndef CS_LAYOUTTEXTS
92 model->setRowCount(0);
93#endif
0718b3f2
JPM
94 if ((a6 = m68k_get_reg(NULL, M68K_REG_A6)) && DBGManager_GetType())
95 {
96 while ((Sa6 = a6))
97 {
98 a6 = GET32(jaguarMainRAM, Sa6);
99 ret = GET32(jaguarMainRAM, Sa6 + 4);
2b91c435
JPM
100#ifdef CS_LAYOUTTEXTS
101 sprintf(string, "0x%06X | Ret: 0x%06X | From: %s - 0x%06X | Line: %s", Sa6, ret, (FuncName = DBGManager_GetFunctionName(ret)), (unsigned int)DBGManager_GetAdrFromSymbolName(FuncName), DBGManager_GetLineSrcFromAdr(ret, DBG_NO_TAG));
0718b3f2
JPM
102 CallStack += QString(string);
103 if (a6)
104 {
2b91c435 105 CallStack += QString("<br>");
0718b3f2 106 }
2b91c435
JPM
107#else
108 model->insertRow(NbRaw);
79a018fa 109 model->setItem(NbRaw, 0, new QStandardItem(QString("%1").arg((FuncName = DBGManager_GetFunctionName(ret)) ? FuncName : "(N/A)")));
2b91c435
JPM
110 FunctionName = QString(FuncName = DBGManager_GetLineSrcFromAdr(ret, DBG_NO_TAG));
111 FunctionName.replace("&nbsp;", " ");
79a018fa
JPM
112 model->setItem(NbRaw, 1, new QStandardItem(QString("%1").arg(FuncName ? FunctionName : "(N/A)")));
113 sprintf(msg, "0x%06X", ret);
114 model->setItem(NbRaw++, 2, new QStandardItem(QString("%1").arg(msg)));
2b91c435 115#endif
0718b3f2 116 }
2b91c435 117#ifdef CS_LAYOUTTEXTS
0718b3f2
JPM
118 text->clear();
119 text->setText(CallStack);
2b91c435
JPM
120#endif
121 sprintf(msg, "Ready");
122 Error = CS_NOERROR;
0718b3f2
JPM
123 }
124 else
125 {
2b91c435
JPM
126 sprintf(msg, "Call Stack not available");
127 Error = CS_NOCALLSTACK;
128#ifdef CS_LAYOUTTEXTS
0718b3f2 129 text->clear();
2b91c435
JPM
130#endif
131 }
132
133 // Display status bar
134 if (Error)
135 {
136 if ((Error & CS_WARNING))
137 {
138 statusbar->setStyleSheet("background-color: lightyellow; font: bold");
139 }
140 else
141 {
142 statusbar->setStyleSheet("background-color: tomato; font: bold");
143 }
0718b3f2 144 }
2b91c435
JPM
145 else
146 {
147 statusbar->setStyleSheet("background-color: lightgreen; font: bold");
148 }
149 statusbar->showMessage(QString(msg));
0718b3f2
JPM
150 }
151}
152
153
2b91c435 154//
0718b3f2
JPM
155void CallStackBrowserWindow::keyPressEvent(QKeyEvent * e)
156{
157 if (e->key() == Qt::Key_Escape)
158 {
159 hide();
160 }
161}
162
163