enhanced save command, saves to user directory by default

added "autosave" command
This commit is contained in:
Thomas Jentzsch 2021-05-13 17:26:22 +02:00
parent 20aa94f4fc
commit 16a3a977dd
6 changed files with 80 additions and 30 deletions

View File

@ -862,13 +862,16 @@ later re-use.</p>
<ul>
<li>
<b><a name="savecmd">save</a></b>: If you've defined a lot of complex functions, you probably will
want to re-use them in future runs of the debugger. You can save all
your functions, breakpoints, conditional breaks, traps and watches with the
"save" command. If you name your saved file the same as the ROM filename
and place it in the ROM directory, it will be auto-loaded next time you
load the same ROM in Stella. The saved file is just a plain text file
called "&lt;rom_filename&gt;.script", so you can edit it and add new functions, etc.
<b><a name="savecmd">save</a></b>: If you've defined a lot of complex
functions, you probably will want to re-use them in future runs of the
debugger. You can save all your functions, breakpoints, conditional breaks,
traps and watches with the "save" command. By default it is saved in the
user directory with the same as the ROM filename. In this case it will be
auto-loaded next time you load the same ROM in Stella. The saved file is
just a plain text file called "&lt;rom_filename&gt;.script", so you can
edit it and add more functions, etc.
<p>Use "autoSave" to automatically execute the "save" command when
exiting the debugger.</p>
<p>Note: While "save" is ROM specific, you can also create a file called
"autoexec.script" which will be loaded when the debugger starts, no matter
what ROM you have loaded.<p>
@ -927,6 +930,7 @@ Type "help 'cmd'" to see extended information about the given command.</p>
<pre>
a - Set Accumulator to &lt;value&gt;
aud - Mark 'AUD' range in disassembly
autoSave - Automatically execute "save" when exiting the debugger
base - Set default number base to &lt;base&gt; (bin, dec, hex)
bCol - Mark 'BCOL' range in disassembly
break - Set/clear breakpoint at &lt;address&gt; and &lt;bank&gt;
@ -997,7 +1001,7 @@ clearSaveStateIfs - Clear all saveState points
runTo - Run until string xx in disassembly
runToPc - Run until PC is set to value xx
s - Set Stack Pointer to value xx
save - Save breaks, watches, traps and functions to file <xx or ?>
save - Save breaks, watches, traps and functions to file [xx or ?]
saveAccess - Save access counters to CSV file [?]
saveConfig - Save DiStella config file (with default name)
saveDis - Save DiStella disassembly to file [?]

View File

@ -153,6 +153,9 @@ bool Debugger::startWithFatalError(const string& message)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Debugger::quit(bool exitrom)
{
if(myOSystem.settings().getBool("dbg.autosave"))
myParser->run("save");
if(exitrom)
myOSystem.eventHandler().handleEvent(Event::ExitGame);
else
@ -173,7 +176,8 @@ string Debugger::autoExec(StringList* history)
<< myParser->exec(autoexec, history) << endl;
// Also, "romname.script" if present
FilesystemNode romname(myOSystem.romFile().getPathWithExt(".script"));
const string path = myOSystem.userDir().getPath() + myOSystem.romFile().getNameWithExt(".script");
FilesystemNode romname(path);
buf << myParser->exec(romname, history) << endl;
// Init builtins

View File

@ -758,6 +758,16 @@ void DebuggerParser::executeAud()
executeDirective(Device::AUD);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// "autoSave"
void DebuggerParser::executeAutoSave()
{
bool enable = !settings.getBool("dbg.autosave");
settings.setValue("dbg.autosave", enable);
commandResult << "autoSave " << (enable ? "enabled" : "disabled");
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// "base"
void DebuggerParser::executeBase()
@ -1910,24 +1920,29 @@ void DebuggerParser::executeS()
// "save"
void DebuggerParser::executeSave()
{
if(argCount && argStrings[0] == "?")
{
DebuggerDialog* dlg = debugger.myDialog;
DebuggerDialog* dlg = debugger.myDialog;
const string fileName = dlg->instance().userDir().getPath() + cartName() + ".script";
BrowserDialog::show(dlg, "Save Workbench as",
dlg->instance().userDir().getPath() + cartName() + ".script",
BrowserDialog::Mode::FileSave,
[this, dlg](bool OK, const FilesystemNode& node)
if(argCount)
{
if(argStrings[0] == "?")
{
if(OK)
dlg->prompt().print(saveScriptFile(node.getPath()) + '\n');
dlg->prompt().printPrompt();
});
// avoid printing a new prompt
commandResult.str("_NO_PROMPT");
BrowserDialog::show(dlg, "Save Workbench as", fileName,
BrowserDialog::Mode::FileSave,
[this, dlg](bool OK, const FilesystemNode& node)
{
if(OK)
dlg->prompt().print(saveScriptFile(node.getPath()) + '\n');
dlg->prompt().printPrompt();
});
// avoid printing a new prompt
commandResult.str("_NO_PROMPT");
}
else
commandResult << saveScriptFile(argStrings[0]);
}
else
commandResult << saveScriptFile(argStrings[0]);
commandResult << saveScriptFile(fileName);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -2516,6 +2531,16 @@ DebuggerParser::CommandArray DebuggerParser::commands = { {
std::mem_fn(&DebuggerParser::executeAud)
},
{
"autoSave",
"Toggle automatic saving of commands (see 'save')",
"Example: autoSave (no parameters)",
false,
true,
{ Parameters::ARG_END_ARGS },
std::mem_fn(&DebuggerParser::executeAutoSave)
},
{
"base",
"Set default number base to <base>",
@ -3230,10 +3255,10 @@ DebuggerParser::CommandArray DebuggerParser::commands = { {
{
"save",
"Save breaks, watches, traps and functions to file <xx or ?>",
"Example: save commands.script, save ?\n"
"Save breaks, watches, traps and functions to file [xx or ?]",
"Example: save, save commands.script, save ?\n"
"NOTE: saves to user dir by default",
true,
false,
false,
{ Parameters::ARG_FILE, Parameters::ARG_END_ARGS },
std::mem_fn(&DebuggerParser::executeSave)

View File

@ -101,7 +101,7 @@ class DebuggerParser
std::array<Parameters, 10> parms;
std::function<void (DebuggerParser*)> executor;
};
using CommandArray = std::array<Command, 102>;
using CommandArray = std::array<Command, 103>;
static CommandArray commands;
struct Trap
@ -150,6 +150,7 @@ class DebuggerParser
// List of available command methods
void executeA();
void executeAud();
void executeAutoSave();
void executeBase();
void executeBCol();
void executeBreak();

View File

@ -386,8 +386,22 @@ void PromptWidget::loadConfig()
print(instance().debugger().cartDebug().loadConfigFile() + "\n");
print(instance().debugger().cartDebug().loadListFile() + "\n");
print(instance().debugger().cartDebug().loadSymbolFile() + "\n");
bool extra = false;
if(instance().settings().getBool("dbg.autosave"))
{
print(DebuggerParser::inverse(" autoSave enabled "));
print("\177 "); // must switch inverse here!
extra = true;
}
if(instance().settings().getBool("dbg.logbreaks"))
print(DebuggerParser::inverse(" logBreaks enabled \n"));
{
print(DebuggerParser::inverse(" logBreaks enabled "));
extra = true;
}
if(extra)
print("\n");
print(PROMPT);
_promptStartPos = _promptEndPos = _currentPos;

View File

@ -189,6 +189,7 @@ Settings::Settings()
setPermanent("dbg.uhex", "false");
setPermanent("dbg.ghostreadstrap", "true");
setPermanent("dbg.logbreaks", "false");
setPermanent("dbg.autosave", "false");
setPermanent("dis.resolve", "true");
setPermanent("dis.gfxformat", "2");
setPermanent("dis.showaddr", "true");
@ -614,8 +615,9 @@ void Settings::usage() const
<< " -dbg.fontstyle <0-3> Font style to use in debugger window (bold vs.\n"
<< " normal)\n"
<< " -dbg.ghostreadstrap <1|0> Debugger traps on 'ghost' reads\n"
<< " -dbg.uhex <0|1> lower-/uppercase HEX display\n"
<< " -dbg.logbreaks <0|1> log breaks and traps and continue emulation\n"
<< " -dbg.uhex <0|1> Lower-/uppercase HEX display\n"
<< " -dbg.logbreaks <0|1> Log breaks and traps and continue emulation\n"
<< " -dbg.autosave <0|1> Automatically save breaks, traps etc.\n"
<< " -break <address> Set a breakpoint at 'address'\n"
<< " -debug Start in debugger mode\n"
<< endl