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 FuncName
= (char *)realloc(FuncName
, strlen(Ptr
) + 1);
82 strcpy(FuncName
, Ptr
);
84 LocalInfo
= (WatchInfo
*)realloc(LocalInfo
, (sizeof(WatchInfo
) * NbLocal
));
85 for (size_t i
= 0; i
< NbLocal
; i
++)
87 if (LocalInfo
[i
].PtrVariableName
= DBGManager_GetLocalVariableName(Adr
, i
+ 1))
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);
111 void LocalBrowserWindow::RefreshContents(void)
118 // size_t NbWatch, Adr;
119 // WatchInfo PtrLocalInfo;
126 //#pragma message("Warning: !!! Need to check the memory desalocation for LocalInfo !!!")
128 //#warning "!!! Need to do the memory desalocation for LocalInfo !!!"
131 //#pragma message("Warning: !!! Need to check the memory desalocation for FuncName !!!")
133 //#warning "!!! Need to do the memory desalocation for FuncName !!!"
136 for (size_t i
= 0; i
< NbLocal
; i
++)
138 if (LocalInfo
[i
].PtrVariableName
)
140 if (((LocalInfo
[i
].Op
>= DBG_OP_breg0
) && (LocalInfo
[i
].Op
<= DBG_OP_breg31
)))
142 LocalInfo
[i
].Adr
= m68k_get_reg(NULL
, M68K_REG_A6
) + LocalInfo
[i
].Offset
;
144 if ((LocalInfo
[i
].Adr
>= 0) && (LocalInfo
[i
].Adr
< vjs
.DRAM_size
))
146 PtrValue
= DBGManager_GetVariableValueFromAdr(LocalInfo
[i
].Adr
, LocalInfo
[i
].TypeEncoding
, LocalInfo
[i
].TypeByteSize
);
155 if ((LocalInfo
[i
].Op
>= DBG_OP_reg0
) && (LocalInfo
[i
].Op
<= DBG_OP_reg31
))
157 PtrValue
= itoa(m68k_get_reg(NULL
, (m68k_register_t
)((size_t)M68K_REG_D0
+ (LocalInfo
[i
].Op
- DBG_OP_reg0
))), Value
, 10);
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
)
169 sprintf(string
, "0x%06X", (unsigned int)LocalInfo
[i
].Adr
);
173 sprintf(string
, "%s", (char *)"<font color='#ff0000'>N/A</font>");
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
);
184 text
->setText(Local
);
195 void LocalBrowserWindow::keyPressEvent(QKeyEvent
* e
)
197 if (e
->key() == Qt::Key_Escape
)
199 else if (e
->key() == Qt::Key_PageUp
)
208 else if (e
->key() == Qt::Key_PageDown
)
212 if (memBase
> (0x200000 - 480))
213 memBase
= 0x200000 - 480;
217 else if (e
->key() == Qt::Key_Up
|| e
->key() == Qt::Key_Minus
)
226 else if (e
->key() == Qt::Key_Down
|| e
->key() == Qt::Key_Equal
)
230 if (memBase
> (0x200000 - 480))
231 memBase
= 0x200000 - 480;
240 void LocalBrowserWindow::GoToAddress(void)
243 QString newAddress
= address
->text();
244 memBase
= newAddress
.toUInt(&ok
, 16);