Skip to content

Commit 5f5b611

Browse files
committed
Add offset in error messages of _read_and_exec_opcode
1 parent 74581d5 commit 5f5b611

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

javaobj.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -525,19 +525,22 @@ def _read_and_exec_opcode(self, ident=0, expect=None):
525525
:raise IOError: Read opcode is not one of the expected ones
526526
:raise RuntimeError: Unknown opcode
527527
"""
528+
position = self.object_stream.tell()
528529
(opid,) = self._readStruct(">B")
529-
log_debug("OpCode: 0x{0:X} -- {1}"
530-
.format(opid, OpCodeDebug.op_id(opid)), ident)
530+
log_debug("OpCode: 0x{0:X} -- {1} (at offset 0x{2:X})"
531+
.format(opid, OpCodeDebug.op_id(opid), position), ident)
531532

532533
if expect and opid not in expect:
533-
raise IOError("Unexpected opcode 0x{0:X} -- {1}"
534-
.format(opid, OpCodeDebug.op_id(opid)))
534+
raise IOError(
535+
"Unexpected opcode 0x{0:X} -- {1} (at offset 0x{2:X})"
536+
.format(opid, OpCodeDebug.op_id(opid), position))
535537

536538
try:
537539
handler = self.opmap[opid]
538540
except KeyError:
539-
raise RuntimeError("Unknown OpCode in the stream: 0x{0:X}"
540-
.format(opid))
541+
raise RuntimeError(
542+
"Unknown OpCode in the stream: 0x{0:X} (at offset 0x{1:X})"
543+
.format(opid, position))
541544
else:
542545
return opid, handler(ident=ident)
543546

0 commit comments

Comments
 (0)