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