40d8e13001e43d75b77774622a8d5023eb98ad9e
2 // callstackbrowser.cpp - Call Stack
6 // JPM = Jean-Paul Mari <djipi.mari@gmail.com>
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
17 // To set the information display at the right
18 // To use DWARF frame information?
19 // To check if call stack pointer is used (DWARF information?)
22 #include "debugger/callstackbrowser.h"
24 #include "debugger/DBGManager.h"
25 #include "m68000/m68kinterface.h"
30 CallStackBrowserWindow::CallStackBrowserWindow(QWidget
* parent
/*= 0*/) : QWidget(parent
, Qt::Dialog
),
32 text(new QTextBrowser
),
34 TableView(new QTableView
),
35 model(new QStandardItemModel
),
37 statusbar(new QStatusBar
),
38 layout(new QVBoxLayout
)
40 setWindowTitle(tr("Call Stack"));
43 QFont
fixedFont("Lucida Console", 8, QFont::Normal
);
44 fixedFont
.setStyleHint(QFont::TypeWriter
);
47 // Set original layout
48 text
->setFont(fixedFont
);
49 layout
->addWidget(text
);
51 // Set the new layout with proper identation and readibility
52 model
->setColumnCount(4);
53 model
->setHeaderData(0, Qt::Horizontal
, QObject::tr("Function"));
54 model
->setHeaderData(1, Qt::Horizontal
, QObject::tr("Line"));
55 model
->setHeaderData(2, Qt::Horizontal
, QObject::tr("Return address"));
56 model
->setHeaderData(3, Qt::Horizontal
, QObject::tr("Filename"));
58 TableView
->setModel(model
);
59 TableView
->setEditTriggers(QAbstractItemView::NoEditTriggers
);
60 TableView
->setShowGrid(0);
61 TableView
->setFont(fixedFont
);
62 TableView
->verticalHeader()->setDefaultSectionSize(TableView
->verticalHeader()->minimumSectionSize());
63 TableView
->verticalHeader()->setDefaultAlignment(Qt::AlignRight
);
64 layout
->addWidget(TableView
);
68 layout
->addWidget(statusbar
);
74 CallStackBrowserWindow::~CallStackBrowserWindow(void)
80 void CallStackBrowserWindow::RefreshContents(void)
83 size_t Error
= CS_NOERROR
;
84 DBGstatus FilenameStatus
;
85 unsigned int a6
, Sa6
, ret
;
98 #ifndef CS_LAYOUTTEXTS
99 model
->setRowCount(0);
101 if ((a6
= m68k_get_reg(NULL
, M68K_REG_A6
)) && DBGManager_GetType())
103 while ((Sa6
= a6
) && !NumError
)
105 if ((Sa6
>= (m68k_get_reg(NULL
, M68K_REG_SP
) - 4)) && (Sa6
< vjs
.DRAM_size
))
107 a6
= GET32(jaguarMainRAM
, Sa6
);
108 ret
= GET32(jaguarMainRAM
, Sa6
+ 4);
109 #ifdef CS_LAYOUTTEXTS
110 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
));
111 CallStack
+= QString(string
);
114 CallStack
+= QString("<br>");
118 model
->insertRow(NbRaw
);
119 // display the function name
120 model
->setItem(NbRaw
, 0, new QStandardItem(QString("%1").arg((Name
= DBGManager_GetFunctionName(ret
)) ? Name
: "(N/A)")));
121 // display the called line
122 FunctionName
= QString(Name
= DBGManager_GetLineSrcFromAdr(ret
, DBG_NO_TAG
));
123 //FunctionName.replace(" ", " ");
124 FunctionName
= FunctionName
.trimmed();
125 model
->setItem(NbRaw
, 1, new QStandardItem(QString("%1").arg(Name
? FunctionName
: "(N/A)")));
126 // display the return address
127 sprintf(msg
, "0x%06X", ret
);
128 model
->setItem(NbRaw
, 2, new QStandardItem(QString("%1").arg(msg
)));
129 // display the source filename from called source line
130 model
->setItem(NbRaw
++, 3, new QStandardItem(QString("%1").arg(((Name
= DBGManager_GetFullSourceFilenameFromAdr(ret
, &FilenameStatus
)) && !FilenameStatus
) ? Name
: "(N/A)")));
138 #ifdef CS_LAYOUTTEXTS
140 text
->setText(CallStack
);
145 sprintf(msg
, "Ready");
150 sprintf(msg
, "Call Stack out of range");
155 sprintf(msg
, "Call Stack in limbo");
162 sprintf(msg
, "Call Stack not available");
163 Error
= CS_NOCALLSTACK
;
164 #ifdef CS_LAYOUTTEXTS
169 // Display status bar
172 if ((Error
& CS_WARNING
))
174 statusbar
->setStyleSheet("background-color: lightyellow; font: bold");
178 statusbar
->setStyleSheet("background-color: tomato; font: bold");
183 statusbar
->setStyleSheet("background-color: lightgreen; font: bold");
185 statusbar
->showMessage(QString(msg
));
191 void CallStackBrowserWindow::keyPressEvent(QKeyEvent
* e
)
193 if (e
->key() == Qt::Key_Escape
)