Commit | Line | Data |
---|---|---|
0203b5fd JPM |
1 | //\r |
2 | // allwatchbrowser.cpp - All Watch\r | |
3 | //\r | |
4 | // by Jean-Paul Mari\r | |
5 | //\r | |
6 | // JPM = Jean-Paul Mari <djipi.mari@gmail.com>\r | |
7 | //\r | |
8 | // Who When What\r | |
9 | // --- ---------- -----------------------------------------------------------\r | |
10 | // JPM 12/07/2017 Created this file\r | |
4873fe0a | 11 | // JPM 09/14/2018 Added a status bar, better status report and set information values in a tab\r |
8d705db0 | 12 | // JPM April/2019 Added a sorting filter, tableview unique rows creation\r |
b53b74f6 | 13 | // JPM April/2021 Added a search feature.\r |
0203b5fd JPM |
14 | //\r |
15 | \r | |
16 | // STILL TO DO:\r | |
a4e46c05 | 17 | // Better presentation\r |
2b91c435 | 18 | // To set the information display at the right\r |
8d705db0 | 19 | // To understand/fix the problem with the sorting filter\r |
fe3b257d JPM |
20 | // Display arrays information\r |
21 | // Display structures information\r | |
0203b5fd JPM |
22 | //\r |
23 | \r | |
8d705db0 | 24 | //#define AW_SORTINGFILTER // Authorise the sorting filtes\r |
4873fe0a | 25 | //#define AW_DEBUGNUMVARIABLE 4415 // Set the global variable number to debug\r |
2b91c435 JPM |
26 | #ifndef AW_DEBUGNUMVARIABLE\r |
27 | #define AW_STARTNUMVARIABLE 0 // Must be kept to 0 in case of no debug is required\r | |
28 | #else\r | |
29 | #define AW_STARTNUMVARIABLE AW_DEBUGNUMVARIABLE - 1\r | |
30 | #endif\r | |
31 | \r | |
32 | \r | |
0203b5fd JPM |
33 | #include "debugger/allwatchbrowser.h"\r |
34 | #include "memory.h"\r | |
35 | #include "debugger/DBGManager.h"\r | |
36 | \r | |
37 | \r | |
a4e46c05 | 38 | // \r |
0203b5fd | 39 | AllWatchBrowserWindow::AllWatchBrowserWindow(QWidget * parent/*= 0*/) : QWidget(parent, Qt::Dialog),\r |
2b91c435 | 40 | layout(new QVBoxLayout),\r |
03458eec JPM |
41 | symbol(new QLineEdit),\r |
42 | search(new QPushButton(tr("Search"))),\r | |
2b91c435 JPM |
43 | #ifdef AW_LAYOUTTEXTS\r |
44 | text(new QTextBrowser),\r | |
45 | #else\r | |
46 | TableView(new QTableView),\r | |
47 | model(new QStandardItemModel),\r | |
48 | #endif\r | |
49 | NbWatch(0),\r | |
03458eec | 50 | CurrentWatch(0),\r |
2b91c435 JPM |
51 | statusbar(new QStatusBar),\r |
52 | PtrWatchInfo(NULL)\r | |
0203b5fd JPM |
53 | {\r |
54 | setWindowTitle(tr("All Watch"));\r | |
55 | \r | |
03458eec | 56 | // set the font\r |
0203b5fd | 57 | QFont fixedFont("Lucida Console", 8, QFont::Normal);\r |
0203b5fd | 58 | fixedFont.setStyleHint(QFont::TypeWriter);\r |
0203b5fd | 59 | \r |
2b91c435 JPM |
60 | #ifdef AW_LAYOUTTEXTS\r |
61 | // Set original layout\r | |
62 | text->setFont(fixedFont);\r | |
0203b5fd | 63 | layout->addWidget(text);\r |
2b91c435 JPM |
64 | #else\r |
65 | // Set the new layout with proper identation and readibility\r | |
66 | model->setColumnCount(3);\r | |
67 | model->setHeaderData(0, Qt::Horizontal, QObject::tr("Name"));\r | |
68 | model->setHeaderData(1, Qt::Horizontal, QObject::tr("Value"));\r | |
69 | model->setHeaderData(2, Qt::Horizontal, QObject::tr("Type"));\r | |
70 | // Information table\r | |
71 | TableView->setModel(model);\r | |
72 | TableView->setEditTriggers(QAbstractItemView::NoEditTriggers);\r | |
73 | TableView->setShowGrid(0);\r | |
74 | TableView->setFont(fixedFont);\r | |
75 | TableView->verticalHeader()->setDefaultSectionSize(TableView->verticalHeader()->minimumSectionSize());\r | |
76 | TableView->verticalHeader()->setDefaultAlignment(Qt::AlignRight);\r | |
77 | layout->addWidget(TableView);\r | |
78 | #endif\r | |
79 | \r | |
03458eec JPM |
80 | // search bar\r |
81 | QHBoxLayout * hbox1 = new QHBoxLayout;\r | |
82 | symbol->setPlaceholderText("symbol name");\r | |
83 | hbox1->addWidget(symbol);\r | |
84 | hbox1->addWidget(search);\r | |
85 | layout->addLayout(hbox1);\r | |
86 | \r | |
87 | // status bar\r | |
2b91c435 JPM |
88 | layout->addWidget(statusbar);\r |
89 | setLayout(layout);\r | |
03458eec JPM |
90 | \r |
91 | // connect slot\r | |
92 | connect(search, SIGNAL(clicked()), this, SLOT(SearchSymbol()));\r | |
93 | connect(symbol, SIGNAL(cursorPositionChanged(int, int)), this, SLOT(SelectSearchSymbol()));\r | |
0203b5fd JPM |
94 | }\r |
95 | \r | |
96 | \r | |
97 | //\r | |
98 | AllWatchBrowserWindow::~AllWatchBrowserWindow(void)\r | |
99 | {\r | |
a4e46c05 JPM |
100 | Reset();\r |
101 | }\r | |
102 | \r | |
103 | \r | |
03458eec JPM |
104 | // Search the symbol in the watch list\r |
105 | void AllWatchBrowserWindow::SearchSymbol(void) | |
106 | { | |
107 | bool found = false; | |
108 | size_t i; | |
109 | ||
110 | // user cannot enter symbol to allow the search | |
111 | symbol->setDisabled(true); | |
112 | ||
113 | // look for the symbol in the watch list | |
114 | for (i = AW_STARTNUMVARIABLE; (i < NbWatch) && !found; i++)\r | |
115 | {\r | |
116 | // check symbol presence\r | |
117 | if (!symbol->text().compare(PtrWatchInfo[i].PtrVariableName, Qt::CaseSensitive))\r | |
118 | {\r | |
119 | found = true;\r | |
120 | }\r | |
121 | }\r | |
122 | \r | |
123 | if (found)\r | |
124 | {\r | |
125 | // remove previous highlight\r | |
126 | if (CurrentWatch)\r | |
127 | {\r | |
128 | model->item((int)(CurrentWatch - 1), 0)->setBackground(QColor(255, 255, 255));\r | |
129 | model->item((int)(CurrentWatch - 1), 1)->setBackground(QColor(255, 255, 255));\r | |
130 | model->item((int)(CurrentWatch - 1), 2)->setBackground(QColor(255, 255, 255));\r | |
131 | }\r | |
132 | // Get the slider maximum position\r | |
133 | int MaxSlider = TableView->verticalScrollBar()->maximum(); \r | |
134 | // Number of items displayed in the scroll bar slider\r | |
135 | int DeltaSlider = (int)NbWatch - MaxSlider;\r | |
136 | // set the scroll bar\r | |
137 | TableView->verticalScrollBar()->setSliderPosition((int)i - (DeltaSlider / 2) - 1);\r | |
138 | // highlight watch symbol\r | |
139 | CurrentWatch = i;\r | |
140 | model->item((int)(CurrentWatch - 1), 0)->setBackground(QColor(0xff, 0xfa, 0xcd));\r | |
141 | model->item((int)(CurrentWatch - 1), 1)->setBackground(QColor(0xff, 0xfa, 0xcd));\r | |
142 | model->item((int)(CurrentWatch - 1), 2)->setBackground(QColor(0xff, 0xfa, 0xcd));\r | |
143 | // allow new symbol\r | |
144 | symbol->setText("");\r | |
145 | }\r | |
146 | else\r | |
147 | {\r | |
148 | // invalid symbol\r | |
149 | symbol->setStyleSheet("color: red");\r | |
150 | }\r | |
151 | ||
152 | // user can enter a symbol | |
153 | symbol->setEnabled(true); | |
154 | symbol->setFocus(); | |
155 | } | |
156 | ||
157 | ||
158 | // | |
159 | void AllWatchBrowserWindow::SelectSearchSymbol(void)\r | |
160 | {\r | |
161 | symbol->setStyleSheet("color: black");\r | |
162 | }\r | |
163 | \r | |
164 | \r | |
a4e46c05 JPM |
165 | //\r |
166 | void AllWatchBrowserWindow::Reset(void)\r | |
167 | {\r | |
0203b5fd | 168 | free(PtrWatchInfo);\r |
a4e46c05 JPM |
169 | NbWatch = 0;\r |
170 | PtrWatchInfo = NULL;\r | |
0203b5fd JPM |
171 | }\r |
172 | \r | |
173 | \r | |
174 | //\r | |
175 | void AllWatchBrowserWindow::RefreshContents(void)\r | |
176 | {\r | |
2b91c435 JPM |
177 | char msg[100];\r |
178 | #ifdef AW_LAYOUTTEXTS\r | |
0203b5fd | 179 | char string[1024];\r |
2b91c435 | 180 | #endif\r |
0203b5fd | 181 | QString WatchAll;\r |
2b91c435 JPM |
182 | size_t Error = AW_NOERROR;\r |
183 | char *PtrValue;\r | |
0203b5fd JPM |
184 | \r |
185 | if (isVisible())\r | |
186 | {\r | |
187 | if (!NbWatch)\r | |
188 | {\r | |
2b91c435 | 189 | // Pre-catch the information for each global variables\r |
0203b5fd JPM |
190 | if (NbWatch = DBGManager_GetNbGlobalVariables())\r |
191 | {\r | |
192 | PtrWatchInfo = (WatchInfo *)calloc(NbWatch, sizeof(WatchInfo));\r | |
8d705db0 JPM |
193 | #ifndef AW_LAYOUTTEXTS\r |
194 | #ifdef AW_SORTINGFILTER\r | |
195 | TableView->setSortingEnabled(false);\r | |
196 | #endif\r | |
197 | model->setRowCount(0);\r | |
198 | #endif\r | |
2b91c435 | 199 | for (uint32_t i = AW_STARTNUMVARIABLE; i < NbWatch; i++)\r |
0203b5fd JPM |
200 | {\r |
201 | PtrWatchInfo[i].PtrVariableName = DBGManager_GetGlobalVariableName(i + 1);\r | |
0203b5fd | 202 | PtrWatchInfo[i].TypeTag = DBGManager_GetGlobalVariableTypeTag(i + 1);\r |
2b91c435 JPM |
203 | #ifdef AW_LAYOUTTEXTS\r |
204 | PtrWatchInfo[i].addr = DBGManager_GetGlobalVariableAdr(i + 1);\r | |
0203b5fd JPM |
205 | if (!strlen(PtrWatchInfo[i].PtrVariableBaseTypeName = DBGManager_GetGlobalVariableTypeName(i + 1)))\r |
206 | {\r | |
207 | PtrWatchInfo[i].PtrVariableBaseTypeName = (char *)"<font color='#ff0000'>N/A</font>";\r | |
208 | }\r | |
2b91c435 JPM |
209 | #else\r |
210 | PtrWatchInfo[i].PtrVariableBaseTypeName = DBGManager_GetGlobalVariableTypeName(i + 1);\r | |
8d705db0 | 211 | model->insertRow(i);\r |
2b91c435 | 212 | #endif\r |
0203b5fd JPM |
213 | }\r |
214 | }\r | |
215 | }\r | |
8d705db0 | 216 | \r |
2b91c435 | 217 | if (NbWatch)\r |
0203b5fd | 218 | {\r |
2b91c435 | 219 | for (uint32_t i = AW_STARTNUMVARIABLE; i < NbWatch; i++)\r |
0203b5fd | 220 | {\r |
2b91c435 JPM |
221 | if ((PtrWatchInfo[i].TypeTag & (DBG_TAG_TYPE_array | DBG_TAG_TYPE_structure)))\r |
222 | {\r | |
223 | #if defined(AW_SUPPORTARRAY) || defined(AW_SUPPORTSTRUCTURE)\r | |
224 | //PtrValue = (char *)memcpy(Value, &jaguarMainRAM[PtrWatchInfo[i].addr], 20);\r | |
225 | PtrValue = NULL;\r | |
226 | #else\r | |
227 | PtrValue = NULL;\r | |
228 | #endif\r | |
229 | }\r | |
230 | else\r | |
231 | {\r | |
232 | PtrValue = DBGManager_GetGlobalVariableValue(i + 1);\r | |
233 | }\r | |
234 | #ifdef AW_LAYOUTTEXTS\r | |
235 | if (i)\r | |
236 | {\r | |
237 | WatchAll += QString("<br>");\r | |
238 | }\r | |
239 | 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>");\r | |
0203b5fd | 240 | WatchAll += QString(string);\r |
2b91c435 | 241 | #else\r |
2b91c435 JPM |
242 | model->setItem(i, 0, new QStandardItem(QString("%1").arg(PtrWatchInfo[i].PtrVariableName)));\r |
243 | model->setItem(i, 1, new QStandardItem(QString("%1").arg(PtrValue)));\r | |
244 | model->setItem(i, 2, new QStandardItem(QString("%1").arg(PtrWatchInfo[i].PtrVariableBaseTypeName)));\r | |
245 | #endif\r | |
0203b5fd | 246 | }\r |
2b91c435 JPM |
247 | #ifdef AW_LAYOUTTEXTS\r |
248 | text->clear();\r | |
249 | text->setText(WatchAll);\r | |
4873fe0a | 250 | #else\r |
8d705db0 | 251 | #ifdef AW_SORTINGFILTER\r |
4873fe0a | 252 | TableView->setSortingEnabled(true);\r |
8d705db0 | 253 | #endif\r |
2b91c435 JPM |
254 | #endif\r |
255 | sprintf(msg, "Ready");\r | |
256 | }\r | |
257 | else\r | |
258 | {\r | |
259 | sprintf(msg, "No watches");\r | |
260 | Error = AW_NOALLWATCH;\r | |
0203b5fd JPM |
261 | }\r |
262 | \r | |
2b91c435 JPM |
263 | // Display status bar\r |
264 | if (Error)\r | |
265 | {\r | |
266 | if ((Error & AW_WARNING))\r | |
267 | {\r | |
268 | statusbar->setStyleSheet("background-color: lightyellow; font: bold");\r | |
269 | }\r | |
270 | else\r | |
271 | {\r | |
272 | statusbar->setStyleSheet("background-color: tomato; font: bold");\r | |
273 | }\r | |
274 | }\r | |
275 | else\r | |
276 | {\r | |
277 | statusbar->setStyleSheet("background-color: lightgreen; font: bold");\r | |
278 | }\r | |
279 | statusbar->showMessage(QString(msg));\r | |
0203b5fd JPM |
280 | }\r |
281 | }\r | |
282 | \r | |
283 | \r | |
03458eec | 284 | // Handle keyboard event\r |
0203b5fd JPM |
285 | void AllWatchBrowserWindow::keyPressEvent(QKeyEvent * e)\r |
286 | {\r | |
03458eec | 287 | // ESC to close / hide the window\r |
0203b5fd | 288 | if (e->key() == Qt::Key_Escape)\r |
0203b5fd | 289 | {\r |
a4e46c05 | 290 | hide();\r |
0203b5fd | 291 | }\r |
03458eec JPM |
292 | else\r |
293 | {\r | |
294 | // select the \r | |
295 | if (e->key() == Qt::Key_Return)\r | |
296 | {\r | |
297 | SearchSymbol();\r | |
298 | }\r | |
299 | }\r | |
0203b5fd | 300 | }\r |
0203b5fd | 301 | \r |