From 07617997f4998d7acb25a52e042779051d2ee68b Mon Sep 17 00:00:00 2001 From: harry Date: Sun, 12 Feb 2023 09:09:17 -0500 Subject: [PATCH] Added hooks to Qt GUI for importing of ld65 debug symbol files. --- src/debugsymboltable.cpp | 13 +++++ src/debugsymboltable.h | 2 + src/drivers/Qt/ConsoleDebugger.cpp | 87 ++++++++++++++++++++++++++++++ src/drivers/Qt/ConsoleDebugger.h | 1 + src/ld65dbg.cpp | 7 +++ src/ld65dbg.h | 2 + 6 files changed, 112 insertions(+) diff --git a/src/debugsymboltable.cpp b/src/debugsymboltable.cpp index 78d65352..062660aa 100644 --- a/src/debugsymboltable.cpp +++ b/src/debugsymboltable.cpp @@ -7,6 +7,7 @@ #include "debug.h" #include "fceu.h" #include "cart.h" +#include "ld65dbg.h" #ifdef __QT_DRIVER__ #include "Qt/ConsoleUtilities.h" @@ -773,6 +774,7 @@ int debugSymbolTable_t::loadGameSymbols(void) return 0; } +//-------------------------------------------------------------- int debugSymbolTable_t::addSymbolAtBankOffset(int bank, int ofs, const char *name, const char *comment) { int result = -1; @@ -909,3 +911,14 @@ const char *debugSymbolTable_t::errorMessage(void) return dbgSymTblErrMsg; } //-------------------------------------------------------------- +int debugSymbolTable_t::ld65LoadDebugFile( const char *dbgFilePath ) +{ + ld65::database db; + + if ( db.dbgFileLoad( dbgFilePath ) ) + { + return -1; + } + return 0; +} +//-------------------------------------------------------------- diff --git a/src/debugsymboltable.h b/src/debugsymboltable.h index caf0dc5a..7deb4586 100644 --- a/src/debugsymboltable.h +++ b/src/debugsymboltable.h @@ -153,6 +153,8 @@ class debugSymbolTable_t const char *errorMessage(void); + int ld65LoadDebugFile( const char *dbgFilePath ); + private: std::map pageMap; FCEU::mutex *cs; diff --git a/src/drivers/Qt/ConsoleDebugger.cpp b/src/drivers/Qt/ConsoleDebugger.cpp index c47812a7..28ccc83f 100644 --- a/src/drivers/Qt/ConsoleDebugger.cpp +++ b/src/drivers/Qt/ConsoleDebugger.cpp @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include @@ -43,6 +44,7 @@ #include #include #include +#include #include #include #include @@ -262,6 +264,83 @@ void ConsoleDebugger::closeWindow(void) deleteLater(); } //---------------------------------------------------------------------------- +void ConsoleDebugger::ld65ImportDebug(void) +{ + int ret, useNativeFileDialogVal; + QString filename; + std::string last; + const char *romPath; + QFileDialog dialog(this, tr("Open ld65 Debug File") ); + QList urls; + QDir d; + + const QStringList filters({ + "dbg files (*.dbg *.DBG)", + "Any files (*)" + }); + + urls << QUrl::fromLocalFile( QDir::rootPath() ); + urls << QUrl::fromLocalFile(QStandardPaths::standardLocations(QStandardPaths::HomeLocation).first()); + urls << QUrl::fromLocalFile(QStandardPaths::standardLocations(QStandardPaths::DesktopLocation).first()); + urls << QUrl::fromLocalFile(QStandardPaths::standardLocations(QStandardPaths::DownloadLocation).first()); + urls << QUrl::fromLocalFile( QDir( FCEUI_GetBaseDirectory() ).absolutePath() ); + + romPath = getRomFile(); + + if ( romPath != nullptr ) + { + std::string dir; + + getDirFromFile( romPath, dir); + + d.setPath(dir.c_str()); + + if ( d.exists() ) + { + urls << QUrl::fromLocalFile( d.absolutePath() ); + + dialog.setDirectory( tr(dir.c_str()) ); + } + } + + dialog.setFileMode(QFileDialog::ExistingFile); + + dialog.setNameFilters( filters ); + + dialog.setViewMode(QFileDialog::List); + dialog.setFilter( QDir::AllEntries | QDir::AllDirs | QDir::Hidden ); + dialog.setLabelText( QFileDialog::Accept, tr("Open") ); + + // Check config option to use native file dialog or not + g_config->getOption ("SDL.UseNativeFileDialog", &useNativeFileDialogVal); + + dialog.setOption(QFileDialog::DontUseNativeDialog, !useNativeFileDialogVal); + dialog.setSidebarUrls(urls); + + ret = dialog.exec(); + + if ( ret ) + { + QStringList fileList; + fileList = dialog.selectedFiles(); + + if ( fileList.size() > 0 ) + { + filename = fileList[0]; + } + } + + if ( filename.isNull() ) + { + return; + } + //qDebug() << "selected file path : " << filename.toUtf8(); + + debugSymbolTable.ld65LoadDebugFile( filename.toStdString().c_str() ); + + return; +} +//---------------------------------------------------------------------------- QMenuBar *ConsoleDebugger::buildMenuBar(void) { QMenu *fileMenu, *viewMenu, *debugMenu, @@ -283,6 +362,14 @@ QMenuBar *ConsoleDebugger::buildMenuBar(void) // File fileMenu = menuBar->addMenu(tr("&File")); + // File -> Import ld65 dbg + act = new QAction(tr("&Import ld65 dbg file"), this); + //act->setShortcut(QKeySequence::Close); + act->setStatusTip(tr("Import ld65 Debug File")); + connect(act, SIGNAL(triggered()), this, SLOT(ld65ImportDebug(void)) ); + + fileMenu->addAction(act); + // File -> Close act = new QAction(tr("&Close"), this); act->setShortcut(QKeySequence::Close); diff --git a/src/drivers/Qt/ConsoleDebugger.h b/src/drivers/Qt/ConsoleDebugger.h index 4c4a3978..6461d532 100644 --- a/src/drivers/Qt/ConsoleDebugger.h +++ b/src/drivers/Qt/ConsoleDebugger.h @@ -557,6 +557,7 @@ class ConsoleDebugger : public QDialog void asmViewCtxMenuRunToCursor(void); void moveTab( QWidget *w, int row, int column); private slots: + void ld65ImportDebug(void); void updatePeriodic(void); void hbarChanged(int value); void vbarChanged(int value); diff --git a/src/ld65dbg.cpp b/src/ld65dbg.cpp index 808c80f5..5b9a5379 100644 --- a/src/ld65dbg.cpp +++ b/src/ld65dbg.cpp @@ -26,4 +26,11 @@ namespace ld65 { } //--------------------------------------------------------------------------------------------------- + int database::dbgFileLoad( const char *dbgFilePath ) + { + + + return 0; + } + //--------------------------------------------------------------------------------------------------- } diff --git a/src/ld65dbg.h b/src/ld65dbg.h index 902102fc..cdbec1c2 100644 --- a/src/ld65dbg.h +++ b/src/ld65dbg.h @@ -64,6 +64,8 @@ namespace ld65 public: database(void); + int dbgFileLoad( const char *dbgFilePath ); + private: std::map scopeMap; std::map segmentMap;