X-Git-Url: http://git.hcoop.net/clinton/Virtual-Jaguar-Rx.git/blobdiff_plain/0203b5fd6f49dbc4f4244417c095882eb9882d49..c4fe5864602982ced026178abdfe862eb2c5e1c5:/src/debugger/localbrowser.cpp diff --git a/src/debugger/localbrowser.cpp b/src/debugger/localbrowser.cpp dissimilarity index 63% index 3b8d816..9cafa71 100644 --- a/src/debugger/localbrowser.cpp +++ b/src/debugger/localbrowser.cpp @@ -1,248 +1,314 @@ -// -// localbrowser.cpp - Local variables -// -// by Jean-Paul Mari -// -// JPM = Jean-Paul Mari -// -// Who When What -// --- ---------- ----------------------------------------------------------- -// JPM 11/03/2017 Created this file -// - - -#include "debugger/localbrowser.h" -#include "memory.h" -#include "debugger/DBGManager.h" -#include "settings.h" -#include "m68000/m68kinterface.h" - - -// -LocalBrowserWindow::LocalBrowserWindow(QWidget * parent/*= 0*/) : QWidget(parent, Qt::Dialog), - layout(new QVBoxLayout), text(new QTextBrowser), -// layout(new QVBoxLayout), text(new QLabel), -// refresh(new QPushButton(tr("Refresh"))), -// address(new QLineEdit), -// go(new QPushButton(tr("Go"))), -// memBase(0), - NbLocal(0), - FuncName((char *)calloc(1, 1)), - LocalInfo(NULL) -{ - setWindowTitle(tr("Local")); - -// address->setInputMask("hhhhhh"); -// QHBoxLayout * hbox1 = new QHBoxLayout; -// hbox1->addWidget(refresh); -// hbox1->addWidget(address); -// hbox1->addWidget(go); - - // Need to set the size as well... -// resize(560, 480); - - QFont fixedFont("Lucida Console", 8, QFont::Normal); -// QFont fixedFont("", 8, QFont::Normal); - fixedFont.setStyleHint(QFont::TypeWriter); - text->setFont(fixedFont); -//// layout->setSizeConstraint(QLayout::SetFixedSize); - setLayout(layout); - - layout->addWidget(text); -// layout->addWidget(refresh); -// layout->addLayout(hbox1); - -// connect(refresh, SIGNAL(clicked()), this, SLOT(RefreshContents())); -// connect(go, SIGNAL(clicked()), this, SLOT(GoToAddress())); -} - - -// -LocalBrowserWindow::~LocalBrowserWindow(void) -{ - free(LocalInfo); - free(FuncName); -// NbLocal = 0; -} - - -// -bool LocalBrowserWindow::UpdateInfos(void) -{ - size_t Adr; - char *Ptr; - - if (NbLocal = DBGManager_GetNbLocalVariables(Adr = m68k_get_reg(NULL, M68K_REG_PC))) - { - if (Ptr = DBGManager_GetFunctionName(Adr)) - { - if (strcmp(FuncName, Ptr)) - { - FuncName = (char *)realloc(FuncName, strlen(Ptr) + 1); - strcpy(FuncName, Ptr); - - LocalInfo = (WatchInfo *)realloc(LocalInfo, (sizeof(WatchInfo) * NbLocal)); - for (size_t i = 0; i < NbLocal; i++) - { - if (LocalInfo[i].PtrVariableName = DBGManager_GetLocalVariableName(Adr, i + 1)) - { - LocalInfo[i].Op = DBGManager_GetLocalVariableOp(Adr, i + 1); - LocalInfo[i].Adr = NULL; - LocalInfo[i].TypeTag = DBGManager_GetLocalVariableTypeTag(Adr, i + 1); - LocalInfo[i].PtrVariableBaseTypeName = DBGManager_GetLocalVariableTypeName(Adr, i + 1); - LocalInfo[i].TypeEncoding = DBGManager_GetLocalVariableTypeEncoding(Adr, i + 1); - LocalInfo[i].TypeByteSize = DBGManager_GetLocalVariableTypeByteSize(Adr, i + 1); - LocalInfo[i].Offset = DBGManager_GetLocalVariableOffset(Adr, i + 1); - } - } - } - - return true; - } - } - - *FuncName = 0; - - return false; -} - - -// -void LocalBrowserWindow::RefreshContents(void) -{ - char string[1024]; -// char buf[64]; - QString Local; - char Value[100]; - char *PtrValue; -// size_t NbWatch, Adr; -// WatchInfo PtrLocalInfo; - - if (isVisible()) - { - if (UpdateInfos()) - { -//#ifdef _MSC_VER - //#pragma message("Warning: !!! Need to check the memory desalocation for LocalInfo !!!") -//#else - //#warning "!!! Need to do the memory desalocation for LocalInfo !!!" -//#endif // _MSC_VER -//#ifdef _MSC_VER - //#pragma message("Warning: !!! Need to check the memory desalocation for FuncName !!!") -//#else - //#warning "!!! Need to do the memory desalocation for FuncName !!!" -//#endif // _MSC_VER - - for (size_t i = 0; i < NbLocal; i++) - { - if (LocalInfo[i].PtrVariableName) - { - if (((LocalInfo[i].Op >= DBG_OP_breg0) && (LocalInfo[i].Op <= DBG_OP_breg31))) - { - LocalInfo[i].Adr = m68k_get_reg(NULL, M68K_REG_A6) + LocalInfo[i].Offset; - - if ((LocalInfo[i].Adr >= 0) && (LocalInfo[i].Adr < vjs.DRAM_size)) - { - PtrValue = DBGManager_GetVariableValueFromAdr(LocalInfo[i].Adr, LocalInfo[i].TypeEncoding, LocalInfo[i].TypeByteSize); - } - else - { - PtrValue = NULL; - } - } - else - { - if ((LocalInfo[i].Op >= DBG_OP_reg0) && (LocalInfo[i].Op <= DBG_OP_reg31)) - { - PtrValue = itoa(m68k_get_reg(NULL, (m68k_register_t)((size_t)M68K_REG_D0 + (LocalInfo[i].Op - DBG_OP_reg0))), Value, 10); - } - else - { - PtrValue = NULL; - } - } - - sprintf(string, "%i : %s | %s | ", (i + 1), (LocalInfo[i].PtrVariableBaseTypeName ? LocalInfo[i].PtrVariableBaseTypeName : (char *)"N/A"), LocalInfo[i].PtrVariableName); - Local += QString(string); - if ((unsigned int)LocalInfo[i].Adr) - { - sprintf(string, "0x%06X", (unsigned int)LocalInfo[i].Adr); - } - else - { - sprintf(string, "%s", (char *)"N/A"); - } - Local += QString(string); - sprintf(string, " | %s", (!PtrValue ? (char *)"N/A" : PtrValue)); - Local += QString(string); - sprintf(string, "
"); - Local += QString(string); - } - } - - text->clear(); - text->setText(Local); - } - else - { - text->clear(); - } - } -} - - -#if 0 -void LocalBrowserWindow::keyPressEvent(QKeyEvent * e) -{ - if (e->key() == Qt::Key_Escape) - hide(); - else if (e->key() == Qt::Key_PageUp) - { - memBase -= 480; - - if (memBase < 0) - memBase = 0; - - RefreshContents(); - } - else if (e->key() == Qt::Key_PageDown) - { - memBase += 480; - - if (memBase > (0x200000 - 480)) - memBase = 0x200000 - 480; - - RefreshContents(); - } - else if (e->key() == Qt::Key_Up || e->key() == Qt::Key_Minus) - { - memBase -= 16; - - if (memBase < 0) - memBase = 0; - - RefreshContents(); - } - else if (e->key() == Qt::Key_Down || e->key() == Qt::Key_Equal) - { - memBase += 16; - - if (memBase > (0x200000 - 480)) - memBase = 0x200000 - 480; - - RefreshContents(); - } -} -#endif - - -#if 0 -void LocalBrowserWindow::GoToAddress(void) -{ - bool ok; - QString newAddress = address->text(); - memBase = newAddress.toUInt(&ok, 16); - RefreshContents(); -} -#endif - +// +// localbrowser.cpp - Local variables +// +// by Jean-Paul Mari +// +// JPM = Jean-Paul Mari +// RG = Richard Goedeken +// +// Who When What +// --- ---------- ----------------------------------------------------------- +// JPM 11/03/2017 Created this file +// JPM Sept./2018 Added a status bar and better status report, and set information values in a tab +// RG Jan./2021 Linux build fixes +// + +// STILL TO DO: +// Feature to list the pointer(s) in the code using the allocation +// To set the information display at the right +// To support the array +// To support the static variables +// To add a filter +// + +#include + +#include "debugger/localbrowser.h" +#include "memory.h" +#include "debugger/DBGManager.h" +#include "settings.h" +#include "m68000/m68kinterface.h" + + +// +LocalBrowserWindow::LocalBrowserWindow(QWidget * parent/*= 0*/) : QWidget(parent, Qt::Dialog), +layout(new QVBoxLayout), +#ifdef LOCAL_LAYOUTTEXTS +text(new QTextBrowser), +#else +TableView(new QTableView), +model(new QStandardItemModel), +#endif +NbLocal(0), +FuncName((char *)calloc(1, 1)), +LocalInfo(NULL), +statusbar(new QStatusBar) +{ + setWindowTitle(tr("Locals")); + + // Set the font + QFont fixedFont("Lucida Console", 8, QFont::Normal); + fixedFont.setStyleHint(QFont::TypeWriter); + +#ifdef LOCAL_LAYOUTTEXTS + // Set original layout + text->setFont(fixedFont); + layout->addWidget(text); +#else + // Set the new layout with proper identation and readibility + model->setColumnCount(3); + model->setHeaderData(0, Qt::Horizontal, QObject::tr("Name")); + model->setHeaderData(1, Qt::Horizontal, QObject::tr("Value")); + model->setHeaderData(2, Qt::Horizontal, QObject::tr("Type")); + // Information table + TableView->setModel(model); + TableView->setEditTriggers(QAbstractItemView::NoEditTriggers); + TableView->setShowGrid(0); + TableView->setFont(fixedFont); + TableView->verticalHeader()->setDefaultSectionSize(TableView->verticalHeader()->minimumSectionSize()); + TableView->verticalHeader()->setDefaultAlignment(Qt::AlignRight); + layout->addWidget(TableView); +#endif + + // Status bar + layout->addWidget(statusbar); + setLayout(layout); +} + + +// +LocalBrowserWindow::~LocalBrowserWindow(void) +{ + free(LocalInfo); + free(FuncName); +} + + +// +bool LocalBrowserWindow::UpdateInfos(void) +{ + size_t Adr; + char *Ptr; + + if (NbLocal = DBGManager_GetNbLocalVariables(Adr = m68k_get_reg(NULL, M68K_REG_PC))) + { + if (Ptr = DBGManager_GetFunctionName(Adr)) + { + if (strcmp(FuncName, Ptr)) + { + if (FuncName = (char *)realloc(FuncName, strlen(Ptr) + 1)) + { + strcpy(FuncName, Ptr); + + if (LocalInfo = (WatchInfo *)realloc(LocalInfo, (sizeof(WatchInfo) * NbLocal))) + { + for (size_t i = 0; i < NbLocal; i++) + { + // Get local variable name and his information + if (LocalInfo[i].PtrVariableName = DBGManager_GetLocalVariableName(Adr, i + 1)) + { + LocalInfo[i].Op = DBGManager_GetLocalVariableOp(Adr, i + 1); + LocalInfo[i].Adr = NULL; + LocalInfo[i].PtrCPURegisterName = NULL; + LocalInfo[i].TypeTag = DBGManager_GetLocalVariableTypeTag(Adr, i + 1); + LocalInfo[i].PtrVariableBaseTypeName = DBGManager_GetLocalVariableTypeName(Adr, i + 1); + LocalInfo[i].TypeEncoding = DBGManager_GetLocalVariableTypeEncoding(Adr, i + 1); + LocalInfo[i].TypeByteSize = DBGManager_GetLocalVariableTypeByteSize(Adr, i + 1); + LocalInfo[i].Offset = DBGManager_GetLocalVariableOffset(Adr, i + 1); + } + } + } + } + } + + return true; + } + } + + *FuncName = 0; + + return false; +} + + +// +void LocalBrowserWindow::RefreshContents(void) +{ +#ifdef LOCAL_LAYOUTTEXTS + char string[1024]; +#endif + size_t Error = LOCAL_NOERROR; + QString Local; + QString MSG; + char Value1[100]; +#ifdef LOCAL_SUPPORTARRAY + char Value[100]; +#endif + char *PtrValue; + + const char *CPURegName[] = { "D0", "D1", "D2", "D3", "D4", "D5", "D6", "D7", "A0", "A1", "A2", "A3", "A4", "A5", "A6", "A7" }; + + if (isVisible()) + { +#ifndef LOCAL_LAYOUTTEXTS + model->setRowCount(0); +#endif + if (UpdateInfos()) + { + for (size_t i = 0; i < NbLocal; i++) + { + if (LocalInfo[i].PtrVariableName) + { + memset(Value1, 0, sizeof(Value1)); +#ifdef LOCAL_LAYOUTTEXTS + if (i) + { + Local += QString("
"); + } +#else + model->insertRow(i); +#endif + // Local or parameters variables + if (((LocalInfo[i].Op >= DBG_OP_breg0) && (LocalInfo[i].Op <= DBG_OP_breg31)) || (LocalInfo[i].Op == DBG_OP_fbreg)) + { + LocalInfo[i].Adr = m68k_get_reg(NULL, M68K_REG_A6) + LocalInfo[i].Offset; + + if ((LocalInfo[i].Op == DBG_OP_fbreg)) + { + LocalInfo[i].Adr += 8; + } + + if ((LocalInfo[i].Adr >= 0) && (LocalInfo[i].Adr < vjs.DRAM_size)) + { + if ((LocalInfo[i].TypeTag & (DBG_TAG_TYPE_array | DBG_TAG_TYPE_structure))) + { +#if defined(LOCAL_SUPPORTARRAY) || defined(LOCAL_SUPPORTSTRUCTURE) + //memcpy(Value1, &jaguarMainRAM[LocalInfo[i].Adr], 20); +#ifdef LOCAL_LAYOUTTEXTS + //sprintf(Value, "\"%s\"", Value1); +#else + //sprintf(Value, "0x%06X, \"%s\"", LocalInfo[i].Adr, Value1); +#endif + //PtrValue = Value; + PtrValue = NULL; +#else + PtrValue = NULL; +#endif + } + else + { + PtrValue = DBGManager_GetVariableValueFromAdr(LocalInfo[i].Adr, LocalInfo[i].TypeEncoding, LocalInfo[i].TypeByteSize); + } + } + else + { + PtrValue = NULL; + } + } + else + { + // Value from CPU register + if ((LocalInfo[i].Op >= DBG_OP_reg0) && (LocalInfo[i].Op <= DBG_OP_reg31)) + { + LocalInfo[i].PtrCPURegisterName = (char *)CPURegName[(LocalInfo[i].Op - DBG_OP_reg0)]; + sprintf(Value1, "%d", m68k_get_reg(NULL, (m68k_register_t)((size_t)M68K_REG_D0 + (LocalInfo[i].Op - DBG_OP_reg0)))); + PtrValue = Value1; + } + else + { + PtrValue = NULL; + } + } + +#ifndef LOCAL_LAYOUTTEXTS + model->setItem(i, 0, new QStandardItem(QString("%1").arg(LocalInfo[i].PtrVariableName))); +#endif + // Check if the local variable is use by the code + if (!LocalInfo[i].Op) + { +#ifdef LOCAL_LAYOUTTEXTS + sprintf(string, "%i : %s | %s | [Not used]", (i + 1), (LocalInfo[i].PtrVariableBaseTypeName ? LocalInfo[i].PtrVariableBaseTypeName : (char *)"N/A"), LocalInfo[i].PtrVariableName); +#else +#endif + } + else + { +#ifndef LOCAL_LAYOUTTEXTS + model->setItem(i, 1, new QStandardItem(QString("%1").arg(PtrValue))); +#else + sprintf(string, "%i : %s | %s | ", (i + 1), (LocalInfo[i].PtrVariableBaseTypeName ? LocalInfo[i].PtrVariableBaseTypeName : (char *)"N/A"), LocalInfo[i].PtrVariableName); + Local += QString(string); + + if ((unsigned int)LocalInfo[i].Adr) + { + sprintf(string, "0x%06X", (unsigned int)LocalInfo[i].Adr); + } + else + { + if (LocalInfo[i].PtrCPURegisterName) + { + sprintf(string, "%s", LocalInfo[i].PtrCPURegisterName); + } + else + { + sprintf(string, "%s", (char *)"N/A"); + } + } + + Local += QString(string); + sprintf(string, " | %s", (!PtrValue ? (char *)"N/A" : PtrValue)); +#endif + } +#ifndef LOCAL_LAYOUTTEXTS + model->setItem(i, 2, new QStandardItem(QString("%1").arg((LocalInfo[i].PtrVariableBaseTypeName ? LocalInfo[i].PtrVariableBaseTypeName : (char *)"N/A")))); +#else + Local += QString(string); +#endif + } + } + + MSG += QString("Ready"); +#ifdef LOCAL_LAYOUTTEXTS + text->clear(); + text->setText(Local); +#endif + } + else + { + // No locals + MSG += QString("No locals"); + Error = LOCAL_NOLOCALS; +#ifdef LOCAL_LAYOUTTEXTS + text->clear(); +#endif + } + + // Display status bar + if (Error) + { + if ((Error & LOCAL_WARNING)) + { + statusbar->setStyleSheet("background-color: lightyellow; font: bold"); + } + else + { + statusbar->setStyleSheet("background-color: tomato; font: bold"); + } + } + else + { + statusbar->setStyleSheet("background-color: lightgreen; font: bold"); + } + statusbar->showMessage(MSG); + } +} + + +// +void LocalBrowserWindow::keyPressEvent(QKeyEvent * e) +{ + if (e->key() == Qt::Key_Escape) + { + hide(); + } +}