From a95d40c682705e63818d6107eb45bfb78acc4ccd Mon Sep 17 00:00:00 2001 From: thrust26 Date: Tue, 12 Jan 2021 15:46:36 +0100 Subject: [PATCH] create DebuggerDialog and included OptionsDialog on demand only --- src/debugger/Debugger.cxx | 32 +++++++++++++++++------------ src/debugger/Debugger.hxx | 9 ++++++-- src/debugger/DebuggerParser.cxx | 12 +++++------ src/debugger/gui/DebuggerDialog.cxx | 13 +++++++++--- 4 files changed, 42 insertions(+), 24 deletions(-) diff --git a/src/debugger/Debugger.cxx b/src/debugger/Debugger.cxx index 29f73a705..38b5d9098 100644 --- a/src/debugger/Debugger.cxx +++ b/src/debugger/Debugger.cxx @@ -84,7 +84,6 @@ Debugger::Debugger(OSystem& osystem, Console& console) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Debugger::~Debugger() { - delete myDialog; myDialog = nullptr; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -100,11 +99,6 @@ void Debugger::initialize() myOSystem.settings().setValue("dbg.res", mySize); - delete myDialog; myDialog = nullptr; - myDialog = new DebuggerDialog(myOSystem, *this, 0, 0, mySize.w, mySize.h); - - myCartDebug->setDebugWidget(&(myDialog->cartDebug())); - saveOldState(); } @@ -129,8 +123,8 @@ bool Debugger::start(const string& message, int address, bool read, buf << message; if(address > -1) buf << cartDebug().getLabel(address, read, 4); - myDialog->message().setText(buf.str()); - myDialog->message().setToolTip(toolTip); + dialog().message().setText(buf.str()); + dialog().message().setToolTip(toolTip); return true; } return false; @@ -143,7 +137,7 @@ bool Debugger::startWithFatalError(const string& message) { // This must be done *after* we enter debug mode, // so the dialog is properly shown - myDialog->showFatalMessage(message); + dialog().showFatalMessage(message); return true; } return false; @@ -580,8 +574,8 @@ void Debugger::nextFrame(int frames) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void Debugger::updateRewindbuttons(const RewindManager& r) { - myDialog->rewindButton().setEnabled(!r.atFirst()); - myDialog->unwindButton().setEnabled(!r.atLast()); + dialog().rewindButton().setEnabled(!r.atFirst()); + dialog().unwindButton().setEnabled(!r.atLast()); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -685,13 +679,13 @@ void Debugger::setStartState() updateRewindbuttons(r); // Set the 're-disassemble' flag, but don't do it until the next scheduled time - myDialog->rom().invalidate(false); + dialog().rom().invalidate(false); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void Debugger::setQuitState() { - myDialog->saveConfig(); + dialog().saveConfig(); saveOldState(); // Bus must be unlocked for normal operation when leaving debugger mode @@ -846,6 +840,18 @@ bool Debugger::canExit() const return baseDialogIsActive(); } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +DebuggerDialog& Debugger::dialog() +{ + if(myDialog == nullptr) + { + myDialog = make_unique(myOSystem, *this, 0, 0, mySize.w, mySize.h); + myCartDebug->setDebugWidget(&(myDialog->cartDebug())); + } + + return *myDialog; +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - std::array Debugger::ourBuiltinFunctions = { { // left joystick: diff --git a/src/debugger/Debugger.hxx b/src/debugger/Debugger.hxx index 0e7de4c36..2623fb5d3 100644 --- a/src/debugger/Debugger.hxx +++ b/src/debugger/Debugger.hxx @@ -279,7 +279,7 @@ class Debugger : public DialogContainer /** Return (and possibly create) the bottom-most dialog of this container. */ - Dialog* baseDialog() override { return myDialog; } + Dialog* baseDialog() override { return &dialog(); } private: /** @@ -332,11 +332,16 @@ class Debugger : public DialogContainer void loadState(int state); void loadAllStates(); + /** + Return (and possibly create) the debugger dialog. + */ + DebuggerDialog& dialog(); + private: Console& myConsole; System& mySystem; - DebuggerDialog* myDialog{nullptr}; + unique_ptr myDialog; unique_ptr myParser; unique_ptr myCartDebug; unique_ptr myCpuDebug; diff --git a/src/debugger/DebuggerParser.cxx b/src/debugger/DebuggerParser.cxx index eb5904e58..3b1a0d51f 100644 --- a/src/debugger/DebuggerParser.cxx +++ b/src/debugger/DebuggerParser.cxx @@ -1251,7 +1251,7 @@ void DebuggerParser::executeDump() const string outStr = out.str(); const string resultStr = commandResult.str(); - DebuggerDialog* dlg = debugger.myDialog; + DebuggerDialog* dlg = &debugger.dialog(); BrowserDialog::show(dlg, "Save Dump as", path.str(), BrowserDialog::Mode::FileSave, [this, dlg, outStr, resultStr] @@ -1892,7 +1892,7 @@ void DebuggerParser::executeSave() { if(argCount && argStrings[0] == "?") { - DebuggerDialog* dlg = debugger.myDialog; + DebuggerDialog* dlg = &debugger.dialog(); BrowserDialog::show(dlg, "Save Workbench as", dlg->instance().userDir().getPath() + cartName() + ".script", @@ -1916,7 +1916,7 @@ void DebuggerParser::executeSaveAccess() { if(argCount && argStrings[0] == "?") { - DebuggerDialog* dlg = debugger.myDialog; + DebuggerDialog* dlg = &debugger.dialog(); BrowserDialog::show(dlg, "Save Access Counters as", dlg->instance().userDir().getPath() + cartName() + ".csv", @@ -1947,7 +1947,7 @@ void DebuggerParser::executeSavedisassembly() { if(argCount && argStrings[0] == "?") { - DebuggerDialog* dlg = debugger.myDialog; + DebuggerDialog* dlg = &debugger.dialog(); BrowserDialog::show(dlg, "Save Disassembly as", dlg->instance().userDir().getPath() + cartName() + ".asm", @@ -1971,7 +1971,7 @@ void DebuggerParser::executeSaverom() { if(argCount && argStrings[0] == "?") { - DebuggerDialog* dlg = debugger.myDialog; + DebuggerDialog* dlg = &debugger.dialog(); BrowserDialog::show(dlg, "Save ROM as", dlg->instance().userDir().getPath() + cartName() + ".a26", @@ -1999,7 +1999,7 @@ void DebuggerParser::executeSaveses() if(argCount && argStrings[0] == "?") { - DebuggerDialog* dlg = debugger.myDialog; + DebuggerDialog* dlg = &debugger.dialog(); BrowserDialog::show(dlg, "Save Session as", dlg->instance().userDir().getPath() + filename.str(), diff --git a/src/debugger/gui/DebuggerDialog.cxx b/src/debugger/gui/DebuggerDialog.cxx index 01b476080..52324ec4f 100644 --- a/src/debugger/gui/DebuggerDialog.cxx +++ b/src/debugger/gui/DebuggerDialog.cxx @@ -67,9 +67,6 @@ DebuggerDialog::DebuggerDialog(OSystem& osystem, DialogContainer& parent, // Inform the TIA output widget about its associated zoom widget myTiaOutput->setZoomWidget(myTiaZoom); - - myOptions = make_unique(osystem, parent, this, w, h, - Menu::AppMode::debugger); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -255,7 +252,17 @@ void DebuggerDialog::handleCommand(CommandSender* sender, int cmd, case kDDOptionsCmd: saveConfig(); + + if(myOptions == nullptr) + { + uInt32 w = 0, h = 0; + + getDynamicBounds(w, h); + myOptions = make_unique(instance(), parent(), this, w, h, + Menu::AppMode::debugger); + } myOptions->open(); + loadConfig(); break;