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