Added a Local browser window for local variables
[clinton/Virtual-Jaguar-Rx.git] / src / debugger / localbrowser.cpp
1 //
2 // localbrowser.cpp - Local variables
3 //
4 // by Jean-Paul Mari
5 //
6 // JPM = Jean-Paul Mari <djipi.mari@gmail.com>
7 //
8 // Who When What
9 // --- ---------- -----------------------------------------------------------
10 // JPM 11/03/2017 Created this file
11 //
12
13
14 #include "debugger/localbrowser.h"
15 #include "memory.h"
16 #include "debugger/DBGManager.h"
17 #include "settings.h"
18 #include "m68000/m68kinterface.h"
19
20
21 //
22 LocalBrowserWindow::LocalBrowserWindow(QWidget * parent/*= 0*/) : QWidget(parent, Qt::Dialog),
23 layout(new QVBoxLayout), text(new QTextBrowser),
24 // layout(new QVBoxLayout), text(new QLabel),
25 // refresh(new QPushButton(tr("Refresh"))),
26 // address(new QLineEdit),
27 // go(new QPushButton(tr("Go"))),
28 // memBase(0),
29 NbLocal(0),
30 FuncName((char *)calloc(1, 1)),
31 LocalInfo(NULL)
32 {
33 setWindowTitle(tr("Local"));
34
35 // address->setInputMask("hhhhhh");
36 // QHBoxLayout * hbox1 = new QHBoxLayout;
37 // hbox1->addWidget(refresh);
38 // hbox1->addWidget(address);
39 // hbox1->addWidget(go);
40
41 // Need to set the size as well...
42 // resize(560, 480);
43
44 QFont fixedFont("Lucida Console", 8, QFont::Normal);
45 // QFont fixedFont("", 8, QFont::Normal);
46 fixedFont.setStyleHint(QFont::TypeWriter);
47 text->setFont(fixedFont);
48 //// layout->setSizeConstraint(QLayout::SetFixedSize);
49 setLayout(layout);
50
51 layout->addWidget(text);
52 // layout->addWidget(refresh);
53 // layout->addLayout(hbox1);
54
55 // connect(refresh, SIGNAL(clicked()), this, SLOT(RefreshContents()));
56 // connect(go, SIGNAL(clicked()), this, SLOT(GoToAddress()));
57 }
58
59
60 //
61 LocalBrowserWindow::~LocalBrowserWindow(void)
62 {
63 free(LocalInfo);
64 free(FuncName);
65 // NbLocal = 0;
66 }
67
68
69 //
70 bool LocalBrowserWindow::UpdateInfos(void)
71 {
72 size_t Adr;
73 char *Ptr;
74
75 if (NbLocal = DBGManager_GetNbLocalVariables(Adr = m68k_get_reg(NULL, M68K_REG_PC)))
76 {
77 if (Ptr = DBGManager_GetFunctionName(Adr))
78 {
79 if (strcmp(FuncName, Ptr))
80 {
81 FuncName = (char *)realloc(FuncName, strlen(Ptr) + 1);
82 strcpy(FuncName, Ptr);
83
84 LocalInfo = (WatchInfo *)realloc(LocalInfo, (sizeof(WatchInfo) * NbLocal));
85 for (size_t i = 0; i < NbLocal; i++)
86 {
87 if (LocalInfo[i].PtrVariableName = DBGManager_GetLocalVariableName(Adr, i + 1))
88 {
89 LocalInfo[i].Op = DBGManager_GetLocalVariableOp(Adr, i + 1);
90 LocalInfo[i].Adr = NULL;
91 LocalInfo[i].TypeTag = DBGManager_GetLocalVariableTypeTag(Adr, i + 1);
92 LocalInfo[i].PtrVariableBaseTypeName = DBGManager_GetLocalVariableTypeName(Adr, i + 1);
93 LocalInfo[i].TypeEncoding = DBGManager_GetLocalVariableTypeEncoding(Adr, i + 1);
94 LocalInfo[i].TypeByteSize = DBGManager_GetLocalVariableTypeByteSize(Adr, i + 1);
95 LocalInfo[i].Offset = DBGManager_GetLocalVariableOffset(Adr, i + 1);
96 }
97 }
98 }
99
100 return true;
101 }
102 }
103
104 *FuncName = 0;
105
106 return false;
107 }
108
109
110 //
111 void LocalBrowserWindow::RefreshContents(void)
112 {
113 char string[1024];
114 // char buf[64];
115 QString Local;
116 char Value[100];
117 char *PtrValue;
118 // size_t NbWatch, Adr;
119 // WatchInfo PtrLocalInfo;
120
121 if (isVisible())
122 {
123 if (UpdateInfos())
124 {
125 //#ifdef _MSC_VER
126 //#pragma message("Warning: !!! Need to check the memory desalocation for LocalInfo !!!")
127 //#else
128 //#warning "!!! Need to do the memory desalocation for LocalInfo !!!"
129 //#endif // _MSC_VER
130 //#ifdef _MSC_VER
131 //#pragma message("Warning: !!! Need to check the memory desalocation for FuncName !!!")
132 //#else
133 //#warning "!!! Need to do the memory desalocation for FuncName !!!"
134 //#endif // _MSC_VER
135
136 for (size_t i = 0; i < NbLocal; i++)
137 {
138 if (LocalInfo[i].PtrVariableName)
139 {
140 if (((LocalInfo[i].Op >= DBG_OP_breg0) && (LocalInfo[i].Op <= DBG_OP_breg31)))
141 {
142 LocalInfo[i].Adr = m68k_get_reg(NULL, M68K_REG_A6) + LocalInfo[i].Offset;
143
144 if ((LocalInfo[i].Adr >= 0) && (LocalInfo[i].Adr < vjs.DRAM_size))
145 {
146 PtrValue = DBGManager_GetVariableValueFromAdr(LocalInfo[i].Adr, LocalInfo[i].TypeEncoding, LocalInfo[i].TypeByteSize);
147 }
148 else
149 {
150 PtrValue = NULL;
151 }
152 }
153 else
154 {
155 if ((LocalInfo[i].Op >= DBG_OP_reg0) && (LocalInfo[i].Op <= DBG_OP_reg31))
156 {
157 PtrValue = itoa(m68k_get_reg(NULL, (m68k_register_t)((size_t)M68K_REG_D0 + (LocalInfo[i].Op - DBG_OP_reg0))), Value, 10);
158 }
159 else
160 {
161 PtrValue = NULL;
162 }
163 }
164
165 sprintf(string, "%i : %s | %s | ", (i + 1), (LocalInfo[i].PtrVariableBaseTypeName ? LocalInfo[i].PtrVariableBaseTypeName : (char *)"<font color='#ff0000'>N/A</font>"), LocalInfo[i].PtrVariableName);
166 Local += QString(string);
167 if ((unsigned int)LocalInfo[i].Adr)
168 {
169 sprintf(string, "0x%06X", (unsigned int)LocalInfo[i].Adr);
170 }
171 else
172 {
173 sprintf(string, "%s", (char *)"<font color='#ff0000'>N/A</font>");
174 }
175 Local += QString(string);
176 sprintf(string, " | %s", (!PtrValue ? (char *)"<font color='#ff0000'>N/A</font>" : PtrValue));
177 Local += QString(string);
178 sprintf(string, "<br>");
179 Local += QString(string);
180 }
181 }
182
183 text->clear();
184 text->setText(Local);
185 }
186 else
187 {
188 text->clear();
189 }
190 }
191 }
192
193
194 #if 0
195 void LocalBrowserWindow::keyPressEvent(QKeyEvent * e)
196 {
197 if (e->key() == Qt::Key_Escape)
198 hide();
199 else if (e->key() == Qt::Key_PageUp)
200 {
201 memBase -= 480;
202
203 if (memBase < 0)
204 memBase = 0;
205
206 RefreshContents();
207 }
208 else if (e->key() == Qt::Key_PageDown)
209 {
210 memBase += 480;
211
212 if (memBase > (0x200000 - 480))
213 memBase = 0x200000 - 480;
214
215 RefreshContents();
216 }
217 else if (e->key() == Qt::Key_Up || e->key() == Qt::Key_Minus)
218 {
219 memBase -= 16;
220
221 if (memBase < 0)
222 memBase = 0;
223
224 RefreshContents();
225 }
226 else if (e->key() == Qt::Key_Down || e->key() == Qt::Key_Equal)
227 {
228 memBase += 16;
229
230 if (memBase > (0x200000 - 480))
231 memBase = 0x200000 - 480;
232
233 RefreshContents();
234 }
235 }
236 #endif
237
238
239 #if 0
240 void LocalBrowserWindow::GoToAddress(void)
241 {
242 bool ok;
243 QString newAddress = address->text();
244 memBase = newAddress.toUInt(&ok, 16);
245 RefreshContents();
246 }
247 #endif
248