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