Local browser window displays register name used 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].PtrCPURegisterName = NULL;
92 LocalInfo[i].TypeTag = DBGManager_GetLocalVariableTypeTag(Adr, i + 1);
93 LocalInfo[i].PtrVariableBaseTypeName = DBGManager_GetLocalVariableTypeName(Adr, i + 1);
94 LocalInfo[i].TypeEncoding = DBGManager_GetLocalVariableTypeEncoding(Adr, i + 1);
95 LocalInfo[i].TypeByteSize = DBGManager_GetLocalVariableTypeByteSize(Adr, i + 1);
96 LocalInfo[i].Offset = DBGManager_GetLocalVariableOffset(Adr, i + 1);
97 }
98 }
99 }
100
101 return true;
102 }
103 }
104
105 *FuncName = 0;
106
107 return false;
108 }
109
110
111 //
112 void LocalBrowserWindow::RefreshContents(void)
113 {
114 char string[1024];
115 // char buf[64];
116 QString Local;
117 char Value[100];
118 char *PtrValue;
119 // size_t NbWatch, Adr;
120 // WatchInfo PtrLocalInfo;
121
122 const char *CPURegName[] = { "D0", "D1", "D2", "D3", "D4", "D5", "D6", "D7", "A0", "A1", "A2", "A3", "A4", "A5", "A6", "A7" };
123
124 if (isVisible())
125 {
126 if (UpdateInfos())
127 {
128 //#ifdef _MSC_VER
129 //#pragma message("Warning: !!! Need to check the memory desalocation for LocalInfo !!!")
130 //#else
131 //#warning "!!! Need to do the memory desalocation for LocalInfo !!!"
132 //#endif // _MSC_VER
133 //#ifdef _MSC_VER
134 //#pragma message("Warning: !!! Need to check the memory desalocation for FuncName !!!")
135 //#else
136 //#warning "!!! Need to do the memory desalocation for FuncName !!!"
137 //#endif // _MSC_VER
138
139 for (size_t i = 0; i < NbLocal; i++)
140 {
141 if (LocalInfo[i].PtrVariableName)
142 {
143 if (((LocalInfo[i].Op >= DBG_OP_breg0) && (LocalInfo[i].Op <= DBG_OP_breg31)))
144 {
145 LocalInfo[i].Adr = m68k_get_reg(NULL, M68K_REG_A6) + LocalInfo[i].Offset;
146
147 if ((LocalInfo[i].Adr >= 0) && (LocalInfo[i].Adr < vjs.DRAM_size))
148 {
149 PtrValue = DBGManager_GetVariableValueFromAdr(LocalInfo[i].Adr, LocalInfo[i].TypeEncoding, LocalInfo[i].TypeByteSize);
150 }
151 else
152 {
153 PtrValue = NULL;
154 }
155 }
156 else
157 {
158 // Value from CPU register
159 if ((LocalInfo[i].Op >= DBG_OP_reg0) && (LocalInfo[i].Op <= DBG_OP_reg31))
160 {
161 LocalInfo[i].PtrCPURegisterName = (char *)CPURegName[(LocalInfo[i].Op - DBG_OP_reg0)];
162 PtrValue = itoa(m68k_get_reg(NULL, (m68k_register_t)((size_t)M68K_REG_D0 + (LocalInfo[i].Op - DBG_OP_reg0))), Value, 10);
163 }
164 else
165 {
166 PtrValue = NULL;
167 }
168 }
169
170 sprintf(string, "%i : %s | %s | ", (i + 1), (LocalInfo[i].PtrVariableBaseTypeName ? LocalInfo[i].PtrVariableBaseTypeName : (char *)"<font color='#ff0000'>N/A</font>"), LocalInfo[i].PtrVariableName);
171 Local += QString(string);
172 if ((unsigned int)LocalInfo[i].Adr)
173 {
174 sprintf(string, "0x%06X", (unsigned int)LocalInfo[i].Adr);
175 }
176 else
177 {
178 if (LocalInfo[i].PtrCPURegisterName)
179 {
180 sprintf(string, "<font color='#0000FF'>%s</font>", LocalInfo[i].PtrCPURegisterName);
181 }
182 else
183 {
184 sprintf(string, "%s", (char *)"<font color='#ff0000'>N/A</font>");
185 }
186 }
187 Local += QString(string);
188 sprintf(string, " | %s", (!PtrValue ? (char *)"<font color='#ff0000'>N/A</font>" : PtrValue));
189 Local += QString(string);
190 sprintf(string, "<br>");
191 Local += QString(string);
192 }
193 }
194
195 text->clear();
196 text->setText(Local);
197 }
198 else
199 {
200 text->clear();
201 }
202 }
203 }
204
205
206 #if 0
207 void LocalBrowserWindow::keyPressEvent(QKeyEvent * e)
208 {
209 if (e->key() == Qt::Key_Escape)
210 hide();
211 else if (e->key() == Qt::Key_PageUp)
212 {
213 memBase -= 480;
214
215 if (memBase < 0)
216 memBase = 0;
217
218 RefreshContents();
219 }
220 else if (e->key() == Qt::Key_PageDown)
221 {
222 memBase += 480;
223
224 if (memBase > (0x200000 - 480))
225 memBase = 0x200000 - 480;
226
227 RefreshContents();
228 }
229 else if (e->key() == Qt::Key_Up || e->key() == Qt::Key_Minus)
230 {
231 memBase -= 16;
232
233 if (memBase < 0)
234 memBase = 0;
235
236 RefreshContents();
237 }
238 else if (e->key() == Qt::Key_Down || e->key() == Qt::Key_Equal)
239 {
240 memBase += 16;
241
242 if (memBase > (0x200000 - 480))
243 memBase = 0x200000 - 480;
244
245 RefreshContents();
246 }
247 }
248 #endif
249
250
251 #if 0
252 void LocalBrowserWindow::GoToAddress(void)
253 {
254 bool ok;
255 QString newAddress = address->text();
256 memBase = newAddress.toUInt(&ok, 16);
257 RefreshContents();
258 }
259 #endif
260