Added a #line in the call stack browser window
[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
418240cd 52 model->setColumnCount(5);
e27f08e7 53 model->setHeaderData(0, Qt::Horizontal, QObject::tr("Function"));
418240cd
JPM
54 model->setHeaderData(1, Qt::Horizontal, QObject::tr("#Line"));
55 model->setHeaderData(2, Qt::Horizontal, QObject::tr("Line"));
56 model->setHeaderData(3, Qt::Horizontal, QObject::tr("Return address"));
57 model->setHeaderData(4, Qt::Horizontal, QObject::tr("Filename"));
2b91c435
JPM
58 // Information table
59 TableView->setModel(model);
60 TableView->setEditTriggers(QAbstractItemView::NoEditTriggers);
61 TableView->setShowGrid(0);
62 TableView->setFont(fixedFont);
63 TableView->verticalHeader()->setDefaultSectionSize(TableView->verticalHeader()->minimumSectionSize());
64 TableView->verticalHeader()->setDefaultAlignment(Qt::AlignRight);
65 layout->addWidget(TableView);
66#endif
67
68 // Status bar
69 layout->addWidget(statusbar);
70 setLayout(layout);
0718b3f2
JPM
71}
72
73
2b91c435 74//
0718b3f2
JPM
75CallStackBrowserWindow::~CallStackBrowserWindow(void)
76{
77}
78
79
2b91c435 80//
0718b3f2
JPM
81void CallStackBrowserWindow::RefreshContents(void)
82{
2b91c435
JPM
83 char msg[1024];
84 size_t Error = CS_NOERROR;
009df4d7 85 DBGstatus FilenameStatus;
0718b3f2 86 unsigned int a6, Sa6, ret;
e27f08e7
JPM
87 char *Name;
88 size_t NumError = 0;
2b91c435 89#ifdef CS_LAYOUTTEXTS
0718b3f2
JPM
90 QString CallStack;
91 char string[1024];
2b91c435 92#else
8b11a1b0 93 int NbRaw = 0;
2b91c435
JPM
94 QString FunctionName;
95#endif
0718b3f2
JPM
96
97 if (isVisible())
98 {
2b91c435
JPM
99#ifndef CS_LAYOUTTEXTS
100 model->setRowCount(0);
101#endif
0718b3f2
JPM
102 if ((a6 = m68k_get_reg(NULL, M68K_REG_A6)) && DBGManager_GetType())
103 {
8b11a1b0 104 while ((Sa6 = a6) && !NumError)
0718b3f2 105 {
8b11a1b0
JPM
106 if ((Sa6 >= (m68k_get_reg(NULL, M68K_REG_SP) - 4)) && (Sa6 < vjs.DRAM_size))
107 {
108 a6 = GET32(jaguarMainRAM, Sa6);
109 ret = GET32(jaguarMainRAM, Sa6 + 4);
2b91c435 110#ifdef CS_LAYOUTTEXTS
e27f08e7 111 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
112 CallStack += QString(string);
113 if (a6)
114 {
115 CallStack += QString("<br>");
116 }
117#else
e27f08e7 118 // insert line
8b11a1b0 119 model->insertRow(NbRaw);
e27f08e7
JPM
120 // display the function name
121 model->setItem(NbRaw, 0, new QStandardItem(QString("%1").arg((Name = DBGManager_GetFunctionName(ret)) ? Name : "(N/A)")));
418240cd
JPM
122 // display the line number
123 sprintf(msg, "%zi", DBGManager_GetNumLineFromAdr(ret, DBG_NO_TAG));
124 model->setItem(NbRaw, 1, new QStandardItem(QString("%1").arg((msg[0] != '0') ? msg : "(N/A)")));
e27f08e7
JPM
125 // display the called line
126 FunctionName = QString(Name = DBGManager_GetLineSrcFromAdr(ret, DBG_NO_TAG));
aae93d86 127 //FunctionName.replace("&nbsp;", " ");
e27f08e7 128 FunctionName = FunctionName.trimmed();
418240cd 129 model->setItem(NbRaw, 2, new QStandardItem(QString("%1").arg(Name ? FunctionName : "(N/A)")));
e27f08e7 130 // display the return address
8b11a1b0 131 sprintf(msg, "0x%06X", ret);
418240cd 132 model->setItem(NbRaw, 3, new QStandardItem(QString("%1").arg(msg)));
e27f08e7 133 // display the source filename from called source line
418240cd 134 model->setItem(NbRaw++, 4, new QStandardItem(QString("%1").arg(((Name = DBGManager_GetFullSourceFilenameFromAdr(ret, &FilenameStatus)) && !FilenameStatus) ? Name : "(N/A)")));
e27f08e7 135#endif
8b11a1b0
JPM
136 }
137 else
0718b3f2 138 {
8b11a1b0 139 NumError = 0x1;
0718b3f2
JPM
140 }
141 }
2b91c435 142#ifdef CS_LAYOUTTEXTS
0718b3f2
JPM
143 text->clear();
144 text->setText(CallStack);
2b91c435 145#endif
8b11a1b0
JPM
146 switch (NumError)
147 {
148 case 0:
149 sprintf(msg, "Ready");
150 Error = CS_NOERROR;
151 break;
152
153 case 0x1:
154 sprintf(msg, "Call Stack out of range");
155 Error = CS_ERROR;
156 break;
157
158 default:
159 sprintf(msg, "Call Stack in limbo");
160 Error = CS_WARNING;
161 break;
162 }
0718b3f2
JPM
163 }
164 else
165 {
2b91c435
JPM
166 sprintf(msg, "Call Stack not available");
167 Error = CS_NOCALLSTACK;
168#ifdef CS_LAYOUTTEXTS
0718b3f2 169 text->clear();
2b91c435
JPM
170#endif
171 }
172
173 // Display status bar
174 if (Error)
175 {
176 if ((Error & CS_WARNING))
177 {
178 statusbar->setStyleSheet("background-color: lightyellow; font: bold");
179 }
180 else
181 {
182 statusbar->setStyleSheet("background-color: tomato; font: bold");
183 }
0718b3f2 184 }
2b91c435
JPM
185 else
186 {
187 statusbar->setStyleSheet("background-color: lightgreen; font: bold");
188 }
189 statusbar->showMessage(QString(msg));
0718b3f2
JPM
190 }
191}
192
193
2b91c435 194//
0718b3f2
JPM
195void CallStackBrowserWindow::keyPressEvent(QKeyEvent * e)
196{
197 if (e->key() == Qt::Key_Escape)
198 {
199 hide();
200 }
201}
202
203