Update the breakpoint feature
[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//
e27f08e7
JPM
8// Who When (M/D/Y) What
9// --- ------------ -----------------------------------------------------------
10// JPM 08/31/2018 Created this file
11// JPM 09/12/2018 Added a status bar and better status report
12// JPM 10/20/2018 Added the return address information in the call stack
13// JPM 08/09/2019 Prevent crash in case of call stack is out of range
14// JPM 03/16/2020 Modified the layout window and added source filename from the called source line
0718b3f2
JPM
15
16// STILL TO DO:
2b91c435 17// To set the information display at the right
8b11a1b0
JPM
18// To use DWARF frame information?
19// To check if call stack pointer is used (DWARF information?)
0718b3f2
JPM
20//
21
22#include "debugger/callstackbrowser.h"
23#include "memory.h"
24#include "debugger/DBGManager.h"
25#include "m68000/m68kinterface.h"
8b11a1b0 26#include "settings.h"
0718b3f2
JPM
27
28
2b91c435 29//
0718b3f2 30CallStackBrowserWindow::CallStackBrowserWindow(QWidget * parent/*= 0*/) : QWidget(parent, Qt::Dialog),
2b91c435
JPM
31#ifdef CS_LAYOUTTEXTS
32text(new QTextBrowser),
33#else
34TableView(new QTableView),
35model(new QStandardItemModel),
36#endif
37statusbar(new QStatusBar),
38layout(new QVBoxLayout)
0718b3f2
JPM
39{
40 setWindowTitle(tr("Call Stack"));
41
2b91c435 42 // Set the font
0718b3f2
JPM
43 QFont fixedFont("Lucida Console", 8, QFont::Normal);
44 fixedFont.setStyleHint(QFont::TypeWriter);
0718b3f2 45
2b91c435
JPM
46#ifdef CS_LAYOUTTEXTS
47 // Set original layout
48 text->setFont(fixedFont);
0718b3f2 49 layout->addWidget(text);
2b91c435
JPM
50#else
51 // Set the new layout with proper identation and readibility
e27f08e7
JPM
52 model->setColumnCount(4);
53 model->setHeaderData(0, Qt::Horizontal, QObject::tr("Function"));
2b91c435 54 model->setHeaderData(1, Qt::Horizontal, QObject::tr("Line"));
79a018fa 55 model->setHeaderData(2, Qt::Horizontal, QObject::tr("Return address"));
e27f08e7 56 model->setHeaderData(3, Qt::Horizontal, QObject::tr("Filename"));
2b91c435
JPM
57 // Information table
58 TableView->setModel(model);
59 TableView->setEditTriggers(QAbstractItemView::NoEditTriggers);
60 TableView->setShowGrid(0);
61 TableView->setFont(fixedFont);
62 TableView->verticalHeader()->setDefaultSectionSize(TableView->verticalHeader()->minimumSectionSize());
63 TableView->verticalHeader()->setDefaultAlignment(Qt::AlignRight);
64 layout->addWidget(TableView);
65#endif
66
67 // Status bar
68 layout->addWidget(statusbar);
69 setLayout(layout);
0718b3f2
JPM
70}
71
72
2b91c435 73//
0718b3f2
JPM
74CallStackBrowserWindow::~CallStackBrowserWindow(void)
75{
76}
77
78
2b91c435 79//
0718b3f2
JPM
80void CallStackBrowserWindow::RefreshContents(void)
81{
2b91c435
JPM
82 char msg[1024];
83 size_t Error = CS_NOERROR;
009df4d7 84 DBGstatus FilenameStatus;
0718b3f2 85 unsigned int a6, Sa6, ret;
e27f08e7
JPM
86 char *Name;
87 size_t NumError = 0;
2b91c435 88#ifdef CS_LAYOUTTEXTS
0718b3f2
JPM
89 QString CallStack;
90 char string[1024];
2b91c435 91#else
8b11a1b0 92 int NbRaw = 0;
2b91c435
JPM
93 QString FunctionName;
94#endif
0718b3f2
JPM
95
96 if (isVisible())
97 {
2b91c435
JPM
98#ifndef CS_LAYOUTTEXTS
99 model->setRowCount(0);
100#endif
0718b3f2
JPM
101 if ((a6 = m68k_get_reg(NULL, M68K_REG_A6)) && DBGManager_GetType())
102 {
8b11a1b0 103 while ((Sa6 = a6) && !NumError)
0718b3f2 104 {
8b11a1b0
JPM
105 if ((Sa6 >= (m68k_get_reg(NULL, M68K_REG_SP) - 4)) && (Sa6 < vjs.DRAM_size))
106 {
107 a6 = GET32(jaguarMainRAM, Sa6);
108 ret = GET32(jaguarMainRAM, Sa6 + 4);
2b91c435 109#ifdef CS_LAYOUTTEXTS
e27f08e7 110 sprintf(string, "0x%06X | Ret: 0x%06X | From: %s - 0x%06X | Line: %s", Sa6, ret, (Name = DBGManager_GetFunctionName(ret)), (unsigned int)DBGManager_GetAdrFromSymbolName(Name), DBGManager_GetLineSrcFromAdr(ret, DBG_NO_TAG));
8b11a1b0
JPM
111 CallStack += QString(string);
112 if (a6)
113 {
114 CallStack += QString("<br>");
115 }
116#else
e27f08e7 117 // insert line
8b11a1b0 118 model->insertRow(NbRaw);
e27f08e7
JPM
119 // display the function name
120 model->setItem(NbRaw, 0, new QStandardItem(QString("%1").arg((Name = DBGManager_GetFunctionName(ret)) ? Name : "(N/A)")));
121 // display the called line
122 FunctionName = QString(Name = DBGManager_GetLineSrcFromAdr(ret, DBG_NO_TAG));
aae93d86 123 //FunctionName.replace("&nbsp;", " ");
e27f08e7
JPM
124 FunctionName = FunctionName.trimmed();
125 model->setItem(NbRaw, 1, new QStandardItem(QString("%1").arg(Name ? FunctionName : "(N/A)")));
126 // display the return address
8b11a1b0 127 sprintf(msg, "0x%06X", ret);
e27f08e7
JPM
128 model->setItem(NbRaw, 2, new QStandardItem(QString("%1").arg(msg)));
129 // display the source filename from called source line
009df4d7 130 model->setItem(NbRaw++, 3, new QStandardItem(QString("%1").arg(((Name = DBGManager_GetFullSourceFilenameFromAdr(ret, &FilenameStatus)) && !FilenameStatus) ? Name : "(N/A)")));
e27f08e7 131#endif
8b11a1b0
JPM
132 }
133 else
0718b3f2 134 {
8b11a1b0 135 NumError = 0x1;
0718b3f2
JPM
136 }
137 }
2b91c435 138#ifdef CS_LAYOUTTEXTS
0718b3f2
JPM
139 text->clear();
140 text->setText(CallStack);
2b91c435 141#endif
8b11a1b0
JPM
142 switch (NumError)
143 {
144 case 0:
145 sprintf(msg, "Ready");
146 Error = CS_NOERROR;
147 break;
148
149 case 0x1:
150 sprintf(msg, "Call Stack out of range");
151 Error = CS_ERROR;
152 break;
153
154 default:
155 sprintf(msg, "Call Stack in limbo");
156 Error = CS_WARNING;
157 break;
158 }
0718b3f2
JPM
159 }
160 else
161 {
2b91c435
JPM
162 sprintf(msg, "Call Stack not available");
163 Error = CS_NOCALLSTACK;
164#ifdef CS_LAYOUTTEXTS
0718b3f2 165 text->clear();
2b91c435
JPM
166#endif
167 }
168
169 // Display status bar
170 if (Error)
171 {
172 if ((Error & CS_WARNING))
173 {
174 statusbar->setStyleSheet("background-color: lightyellow; font: bold");
175 }
176 else
177 {
178 statusbar->setStyleSheet("background-color: tomato; font: bold");
179 }
0718b3f2 180 }
2b91c435
JPM
181 else
182 {
183 statusbar->setStyleSheet("background-color: lightgreen; font: bold");
184 }
185 statusbar->showMessage(QString(msg));
0718b3f2
JPM
186 }
187}
188
189
2b91c435 190//
0718b3f2
JPM
191void CallStackBrowserWindow::keyPressEvent(QKeyEvent * e)
192{
193 if (e->key() == Qt::Key_Escape)
194 {
195 hide();
196 }
197}
198
199