aboutsummaryrefslogtreecommitdiff
path: root/engines/sci/engine/scriptdebug.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'engines/sci/engine/scriptdebug.cpp')
-rw-r--r--engines/sci/engine/scriptdebug.cpp46
1 files changed, 38 insertions, 8 deletions
diff --git a/engines/sci/engine/scriptdebug.cpp b/engines/sci/engine/scriptdebug.cpp
index 103a016972..4b60626b2e 100644
--- a/engines/sci/engine/scriptdebug.cpp
+++ b/engines/sci/engine/scriptdebug.cpp
@@ -67,6 +67,37 @@ extern const char *selector_name(EngineState *s, int selector);
DebugState g_debugState;
+int propertyOffsetToId(SegManager *segMan, int prop_ofs, reg_t objp) {
+ Object *obj = segMan->getObject(objp);
+ byte *selectoroffset;
+ int selectors;
+
+ if (!obj) {
+ warning("Applied propertyOffsetToId on non-object at %04x:%04x", PRINT_REG(objp));
+ return -1;
+ }
+
+ selectors = obj->getVarCount();
+
+ if (getSciVersion() < SCI_VERSION_1_1)
+ selectoroffset = ((byte *)(obj->_baseObj)) + SCRIPT_SELECTOR_OFFSET + selectors * 2;
+ else {
+ if (!(obj->getInfoSelector().offset & SCRIPT_INFO_CLASS)) {
+ obj = segMan->getObject(obj->getSuperClassSelector());
+ selectoroffset = (byte *)obj->_baseVars;
+ } else
+ selectoroffset = (byte *)obj->_baseVars;
+ }
+
+ if (prop_ofs < 0 || (prop_ofs >> 1) >= selectors) {
+ warning("Applied propertyOffsetToId to invalid property offset %x (property #%d not in [0..%d]) on object at %04x:%04x",
+ prop_ofs, prop_ofs >> 1, selectors - 1, PRINT_REG(objp));
+ return -1;
+ }
+
+ return READ_SCI11ENDIAN_UINT16(selectoroffset + prop_ofs);
+}
+
// 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, int print_bw_tag, int print_bytecode) {
SegmentObj *mobj = s->_segMan->getSegment(pos.segment, SEG_TYPE_SCRIPT);
@@ -85,7 +116,7 @@ reg_t disassemble(EngineState *s, reg_t pos, int print_bw_tag, int print_bytecod
script_entity = (Script *)mobj;
scr = script_entity->_buf;
- scr_size = script_entity->getBufSize();
+ scr_size = script_entity->_bufSize;
if (pos.offset >= scr_size) {
warning("Trying to disassemble beyond end of script");
@@ -193,11 +224,10 @@ reg_t disassemble(EngineState *s, reg_t pos, int print_bw_tag, int print_bytecod
if (pos == scriptState.xs->addr.pc) { // Extra information if debugging the current opcode
if ((opcode == op_pTos) || (opcode == op_sTop) || (opcode == op_pToa) || (opcode == op_aTop) ||
(opcode == op_dpToa) || (opcode == op_ipToa) || (opcode == op_dpTos) || (opcode == op_ipTos)) {
- const Object *obj = s->_segMan->getObject(scriptState.xs->objp);
- if (!obj)
- warning("Attempted to reference on non-object at %04x:%04x", PRINT_REG(scriptState.xs->objp));
- else
- printf(" (%s)", selector_name(s, obj->propertyOffsetToId(s->_segMan, scr[pos.offset + 1])));
+ int prop_ofs = scr[pos.offset + 1];
+ int prop_id = propertyOffsetToId(s->_segMan, prop_ofs, scriptState.xs->objp);
+
+ printf(" (%s)", selector_name(s, prop_id));
}
}
@@ -246,7 +276,7 @@ reg_t disassemble(EngineState *s, reg_t pos, int print_bw_tag, int print_bytecod
printf(" %s::%s[", name, (selector > kernel->getSelectorNamesSize()) ? "<invalid>" : selector_name(s, selector));
- switch (lookupSelector(s->_segMan, called_obj_addr, selector, 0, &fun_ref)) {
+ switch (lookup_selector(s->_segMan, called_obj_addr, selector, 0, &fun_ref)) {
case kSelectorMethod:
printf("FUNCT");
argc += restmod;
@@ -303,7 +333,7 @@ void script_debug(EngineState *s) {
if (mobj) {
Script *scr = (Script *)mobj;
byte *code_buf = scr->_buf;
- int code_buf_size = scr->getBufSize();
+ int code_buf_size = scr->_bufSize;
int opcode = scriptState.xs->addr.pc.offset >= code_buf_size ? 0 : code_buf[scriptState.xs->addr.pc.offset];
int op = opcode >> 1;
int paramb1 = scriptState.xs->addr.pc.offset + 1 >= code_buf_size ? 0 : code_buf[scriptState.xs->addr.pc.offset + 1];