2 // allwatchbrowser.cpp - All Watch
6 // JPM = Jean-Paul Mari <djipi.mari@gmail.com>
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 // JPM April/2021 Added a search feature.
17 // Better presentation
18 // To set the information display at the right
19 // To understand/fix the problem with the sorting filter
20 // Display arrays information
21 // Display structures information
24 //#define AW_SORTINGFILTER // Authorise the sorting filtes
25 //#define AW_DEBUGNUMVARIABLE 4415 // Set the global variable number to debug
26 #ifndef AW_DEBUGNUMVARIABLE
27 #define AW_STARTNUMVARIABLE 0 // Must be kept to 0 in case of no debug is required
29 #define AW_STARTNUMVARIABLE AW_DEBUGNUMVARIABLE - 1
33 #include "debugger/allwatchbrowser.h"
35 #include "debugger/DBGManager.h"
39 AllWatchBrowserWindow::AllWatchBrowserWindow(QWidget
* parent
/*= 0*/) : QWidget(parent
, Qt::Dialog
),
40 layout(new QVBoxLayout
),
41 symbol(new QLineEdit
),
42 search(new QPushButton(tr("Search"))),
44 text(new QTextBrowser
),
46 TableView(new QTableView
),
47 model(new QStandardItemModel
),
51 statusbar(new QStatusBar
),
54 setWindowTitle(tr("All Watch"));
57 QFont
fixedFont("Lucida Console", 8, QFont::Normal
);
58 fixedFont
.setStyleHint(QFont::TypeWriter
);
61 // Set original layout
62 text
->setFont(fixedFont
);
63 layout
->addWidget(text
);
65 // Set the new layout with proper identation and readibility
66 model
->setColumnCount(3);
67 model
->setHeaderData(0, Qt::Horizontal
, QObject::tr("Name"));
68 model
->setHeaderData(1, Qt::Horizontal
, QObject::tr("Value"));
69 model
->setHeaderData(2, Qt::Horizontal
, QObject::tr("Type"));
71 TableView
->setModel(model
);
72 TableView
->setEditTriggers(QAbstractItemView::NoEditTriggers
);
73 TableView
->setShowGrid(0);
74 TableView
->setFont(fixedFont
);
75 TableView
->verticalHeader()->setDefaultSectionSize(TableView
->verticalHeader()->minimumSectionSize());
76 TableView
->verticalHeader()->setDefaultAlignment(Qt::AlignRight
);
77 layout
->addWidget(TableView
);
81 QHBoxLayout
* hbox1
= new QHBoxLayout
;
82 symbol
->setPlaceholderText("symbol name");
83 hbox1
->addWidget(symbol
);
84 hbox1
->addWidget(search
);
85 layout
->addLayout(hbox1
);
88 layout
->addWidget(statusbar
);
92 connect(search
, SIGNAL(clicked()), this, SLOT(SearchSymbol()));
93 connect(symbol
, SIGNAL(cursorPositionChanged(int, int)), this, SLOT(SelectSearchSymbol()));
98 AllWatchBrowserWindow::~AllWatchBrowserWindow(void)
104 // Search the symbol in the watch list
105 void AllWatchBrowserWindow::SearchSymbol(void)
110 // user cannot enter symbol to allow the search
111 symbol
->setDisabled(true);
113 // look for the symbol in the watch list
114 for (i
= AW_STARTNUMVARIABLE
; (i
< NbWatch
) && !found
; i
++)
116 // check symbol presence
117 if (!symbol
->text().compare(((S_VariablesStruct
*)PtrWatchInfo
[i
])->PtrName
, Qt::CaseSensitive
))
125 // remove previous highlight
128 model
->item((int)(CurrentWatch
- 1), 0)->setBackground(QColor(255, 255, 255));
129 model
->item((int)(CurrentWatch
- 1), 1)->setBackground(QColor(255, 255, 255));
130 model
->item((int)(CurrentWatch
- 1), 2)->setBackground(QColor(255, 255, 255));
132 // Get the slider maximum position
133 int MaxSlider
= TableView
->verticalScrollBar()->maximum();
134 // Number of items displayed in the scroll bar slider
135 int DeltaSlider
= (int)NbWatch
- MaxSlider
;
136 // set the scroll bar
137 TableView
->verticalScrollBar()->setSliderPosition((int)i
- (DeltaSlider
/ 2) - 1);
138 // highlight watch symbol
140 model
->item((int)(CurrentWatch
- 1), 0)->setBackground(QColor(0xff, 0xfa, 0xcd));
141 model
->item((int)(CurrentWatch
- 1), 1)->setBackground(QColor(0xff, 0xfa, 0xcd));
142 model
->item((int)(CurrentWatch
- 1), 2)->setBackground(QColor(0xff, 0xfa, 0xcd));
149 symbol
->setStyleSheet("color: red");
152 // user can enter a symbol
153 symbol
->setEnabled(true);
159 void AllWatchBrowserWindow::SelectSearchSymbol(void)
161 symbol
->setStyleSheet("color: black");
166 void AllWatchBrowserWindow::Reset(void)
175 void AllWatchBrowserWindow::RefreshContents(void)
178 #ifdef AW_LAYOUTTEXTS
182 size_t Error
= AW_NOERROR
;
184 //S_VariablesStruct* Var;
190 // Pre-catch the information for each global variables
191 if (NbWatch
= DBGManager_GetNbVariables(NULL
))
193 PtrWatchInfo
= (void**)calloc(NbWatch
, sizeof(S_VariablesStruct
*));
194 #ifndef AW_LAYOUTTEXTS
195 #ifdef AW_SORTINGFILTER
196 TableView
->setSortingEnabled(false);
198 model
->setRowCount(0);
200 for (uint32_t i
= AW_STARTNUMVARIABLE
; i
< NbWatch
; i
++)
202 if ((PtrWatchInfo
[i
] = (void*)DBGManager_GetInfosVariable(NULL
, i
+ 1)))
204 #ifdef AW_LAYOUTTEXTS
205 PtrWatchInfo
[i
].addr
= DBGManager_GetGlobalVariableAdr(i
+ 1);
206 if (!strlen(PtrWatchInfo
[i
].PtrVariableBaseTypeName
= DBGManager_GetGlobalVariableTypeName(i
+ 1)))
208 PtrWatchInfo
[i
].PtrVariableBaseTypeName
= (char *)"<font color='#ff0000'>N/A</font>";
220 for (uint32_t i
= AW_STARTNUMVARIABLE
; i
< NbWatch
; i
++)
222 if (((S_VariablesStruct
*)PtrWatchInfo
[i
])->TypeTag
& (DBG_TAG_TYPE_array
| DBG_TAG_TYPE_structure
))
224 #if defined(AW_SUPPORTARRAY) || defined(AW_SUPPORTSTRUCTURE)
225 //PtrValue = (char *)memcpy(Value, &jaguarMainRAM[PtrWatchInfo[i].addr], 20);
233 PtrValue
= DBGManager_GetVariableValueFromAdr(((S_VariablesStruct
*)PtrWatchInfo
[i
])->Addr
, ((S_VariablesStruct
*)PtrWatchInfo
[i
])->TypeEncoding
, ((S_VariablesStruct
*)PtrWatchInfo
[i
])->TypeByteSize
);
235 #ifdef AW_LAYOUTTEXTS
238 WatchAll
+= QString("<br>");
240 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>");
241 WatchAll
+= QString(string
);
243 model
->setItem(i
, 0, new QStandardItem(QString("%1").arg(((S_VariablesStruct
*)PtrWatchInfo
[i
])->PtrName
)));
244 model
->setItem(i
, 1, new QStandardItem(QString("%1").arg(PtrValue
)));
245 model
->setItem(i
, 2, new QStandardItem(QString("%1").arg(((S_VariablesStruct
*)PtrWatchInfo
[i
])->PtrTypeName
)));
248 #ifdef AW_LAYOUTTEXTS
250 text
->setText(WatchAll
);
252 #ifdef AW_SORTINGFILTER
253 TableView
->setSortingEnabled(true);
256 sprintf(msg
, "Ready");
260 sprintf(msg
, "No watches");
261 Error
= AW_NOALLWATCH
;
264 // Display status bar
267 if ((Error
& AW_WARNING
))
269 statusbar
->setStyleSheet("background-color: lightyellow; font: bold");
273 statusbar
->setStyleSheet("background-color: tomato; font: bold");
278 statusbar
->setStyleSheet("background-color: lightgreen; font: bold");
280 statusbar
->showMessage(QString(msg
));
285 // Handle keyboard event
286 void AllWatchBrowserWindow::keyPressEvent(QKeyEvent
* e
)
288 // ESC to close / hide the window
289 if (e
->key() == Qt::Key_Escape
)
296 if (e
->key() == Qt::Key_Return
)