[Scummvm-git-logs] scummvm master -> ac87c01895b14732911f30ad01b2a13eb991d2bc
bluegr
bluegr at gmail.com
Thu Feb 13 21:42:10 UTC 2020
This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
ac87c01895 SCI: debugger: disasm - added 'bcc' parameter, to use in C code
Commit: ac87c01895b14732911f30ad01b2a13eb991d2bc
https://github.com/scummvm/scummvm/commit/ac87c01895b14732911f30ad01b2a13eb991d2bc
Author: Zvika Haramaty (haramaty.zvika at gmail.com)
Date: 2020-02-13T23:42:06+02:00
Commit Message:
SCI: debugger: disasm - added 'bcc' parameter, to use in C code
'bcc' is based on 'bc', but prints in format that's can be used in
C code for patches - just copy and paste (without the address column).
Changed paths:
engines/sci/console.cpp
engines/sci/console.h
engines/sci/engine/scriptdebug.cpp
diff --git a/engines/sci/console.cpp b/engines/sci/console.cpp
index 84f74d9..0ca003c 100644
--- a/engines/sci/console.cpp
+++ b/engines/sci/console.cpp
@@ -3527,12 +3527,14 @@ bool Console::cmdDisassemble(int argc, const char **argv) {
debugPrintf("Valid options are:\n");
debugPrintf(" bwt : Print byte/word tag\n");
debugPrintf(" bc : Print bytecode\n");
+ debugPrintf(" bcc : Print bytecode, formatted to use in C code\n");
return true;
}
reg_t objAddr = NULL_REG;
bool printBytecode = false;
bool printBWTag = false;
+ bool printCSyntax = false;
if (parse_reg_t(_engine->_gamestate, argv[1], &objAddr)) {
debugPrintf("Invalid address passed.\n");
@@ -3564,6 +3566,10 @@ bool Console::cmdDisassemble(int argc, const char **argv) {
printBWTag = true;
else if (!scumm_stricmp(argv[i], "bc"))
printBytecode = true;
+ else if (!scumm_stricmp(argv[i], "bcc")) {
+ printBytecode = true;
+ printCSyntax = true;
+ }
}
reg_t farthestTarget = addr;
@@ -3574,7 +3580,7 @@ bool Console::cmdDisassemble(int argc, const char **argv) {
if (jumpTarget > farthestTarget)
farthestTarget = jumpTarget;
}
- addr = disassemble(_engine->_gamestate, make_reg32(addr.getSegment(), addr.getOffset()), obj, printBWTag, printBytecode);
+ addr = disassemble(_engine->_gamestate, make_reg32(addr.getSegment(), addr.getOffset()), obj, printBWTag, printBytecode, printCSyntax);
if (addr.isNull() && prevAddr < farthestTarget)
addr = prevAddr + 1; // skip past the ret
} while (addr.getOffset() > 0);
@@ -3590,6 +3596,7 @@ bool Console::cmdDisassembleAddress(int argc, const char **argv) {
debugPrintf(" bwt : Print byte/word tag\n");
debugPrintf(" c<x> : Disassemble <x> bytes\n");
debugPrintf(" bc : Print bytecode\n");
+ debugPrintf(" bcc : Print bytecode, formatted to use in C code\n");
return true;
}
@@ -3597,6 +3604,7 @@ bool Console::cmdDisassembleAddress(int argc, const char **argv) {
uint opCount = 1;
bool printBWTag = false;
bool printBytes = false;
+ bool printCSyntax = false;
uint32 size;
if (parse_reg_t(_engine->_gamestate, argv[1], &vpc)) {
@@ -3622,7 +3630,7 @@ bool Console::cmdDisassembleAddress(int argc, const char **argv) {
}
do {
- vpc = disassemble(_engine->_gamestate, make_reg32(vpc.getSegment(), vpc.getOffset()), nullptr, printBWTag, printBytes);
+ vpc = disassemble(_engine->_gamestate, make_reg32(vpc.getSegment(), vpc.getOffset()), nullptr, printBWTag, printBytes, printCSyntax);
} while ((vpc.getOffset() > 0) && (vpc.getOffset() + 6 < size) && (--opCount));
return true;
diff --git a/engines/sci/console.h b/engines/sci/console.h
index 49dfb77..60ff01d 100644
--- a/engines/sci/console.h
+++ b/engines/sci/console.h
@@ -33,7 +33,7 @@ namespace Sci {
class SciEngine;
struct List;
-reg_t disassemble(EngineState *s, reg_t pos, const Object *obj, bool printBWTag, bool printBytecode);
+reg_t disassemble(EngineState *s, reg_t pos, const Object *obj, bool printBWTag, bool printBytecode, bool printCSyntax);
bool isJumpOpcode(EngineState *s, reg_t pos, reg_t& jumpOffset);
class Console : public GUI::Debugger {
diff --git a/engines/sci/engine/scriptdebug.cpp b/engines/sci/engine/scriptdebug.cpp
index 2f0dd00..fc80d1f 100644
--- a/engines/sci/engine/scriptdebug.cpp
+++ b/engines/sci/engine/scriptdebug.cpp
@@ -81,7 +81,7 @@ void DebugState::updateActiveBreakpointTypes() {
}
// Disassembles one command from the heap, returns address of next command or 0 if a ret was encountered.
-reg_t disassemble(EngineState *s, reg_t pos, const Object *obj, bool printBWTag, bool printBytecode) {
+reg_t disassemble(EngineState *s, reg_t pos, const Object *obj, bool printBWTag, bool printBytecode, bool printCSyntax) {
SegmentObj *mobj = s->_segMan->getSegment(pos.getSegment(), SEG_TYPE_SCRIPT);
Script *script_entity = NULL;
reg_t retval = make_reg32(pos.getSegment(), pos.getOffset() + 1);
@@ -117,15 +117,28 @@ reg_t disassemble(EngineState *s, reg_t pos, const Object *obj, bool printBWTag,
return retval;
}
- for (i = 0; i < bytecount; i++)
- debugN("%02x ", scr[pos.getOffset() + i]);
+ for (i = 0; i < bytecount; i++) {
+ const char *f;
+ if (printCSyntax) {
+ f = "0x%02x, "; // avoiding the builtin '#' formatter because it doesn't prepend '0x' to zeroes
+ } else {
+ f = "%02x ";
+ }
+ debugN(f, scr[pos.getOffset() + i]);
+ }
for (i = bytecount; i < 5; i++)
- debugN(" ");
+ if (printCSyntax)
+ debugN(" ");
+ else
+ debugN(" ");
}
opsize &= 1; // byte if true, word if false
+ if (printCSyntax)
+ debugN(" // ");
+
if (printBWTag)
debugN("[%c] ", opsize ? 'B' : 'W');
@@ -491,7 +504,7 @@ void SciEngine::scriptDebug() {
}
debugN("Step #%d\n", s->scriptStepCounter);
- disassemble(s, s->xs->addr.pc, s->_segMan->getObject(s->xs->objp), false, true);
+ disassemble(s, s->xs->addr.pc, s->_segMan->getObject(s->xs->objp), false, true, false);
if (_debugState.runningStep) {
_debugState.runningStep--;
More information about the Scummvm-git-logs
mailing list