Fix issues with passing streams into lambda, and data not being transferred sometimes.

Documented weirdness of this; perhaps a future version of C++ will allow it.
Write data through 'node' object rather than raw ofstream, like other code in the class.
This commit is contained in:
Stephen Anthony 2020-12-28 16:19:52 -03:30
parent 14a0f5cc64
commit 73a09d3b78
2 changed files with 28 additions and 24 deletions

View File

@ -701,20 +701,20 @@ string DebuggerParser::saveScriptFile(string file)
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void DebuggerParser::saveDump(const FilesystemNode& node, const ostringstream& out, void DebuggerParser::saveDump(const FilesystemNode& node, const stringstream& out,
ostringstream& result) ostringstream& result)
{ {
// cout << "dump " << args[0] << "-" << args[1] << " to " << path.str() << endl; try
std::ofstream ofs(node.getPath(), std::ofstream::out);
if(!ofs.is_open())
result.str(red("Unable to append dump to file " + node.getShortPath()));
else
{ {
ofs << out.str(); node.write(out);
result << " to file " << node.getShortPath(); result << " to file " << node.getShortPath();
} }
catch(...)
{
result.str(red("Unable to append dump to file " + node.getShortPath()));
}
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void DebuggerParser::executeDirective(Device::AccessType type) void DebuggerParser::executeDirective(Device::AccessType type)
{ {
@ -1181,7 +1181,7 @@ void DebuggerParser::executeDump()
commandResult << "dumped "; commandResult << "dumped ";
ostringstream out; stringstream out;
if((args[2] & 0x01) != 0) if((args[2] & 0x01) != 0)
{ {
// dump memory // dump memory
@ -1244,22 +1244,26 @@ void DebuggerParser::executeDump()
if(argCount == 4) if(argCount == 4)
{ {
// FIXME: C++ doesn't currently allow capture of stringstreams
// So we pass a copy of its contents, then re-create the
// stream inside the lambda
// Maybe this will change in a future version
const string outStr = out.str();
const string resultStr = commandResult.str();
DebuggerDialog* dlg = debugger.myDialog; DebuggerDialog* dlg = debugger.myDialog;
const string outStr = out.str(); // ugly, why can't we capture directly?
const string resultStr = commandResult.str(); // same
BrowserDialog::show(dlg, "Save Dump as", path.str(), BrowserDialog::show(dlg, "Save Dump as", path.str(),
BrowserDialog::Mode::FileSave, BrowserDialog::Mode::FileSave,
[=](bool OK, const FilesystemNode& node) [this, dlg, outStr, resultStr]
(bool OK, const FilesystemNode& node)
{ {
if(OK) if(OK)
{ {
ostringstream out, result; stringstream localOut(outStr);
ostringstream localResult(resultStr, std::ios_base::app);
out.str(outStr); // ...and ugly back saveDump(node, localOut, localResult);
result.str(resultStr); dlg->prompt().print(localResult.str() + '\n');
saveDump(node, out, result);
dlg->prompt().print(result.str() + '\n');
} }
dlg->prompt().printPrompt(); dlg->prompt().printPrompt();
}); });
@ -1893,7 +1897,7 @@ void DebuggerParser::executeSave()
BrowserDialog::show(dlg, "Save Workbench as", BrowserDialog::show(dlg, "Save Workbench as",
dlg->instance().userDir().getPath() + cartName() + ".script", dlg->instance().userDir().getPath() + cartName() + ".script",
BrowserDialog::Mode::FileSave, BrowserDialog::Mode::FileSave,
[=](bool OK, const FilesystemNode& node) [this, dlg](bool OK, const FilesystemNode& node)
{ {
if(OK) if(OK)
dlg->prompt().print(saveScriptFile(node.getPath()) + '\n'); dlg->prompt().print(saveScriptFile(node.getPath()) + '\n');
@ -1917,7 +1921,7 @@ void DebuggerParser::executeSaveAccess()
BrowserDialog::show(dlg, "Save Access Counters as", BrowserDialog::show(dlg, "Save Access Counters as",
dlg->instance().userDir().getPath() + cartName() + ".csv", dlg->instance().userDir().getPath() + cartName() + ".csv",
BrowserDialog::Mode::FileSave, BrowserDialog::Mode::FileSave,
[=](bool OK, const FilesystemNode& node) [this, dlg](bool OK, const FilesystemNode& node)
{ {
if(OK) if(OK)
dlg->prompt().print(debugger.cartDebug().saveAccessFile(node.getPath()) + '\n'); dlg->prompt().print(debugger.cartDebug().saveAccessFile(node.getPath()) + '\n');
@ -1948,7 +1952,7 @@ void DebuggerParser::executeSavedisassembly()
BrowserDialog::show(dlg, "Save Disassembly as", BrowserDialog::show(dlg, "Save Disassembly as",
dlg->instance().userDir().getPath() + cartName() + ".asm", dlg->instance().userDir().getPath() + cartName() + ".asm",
BrowserDialog::Mode::FileSave, BrowserDialog::Mode::FileSave,
[=](bool OK, const FilesystemNode& node) [this, dlg](bool OK, const FilesystemNode& node)
{ {
if(OK) if(OK)
dlg->prompt().print(debugger.cartDebug().saveDisassembly(node.getPath()) + '\n'); dlg->prompt().print(debugger.cartDebug().saveDisassembly(node.getPath()) + '\n');
@ -1972,7 +1976,7 @@ void DebuggerParser::executeSaverom()
BrowserDialog::show(dlg, "Save ROM as", BrowserDialog::show(dlg, "Save ROM as",
dlg->instance().userDir().getPath() + cartName() + ".a26", dlg->instance().userDir().getPath() + cartName() + ".a26",
BrowserDialog::Mode::FileSave, BrowserDialog::Mode::FileSave,
[=](bool OK, const FilesystemNode& node) [this, dlg](bool OK, const FilesystemNode& node)
{ {
if(OK) if(OK)
dlg->prompt().print(debugger.cartDebug().saveRom(node.getPath()) + '\n'); dlg->prompt().print(debugger.cartDebug().saveRom(node.getPath()) + '\n');
@ -2000,7 +2004,7 @@ void DebuggerParser::executeSaveses()
BrowserDialog::show(dlg, "Save Session as", BrowserDialog::show(dlg, "Save Session as",
dlg->instance().userDir().getPath() + filename.str(), dlg->instance().userDir().getPath() + filename.str(),
BrowserDialog::Mode::FileSave, BrowserDialog::Mode::FileSave,
[=](bool OK, const FilesystemNode& node) [this, dlg](bool OK, const FilesystemNode& node)
{ {
if(OK) if(OK)
dlg->prompt().print(debugger.prompt().saveBuffer(node) + '\n'); dlg->prompt().print(debugger.prompt().saveBuffer(node) + '\n');

View File

@ -65,7 +65,7 @@ class DebuggerParser
bool validateArgs(int cmd); bool validateArgs(int cmd);
string eval(); string eval();
string saveScriptFile(string file); string saveScriptFile(string file);
void saveDump(const FilesystemNode& node, const ostringstream& out, void saveDump(const FilesystemNode& node, const stringstream& out,
ostringstream& result); ostringstream& result);
const string& cartName() const; const string& cartName() const;