From b37fb451729d3b743c243e11d138bcf14704e70d Mon Sep 17 00:00:00 2001 From: Matthew Budd Date: Tue, 15 Sep 2020 21:32:54 -0400 Subject: [PATCH] Added symbolic debug edit window logic. --- src/drivers/Qt/ConsoleDebugger.cpp | 138 ++++++++++++++++++++++++++++- src/drivers/Qt/ConsoleDebugger.h | 2 + src/drivers/Qt/SymbolicDebug.cpp | 24 ++++- src/drivers/Qt/SymbolicDebug.h | 4 +- 4 files changed, 165 insertions(+), 3 deletions(-) diff --git a/src/drivers/Qt/ConsoleDebugger.cpp b/src/drivers/Qt/ConsoleDebugger.cpp index 8d5738dd..a6ab0cda 100644 --- a/src/drivers/Qt/ConsoleDebugger.cpp +++ b/src/drivers/Qt/ConsoleDebugger.cpp @@ -529,7 +529,14 @@ void ConsoleDebugger::openBpEditWindow( int editIdx, watchpointinfo *wp ) QPushButton *okButton, *cancelButton; QRadioButton *cpu_radio, *ppu_radio, *sprite_radio; - dialog.setWindowTitle( tr("Add Breakpoint") ); + if ( editIdx >= 0 ) + { + dialog.setWindowTitle( tr("Edit Breakpoint") ); + } + else + { + dialog.setWindowTitle( tr("Add Breakpoint") ); + } hbox = new QHBoxLayout(); mainLayout = new QVBoxLayout(); @@ -764,6 +771,129 @@ void ConsoleDebugger::openBpEditWindow( int editIdx, watchpointinfo *wp ) } } //---------------------------------------------------------------------------- +void ConsoleDebugger::openDebugSymbolEditWindow( int addr ) +{ + int ret, bank, charWidth; + QDialog dialog(this); + QHBoxLayout *hbox; + QVBoxLayout *mainLayout; + QLabel *lbl; + QLineEdit *filepath, *addrEntry, *nameEntry, *commentEntry; + QPushButton *okButton, *cancelButton; + char stmp[512]; + debugSymbol_t *sym; + QFontMetrics fm(font); + +#if QT_VERSION > QT_VERSION_CHECK(5, 11, 0) + charWidth = fm.horizontalAdvance(QLatin1Char('2')); +#else + charWidth = fm.width(QLatin1Char('2')); +#endif + + if ( addr < 0x8000 ) + { + bank = 0; + } + else + { + bank = getBank( addr ); + } + + sym = debugSymbolTable.getSymbolAtBankOffset( bank, addr ); + + generateNLFilenameForAddress( addr, stmp ); + + dialog.setWindowTitle( tr("Symbolic Debug Naming") ); + + hbox = new QHBoxLayout(); + mainLayout = new QVBoxLayout(); + + lbl = new QLabel( tr("File") ); + filepath = new QLineEdit(); + filepath->setFont( font ); + filepath->setText( tr(stmp) ); + filepath->setReadOnly( true ); + filepath->setMinimumWidth( charWidth * (filepath->text().size() + 4) ); + + hbox->addWidget( lbl ); + hbox->addWidget( filepath ); + + mainLayout->addLayout( hbox ); + + sprintf( stmp, "%04X", addr ); + + hbox = new QHBoxLayout(); + lbl = new QLabel( tr("Address") ); + addrEntry = new QLineEdit(); + addrEntry->setFont( font ); + addrEntry->setText( tr(stmp) ); + addrEntry->setReadOnly( true ); + addrEntry->setAlignment(Qt::AlignCenter); + addrEntry->setMaximumWidth( charWidth * 6 ); + + hbox->addWidget( lbl ); + hbox->addWidget( addrEntry ); + + lbl = new QLabel( tr("Name") ); + nameEntry = new QLineEdit(); + + hbox->addWidget( lbl ); + hbox->addWidget( nameEntry ); + + mainLayout->addLayout( hbox ); + + hbox = new QHBoxLayout(); + lbl = new QLabel( tr("Comment") ); + commentEntry = new QLineEdit(); + + hbox->addWidget( lbl ); + hbox->addWidget( commentEntry ); + + mainLayout->addLayout( hbox ); + + hbox = new QHBoxLayout(); + okButton = new QPushButton( tr("OK") ); + cancelButton = new QPushButton( tr("Cancel") ); + + mainLayout->addLayout( hbox ); + hbox->addWidget( cancelButton ); + hbox->addWidget( okButton ); + + connect( okButton, SIGNAL(clicked(void)), &dialog, SLOT(accept(void)) ); + connect( cancelButton, SIGNAL(clicked(void)), &dialog, SLOT(reject(void)) ); + + if ( sym != NULL ) + { + nameEntry->setText( tr(sym->name.c_str()) ); + commentEntry->setText( tr(sym->comment.c_str()) ); + } + + dialog.setLayout( mainLayout ); + + ret = dialog.exec(); + + if ( ret == QDialog::Accepted ) + { + if ( sym == NULL ) + { + sym = new debugSymbol_t(); + sym->ofs = addr; + sym->name = nameEntry->text().toStdString(); + sym->comment = commentEntry->text().toStdString(); + + debugSymbolTable.addSymbolAtBankOffset( bank, addr, sym ); + } + else + { + sym->name = nameEntry->text().toStdString(); + sym->comment = commentEntry->text().toStdString(); + } + fceuWrapperLock(); + asmView->updateAssemblyView(); + fceuWrapperUnLock(); + } +} +//---------------------------------------------------------------------------- void ConsoleDebugger::bpListUpdate( bool reset ) { QTreeWidgetItem *item; @@ -1196,6 +1326,11 @@ void ConsoleDebugger::asmViewCtxMenuAddBP(void) } //---------------------------------------------------------------------------- +void ConsoleDebugger::asmViewCtxMenuAddSym(void) +{ + openDebugSymbolEditWindow( asmView->getCtxMenuAddr() ); +} +//---------------------------------------------------------------------------- int QAsmView::getAsmLineFromAddr(int addr) { int line = -1; @@ -2211,6 +2346,7 @@ void QAsmView::contextMenuEvent(QContextMenuEvent *event) act = new QAction(tr("Add Symbolic Debug Name"), this); menu.addAction(act); + connect( act, SIGNAL(triggered(void)), parent, SLOT(asmViewCtxMenuAddSym(void)) ); //connect( act, SIGNAL(triggered(void)), this, SLOT(addBookMarkCB(void)) ); menu.exec(event->globalPos()); diff --git a/src/drivers/Qt/ConsoleDebugger.h b/src/drivers/Qt/ConsoleDebugger.h index 4b34dfda..53aae637 100644 --- a/src/drivers/Qt/ConsoleDebugger.h +++ b/src/drivers/Qt/ConsoleDebugger.h @@ -131,6 +131,7 @@ class ConsoleDebugger : public QDialog void updateRegisterView(void); void breakPointNotify(int bpNum); void openBpEditWindow(int editIdx = -1, watchpointinfo *wp = NULL ); + void openDebugSymbolEditWindow( int addr ); QLabel *asmLineSelLbl; protected: @@ -195,6 +196,7 @@ class ConsoleDebugger : public QDialog public slots: void closeWindow(void); void asmViewCtxMenuAddBP(void); + void asmViewCtxMenuAddSym(void); private slots: void updatePeriodic(void); void vbarChanged(int value); diff --git a/src/drivers/Qt/SymbolicDebug.cpp b/src/drivers/Qt/SymbolicDebug.cpp index f48ff8c2..5385c94b 100644 --- a/src/drivers/Qt/SymbolicDebug.cpp +++ b/src/drivers/Qt/SymbolicDebug.cpp @@ -202,7 +202,7 @@ void debugSymbolTable_t::clear(void) pageMap.clear(); } //-------------------------------------------------------------- -static int generateNLFilenameForAddress(int address, char *NLfilename) +int generateNLFilenameForAddress(int address, char *NLfilename) { int i; const char *romFile; @@ -478,6 +478,28 @@ int debugSymbolTable_t::loadGameSymbols(void) return 0; } //-------------------------------------------------------------- +int debugSymbolTable_t::addSymbolAtBankOffset( int bank, int ofs, debugSymbol_t *sym ) +{ + debugSymbolPage_t *page; + std::map ::iterator it; + + it = pageMap.find( bank ); + + if ( it == pageMap.end() ) + { + page = new debugSymbolPage_t(); + page->pageNum = bank; + pageMap[ bank ] = page; + } + else + { + page = it->second; + } + page->addSymbol( sym ); + + return 0; +} +//-------------------------------------------------------------- debugSymbol_t *debugSymbolTable_t::getSymbolAtBankOffset( int bank, int ofs ) { debugSymbol_t*sym = NULL; diff --git a/src/drivers/Qt/SymbolicDebug.h b/src/drivers/Qt/SymbolicDebug.h index 172074ba..79e6800d 100644 --- a/src/drivers/Qt/SymbolicDebug.h +++ b/src/drivers/Qt/SymbolicDebug.h @@ -54,9 +54,10 @@ class debugSymbolTable_t debugSymbol_t *getSymbolAtBankOffset( int bank, int ofs ); + int addSymbolAtBankOffset( int bank, int ofs, debugSymbol_t *sym ); + private: std::map pageMap; - }; @@ -69,5 +70,6 @@ extern debugSymbolTable_t debugSymbolTable; //}; +int generateNLFilenameForAddress(int address, char *NLfilename); #endif