Minor cosmetic and comments modifications
[clinton/Virtual-Jaguar-Rx.git] / src / debugger / allwatchbrowser.cpp
1 //
2 // allwatchbrowser.cpp - All Watch
3 //
4 // by Jean-Paul Mari
5 //
6 // JPM = Jean-Paul Mari <djipi.mari@gmail.com>
7 //
8 // Who When What
9 // --- ---------- -----------------------------------------------------------
10 // JPM 12/07/2017 Created this file
11 // JPM 09/14/2018 Added a status bar, better status report and set information values in a tab
12 // JPM 10/05/2018 Added a sorting filter
13 //
14
15 // STILL TO DO:
16 // Better presentation
17 // To set the information display at the right
18 // Display arrays information
19 // Display structures information
20 //
21
22 //#define AW_DEBUGNUMVARIABLE 4415 // Set the global variable number to debug
23 #ifndef AW_DEBUGNUMVARIABLE
24 #define AW_STARTNUMVARIABLE 0 // Must be kept to 0 in case of no debug is required
25 #else
26 #define AW_STARTNUMVARIABLE AW_DEBUGNUMVARIABLE - 1
27 #endif
28
29
30 #include "debugger/allwatchbrowser.h"
31 #include "memory.h"
32 #include "debugger/DBGManager.h"
33
34
35 //
36 AllWatchBrowserWindow::AllWatchBrowserWindow(QWidget * parent/*= 0*/) : QWidget(parent, Qt::Dialog),
37 layout(new QVBoxLayout),
38 #ifdef AW_LAYOUTTEXTS
39 text(new QTextBrowser),
40 #else
41 TableView(new QTableView),
42 model(new QStandardItemModel),
43 #endif
44 NbWatch(0),
45 statusbar(new QStatusBar),
46 PtrWatchInfo(NULL)
47 {
48 setWindowTitle(tr("All Watch"));
49
50 // Set the font
51 QFont fixedFont("Lucida Console", 8, QFont::Normal);
52 fixedFont.setStyleHint(QFont::TypeWriter);
53
54 #ifdef AW_LAYOUTTEXTS
55 // Set original layout
56 text->setFont(fixedFont);
57 layout->addWidget(text);
58 #else
59 // Set the new layout with proper identation and readibility
60 model->setColumnCount(3);
61 model->setHeaderData(0, Qt::Horizontal, QObject::tr("Name"));
62 model->setHeaderData(1, Qt::Horizontal, QObject::tr("Value"));
63 model->setHeaderData(2, Qt::Horizontal, QObject::tr("Type"));
64 // Information table
65 TableView->setModel(model);
66 TableView->setEditTriggers(QAbstractItemView::NoEditTriggers);
67 TableView->setShowGrid(0);
68 TableView->setFont(fixedFont);
69 TableView->verticalHeader()->setDefaultSectionSize(TableView->verticalHeader()->minimumSectionSize());
70 TableView->verticalHeader()->setDefaultAlignment(Qt::AlignRight);
71 layout->addWidget(TableView);
72 #endif
73
74 // Status bar
75 layout->addWidget(statusbar);
76 setLayout(layout);
77 }
78
79
80 //
81 AllWatchBrowserWindow::~AllWatchBrowserWindow(void)
82 {
83 Reset();
84 }
85
86
87 //
88 void AllWatchBrowserWindow::Reset(void)
89 {
90 free(PtrWatchInfo);
91 NbWatch = 0;
92 PtrWatchInfo = NULL;
93 }
94
95
96 //
97 void AllWatchBrowserWindow::RefreshContents(void)
98 {
99 char msg[100];
100 #ifdef AW_LAYOUTTEXTS
101 char string[1024];
102 #endif
103 QString WatchAll;
104 size_t Error = AW_NOERROR;
105 char *PtrValue;
106
107 if (isVisible())
108 {
109 if (!NbWatch)
110 {
111 // Pre-catch the information for each global variables
112 if (NbWatch = DBGManager_GetNbGlobalVariables())
113 {
114 PtrWatchInfo = (WatchInfo *)calloc(NbWatch, sizeof(WatchInfo));
115
116 for (uint32_t i = AW_STARTNUMVARIABLE; i < NbWatch; i++)
117 {
118 PtrWatchInfo[i].PtrVariableName = DBGManager_GetGlobalVariableName(i + 1);
119 PtrWatchInfo[i].TypeTag = DBGManager_GetGlobalVariableTypeTag(i + 1);
120 #ifdef AW_LAYOUTTEXTS
121 PtrWatchInfo[i].addr = DBGManager_GetGlobalVariableAdr(i + 1);
122 if (!strlen(PtrWatchInfo[i].PtrVariableBaseTypeName = DBGManager_GetGlobalVariableTypeName(i + 1)))
123 {
124 PtrWatchInfo[i].PtrVariableBaseTypeName = (char *)"<font color='#ff0000'>N/A</font>";
125 }
126 #else
127 PtrWatchInfo[i].PtrVariableBaseTypeName = DBGManager_GetGlobalVariableTypeName(i + 1);
128 #endif
129 }
130 }
131 }
132 #ifndef AW_LAYOUTTEXTS
133 TableView->setSortingEnabled(false);
134 model->setRowCount(0);
135 #endif
136 if (NbWatch)
137 {
138 for (uint32_t i = AW_STARTNUMVARIABLE; i < NbWatch; i++)
139 {
140 if ((PtrWatchInfo[i].TypeTag & (DBG_TAG_TYPE_array | DBG_TAG_TYPE_structure)))
141 {
142 #if defined(AW_SUPPORTARRAY) || defined(AW_SUPPORTSTRUCTURE)
143 //PtrValue = (char *)memcpy(Value, &jaguarMainRAM[PtrWatchInfo[i].addr], 20);
144 PtrValue = NULL;
145 #else
146 PtrValue = NULL;
147 #endif
148 }
149 else
150 {
151 PtrValue = DBGManager_GetGlobalVariableValue(i + 1);
152 }
153 #ifdef AW_LAYOUTTEXTS
154 if (i)
155 {
156 WatchAll += QString("<br>");
157 }
158 sprintf(string, "%i : %s | %s | 0x%06X | %s", (i + 1), PtrWatchInfo[i].PtrVariableBaseTypeName, PtrWatchInfo[i].PtrVariableName, (unsigned int)PtrWatchInfo[i].addr, PtrValue ? PtrValue : (char *)"<font color='#ff0000'>N/A</font>");
159 WatchAll += QString(string);
160 #else
161 model->insertRow(i);
162 model->setItem(i, 0, new QStandardItem(QString("%1").arg(PtrWatchInfo[i].PtrVariableName)));
163 model->setItem(i, 1, new QStandardItem(QString("%1").arg(PtrValue)));
164 model->setItem(i, 2, new QStandardItem(QString("%1").arg(PtrWatchInfo[i].PtrVariableBaseTypeName)));
165 #endif
166 }
167 #ifdef AW_LAYOUTTEXTS
168 text->clear();
169 text->setText(WatchAll);
170 #else
171 TableView->setSortingEnabled(true);
172 #endif
173 sprintf(msg, "Ready");
174 }
175 else
176 {
177 sprintf(msg, "No watches");
178 Error = AW_NOALLWATCH;
179 }
180
181 // Display status bar
182 if (Error)
183 {
184 if ((Error & AW_WARNING))
185 {
186 statusbar->setStyleSheet("background-color: lightyellow; font: bold");
187 }
188 else
189 {
190 statusbar->setStyleSheet("background-color: tomato; font: bold");
191 }
192 }
193 else
194 {
195 statusbar->setStyleSheet("background-color: lightgreen; font: bold");
196 }
197 statusbar->showMessage(QString(msg));
198 }
199 }
200
201
202 //
203 void AllWatchBrowserWindow::keyPressEvent(QKeyEvent * e)
204 {
205 if (e->key() == Qt::Key_Escape)
206 {
207 hide();
208 }
209 }
210