UI modifications and crash fix
[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 //
12
13 // STILL TO DO:
14 // Better presentation
15 //
16
17 #include "debugger/allwatchbrowser.h"
18 #include "memory.h"
19 #include "debugger/DBGManager.h"
20
21
22 //
23 AllWatchBrowserWindow::AllWatchBrowserWindow(QWidget * parent/*= 0*/) : QWidget(parent, Qt::Dialog),
24 layout(new QVBoxLayout), text(new QTextBrowser),
25 NbWatch(0),
26 PtrWatchInfo(NULL)
27 {
28 setWindowTitle(tr("All Watch"));
29
30 QFont fixedFont("Lucida Console", 8, QFont::Normal);
31 fixedFont.setStyleHint(QFont::TypeWriter);
32 text->setFont(fixedFont);
33 setLayout(layout);
34
35 layout->addWidget(text);
36 }
37
38
39 //
40 AllWatchBrowserWindow::~AllWatchBrowserWindow(void)
41 {
42 Reset();
43 }
44
45
46 //
47 void AllWatchBrowserWindow::Reset(void)
48 {
49 free(PtrWatchInfo);
50 NbWatch = 0;
51 PtrWatchInfo = NULL;
52 }
53
54
55 //
56 void AllWatchBrowserWindow::RefreshContents(void)
57 {
58 char string[1024];
59 QString WatchAll;
60
61 if (isVisible())
62 {
63 text->clear();
64
65 if (!NbWatch)
66 {
67 if (NbWatch = DBGManager_GetNbGlobalVariables())
68 {
69 PtrWatchInfo = (WatchInfo *)calloc(NbWatch, sizeof(WatchInfo));
70
71 for (uint32_t i = 0; i < NbWatch; i++)
72 {
73 PtrWatchInfo[i].PtrVariableName = DBGManager_GetGlobalVariableName(i + 1);
74 PtrWatchInfo[i].addr = DBGManager_GetGlobalVariableAdr(i + 1);
75 PtrWatchInfo[i].TypeTag = DBGManager_GetGlobalVariableTypeTag(i + 1);
76 if (!strlen(PtrWatchInfo[i].PtrVariableBaseTypeName = DBGManager_GetGlobalVariableTypeName(i + 1)))
77 {
78 PtrWatchInfo[i].PtrVariableBaseTypeName = (char *)"<font color='#ff0000'>N/A</font>";
79 }
80 }
81 }
82 }
83
84 for (uint32_t i = 0; i < NbWatch; i++)
85 {
86 if (PtrWatchInfo[i].PtrVariableName && PtrWatchInfo[i].PtrVariableBaseTypeName)
87 {
88 sprintf(string, "%i : %s | %s | 0x%06X | %s", (i + 1), PtrWatchInfo[i].PtrVariableBaseTypeName, PtrWatchInfo[i].PtrVariableName, (unsigned int)PtrWatchInfo[i].addr, (PtrWatchInfo[i].TypeTag & 0x8) ? "" : DBGManager_GetGlobalVariableValue(i + 1));
89 WatchAll += QString(string);
90 sprintf(string, "<br>");
91 WatchAll += QString(string);
92 }
93 }
94
95 text->setText(WatchAll);
96 }
97 }
98
99
100 //
101 void AllWatchBrowserWindow::keyPressEvent(QKeyEvent * e)
102 {
103 if (e->key() == Qt::Key_Escape)
104 {
105 hide();
106 }
107 }
108