From da05b56cbad4398393258d47b91805f107bd74f6 Mon Sep 17 00:00:00 2001 From: harry Date: Mon, 20 Feb 2023 18:36:07 -0500 Subject: [PATCH] Added checkbox to Qt debugger menu to control trace logger auto start function on debugger open. Also added code to stop the trace logger on debugger close if it was the debugger who started it in the first place. --- src/drivers/Qt/ConsoleDebugger.cpp | 47 ++++++++++++++++++++++++++---- src/drivers/Qt/ConsoleDebugger.h | 2 ++ src/drivers/Qt/TraceLogger.cpp | 19 ++++++++++++ src/drivers/Qt/TraceLogger.h | 3 +- src/drivers/Qt/config.cpp | 1 + 5 files changed, 66 insertions(+), 6 deletions(-) diff --git a/src/drivers/Qt/ConsoleDebugger.cpp b/src/drivers/Qt/ConsoleDebugger.cpp index 4b9ae9f0..6f64cb4f 100644 --- a/src/drivers/Qt/ConsoleDebugger.cpp +++ b/src/drivers/Qt/ConsoleDebugger.cpp @@ -106,6 +106,7 @@ ConsoleDebugger::ConsoleDebugger(QWidget *parent) QMenuBar *menuBar; QSettings settings; std::string fontString; + bool autoStartTraceLogger = false; g_config->getOption("SDL.DebuggerCpuStatusFont", &fontString); @@ -210,8 +211,19 @@ ConsoleDebugger::ConsoleDebugger(QWidget *parent) connect( this, SIGNAL(rejected(void)), this, SLOT(deleteLater(void))); - // Start Trace Logger for Step Back Function - FCEUD_TraceLoggerStart(); + g_config->getOption("SDL.DebugAutoStartTraceLogger", &autoStartTraceLogger); + + startedTraceLogger = false; + + if (autoStartTraceLogger) + { + // Start Trace Logger for Step Back Function + if (!FCEUD_TraceLoggerRunning()) + { + FCEUD_TraceLoggerStart(); + startedTraceLogger = true; + } + } } //---------------------------------------------------------------------------- ConsoleDebugger::~ConsoleDebugger(void) @@ -223,6 +235,12 @@ ConsoleDebugger::~ConsoleDebugger(void) saveDisplayViews(); + if (startedTraceLogger && FCEUD_TraceLoggerRunning() ) + { + FCEUD_TraceLoggerStop(); + startedTraceLogger = false; + } + if ( dbgWin == this ) { dbgWin = NULL; @@ -822,18 +840,30 @@ QMenuBar *ConsoleDebugger::buildMenuBar(void) optMenu->addAction(act); - // Options -> Load .DEB + // Options -> Load .FDB g_config->getOption( "SDL.AutoLoadDebugFiles", &opt ); - act = new QAction(tr("&Load .DEB on ROM Load"), this); + act = new QAction(tr("&Load .FDB on ROM Load"), this); //act->setShortcut(QKeySequence( tr("F7") ) ); - act->setStatusTip(tr("&Load .DEB on ROM Load")); + act->setStatusTip(tr("&Load .FDB on ROM Load")); act->setCheckable(true); act->setChecked( opt ? true : false ); connect( act, SIGNAL(triggered(bool)), this, SLOT(debFileAutoLoadCB(bool)) ); optMenu->addAction(act); + // Options -> Auto Start Trace Logger + g_config->getOption( "SDL.DebugAutoStartTraceLogger", &opt ); + + act = new QAction(tr("Auto Start &Trace Logger on Debugger Open"), this); + //act->setShortcut(QKeySequence( tr("F7") ) ); + act->setStatusTip(tr("Auto Start &Trace Logger on Debugger Open")); + act->setCheckable(true); + act->setChecked( opt ? true : false ); + connect( act, SIGNAL(triggered(bool)), this, SLOT(autoStartTraceLoggerOnOpen(bool)) ); + + optMenu->addAction(act); + optMenu->addSeparator(); // Symbols @@ -2656,6 +2686,13 @@ void ConsoleDebugger::debFileAutoLoadCB( bool value ) } } //---------------------------------------------------------------------------- +void ConsoleDebugger::autoStartTraceLoggerOnOpen( bool value ) +{ + int autoStartTraceLogger = value; + + g_config->setOption("SDL.DebugAutoStartTraceLogger", autoStartTraceLogger); +} +//---------------------------------------------------------------------------- void ConsoleDebugger::changeAsmFontCB(void) { bool ok = false; diff --git a/src/drivers/Qt/ConsoleDebugger.h b/src/drivers/Qt/ConsoleDebugger.h index 6461d532..be5b2e0b 100644 --- a/src/drivers/Qt/ConsoleDebugger.h +++ b/src/drivers/Qt/ConsoleDebugger.h @@ -531,6 +531,7 @@ class ConsoleDebugger : public QDialog int selBmAddrVal; bool windowUpdateReq; + bool startedTraceLogger; private: void setRegsFromEntry(void); @@ -590,6 +591,7 @@ class ConsoleDebugger : public QDialog void registerNameEnableCB(bool value); void autoOpenDebugCB( bool value ); void debFileAutoLoadCB( bool value ); + void autoStartTraceLoggerOnOpen(bool value); void breakOnBadOpcodeCB(bool value); void breakOnNewCodeCB(bool value); void breakOnNewDataCB(bool value); diff --git a/src/drivers/Qt/TraceLogger.cpp b/src/drivers/Qt/TraceLogger.cpp index ba2ffc9d..b8fe13b4 100644 --- a/src/drivers/Qt/TraceLogger.cpp +++ b/src/drivers/Qt/TraceLogger.cpp @@ -1291,6 +1291,25 @@ int FCEUD_TraceLoggerStart(void) return logging; } //---------------------------------------------------- +int FCEUD_TraceLoggerStop(void) +{ + if (!logging) + { + return 0; + } + if (traceLogWindow) + { + traceLogWindow->toggleLoggingOnOff(); + } + else + { + logging = 0; + msleep(1); + pushMsgToLogBuffer("Logging Finished"); + } + return logging; +} +//---------------------------------------------------- int FCEUD_TraceLoggerRunning(void) { return logging; diff --git a/src/drivers/Qt/TraceLogger.h b/src/drivers/Qt/TraceLogger.h index bc9bb58b..dce61a00 100644 --- a/src/drivers/Qt/TraceLogger.h +++ b/src/drivers/Qt/TraceLogger.h @@ -200,9 +200,9 @@ protected: private: public slots: void closeWindow(void); + void toggleLoggingOnOff(void); private slots: void updatePeriodic(void); - void toggleLoggingOnOff(void); void autoUpdateStateChanged(int state); void logToFileStateChanged(int state); void logRegStateChanged(int state); @@ -232,6 +232,7 @@ int initTraceLogBuffer(int maxRecs); void openTraceLoggerWindow(QWidget *parent); +int FCEUD_TraceLoggerStop(void); int FCEUD_TraceLoggerStart(void); int FCEUD_TraceLoggerRunning(void); int FCEUD_TraceLoggerBackUpInstruction(void); diff --git a/src/drivers/Qt/config.cpp b/src/drivers/Qt/config.cpp index cffe8c2a..fc314283 100644 --- a/src/drivers/Qt/config.cpp +++ b/src/drivers/Qt/config.cpp @@ -686,6 +686,7 @@ InitConfig() config->addOption("SDL.DebuggerBreakOnBadOpcodes", 0); config->addOption("SDL.DebuggerBreakOnUnloggedCode", 0); config->addOption("SDL.DebuggerBreakOnUnloggedData", 0); + config->addOption("SDL.DebugAutoStartTraceLogger", 0); // Code Data Logger Options config->addOption("autoSaveCDL" , "SDL.AutoSaveCDL", 1);