2 // localbrowser.cpp - Local variables
6 // JPM = Jean-Paul Mari <djipi.mari@gmail.com>
9 // --- ---------- -----------------------------------------------------------
10 // JPM 11/03/2017 Created this file
14 #include "debugger/localbrowser.h"
16 #include "debugger/DBGManager.h"
18 #include "m68000/m68kinterface.h"
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"))),
30 FuncName((char *)calloc(1, 1)),
33 setWindowTitle(tr("Local"));
35 // address->setInputMask("hhhhhh");
36 // QHBoxLayout * hbox1 = new QHBoxLayout;
37 // hbox1->addWidget(refresh);
38 // hbox1->addWidget(address);
39 // hbox1->addWidget(go);
41 // Need to set the size as well...
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);
51 layout->addWidget(text);
52 // layout->addWidget(refresh);
53 // layout->addLayout(hbox1);
55 // connect(refresh, SIGNAL(clicked()), this, SLOT(RefreshContents()));
56 // connect(go, SIGNAL(clicked()), this, SLOT(GoToAddress()));
61 LocalBrowserWindow::~LocalBrowserWindow(void)
70 bool LocalBrowserWindow::UpdateInfos(void)
75 if (NbLocal = DBGManager_GetNbLocalVariables(Adr = m68k_get_reg(NULL, M68K_REG_PC)))
77 if (Ptr = DBGManager_GetFunctionName(Adr))
79 if (strcmp(FuncName, Ptr))
81 if (FuncName = (char *)realloc(FuncName, strlen(Ptr) + 1))
83 strcpy(FuncName, Ptr);
85 if (LocalInfo = (WatchInfo *)realloc(LocalInfo, (sizeof(WatchInfo) * NbLocal)))
87 for (size_t i = 0; i < NbLocal; i++)
89 // Get local variable name and his information
90 if (LocalInfo[i].PtrVariableName = DBGManager_GetLocalVariableName(Adr, i + 1))
92 LocalInfo[i].Op = DBGManager_GetLocalVariableOp(Adr, i + 1);
93 LocalInfo[i].Adr = NULL;
94 LocalInfo[i].PtrCPURegisterName = NULL;
95 LocalInfo[i].TypeTag = DBGManager_GetLocalVariableTypeTag(Adr, i + 1);
96 LocalInfo[i].PtrVariableBaseTypeName = DBGManager_GetLocalVariableTypeName(Adr, i + 1);
97 LocalInfo[i].TypeEncoding = DBGManager_GetLocalVariableTypeEncoding(Adr, i + 1);
98 LocalInfo[i].TypeByteSize = DBGManager_GetLocalVariableTypeByteSize(Adr, i + 1);
99 LocalInfo[i].Offset = DBGManager_GetLocalVariableOffset(Adr, i + 1);
117 void LocalBrowserWindow::RefreshContents(void)
124 // size_t NbWatch, Adr;
125 // WatchInfo PtrLocalInfo;
127 const char *CPURegName[] = { "D0", "D1", "D2", "D3", "D4", "D5", "D6", "D7", "A0", "A1", "A2", "A3", "A4", "A5", "A6", "A7" };
134 //#pragma message("Warning: !!! Need to check the memory desalocation for LocalInfo !!!")
136 //#warning "!!! Need to do the memory desalocation for LocalInfo !!!"
139 //#pragma message("Warning: !!! Need to check the memory desalocation for FuncName !!!")
141 //#warning "!!! Need to do the memory desalocation for FuncName !!!"
144 for (size_t i = 0; i < NbLocal; i++)
146 if (LocalInfo[i].PtrVariableName)
148 // Local or parameters variables
149 if (((LocalInfo[i].Op >= DBG_OP_breg0) && (LocalInfo[i].Op <= DBG_OP_breg31)) || (LocalInfo[i].Op == DBG_OP_fbreg))
151 LocalInfo[i].Adr = m68k_get_reg(NULL, M68K_REG_A6) + LocalInfo[i].Offset;
153 if ((LocalInfo[i].Op == DBG_OP_fbreg))
155 LocalInfo[i].Adr += 8;
158 if ((LocalInfo[i].Adr >= 0) && (LocalInfo[i].Adr < vjs.DRAM_size))
160 PtrValue = DBGManager_GetVariableValueFromAdr(LocalInfo[i].Adr, LocalInfo[i].TypeEncoding, LocalInfo[i].TypeByteSize);
169 // Value from CPU register
170 if ((LocalInfo[i].Op >= DBG_OP_reg0) && (LocalInfo[i].Op <= DBG_OP_reg31))
172 LocalInfo[i].PtrCPURegisterName = (char *)CPURegName[(LocalInfo[i].Op - DBG_OP_reg0)];
173 PtrValue = itoa(m68k_get_reg(NULL, (m68k_register_t)((size_t)M68K_REG_D0 + (LocalInfo[i].Op - DBG_OP_reg0))), Value, 10);
181 if (!LocalInfo[i].Op)
183 sprintf(string, "<font color='#A52A2A'>%i : %s | %s | [Not used]</font>", (i + 1), (LocalInfo[i].PtrVariableBaseTypeName ? LocalInfo[i].PtrVariableBaseTypeName : (char *)"<font color='#ff0000'>N/A</font>"), LocalInfo[i].PtrVariableName);
187 sprintf(string, "%i : %s | %s | ", (i + 1), (LocalInfo[i].PtrVariableBaseTypeName ? LocalInfo[i].PtrVariableBaseTypeName : (char *)"<font color='#ff0000'>N/A</font>"), LocalInfo[i].PtrVariableName);
188 Local += QString(string);
189 if ((unsigned int)LocalInfo[i].Adr)
191 sprintf(string, "0x%06X", (unsigned int)LocalInfo[i].Adr);
195 if (LocalInfo[i].PtrCPURegisterName)
197 sprintf(string, "<font color='#0000FF'>%s</font>", LocalInfo[i].PtrCPURegisterName);
201 sprintf(string, "%s", (char *)"<font color='#ff0000'>N/A</font>");
204 Local += QString(string);
205 sprintf(string, " | %s", (!PtrValue ? (char *)"<font color='#ff0000'>N/A</font>" : PtrValue));
207 Local += QString(string);
208 sprintf(string, "<br>");
209 Local += QString(string);
214 text->setText(Local);
225 void LocalBrowserWindow::keyPressEvent(QKeyEvent * e)
227 if (e->key() == Qt::Key_Escape)
232 else if (e->key() == Qt::Key_PageUp)
241 else if (e->key() == Qt::Key_PageDown)
245 if (memBase > (0x200000 - 480))
246 memBase = 0x200000 - 480;
250 else if (e->key() == Qt::Key_Up || e->key() == Qt::Key_Minus)
259 else if (e->key() == Qt::Key_Down || e->key() == Qt::Key_Equal)
263 if (memBase > (0x200000 - 480))
264 memBase = 0x200000 - 480;
273 void LocalBrowserWindow::GoToAddress(void)
276 QString newAddress = address->text();
277 memBase = newAddress.toUInt(&ok, 16);