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