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