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