Skip to content

Commit 73bcf41

Browse files
author
rocky
committed
On option -x also show hex for co_code start
1 parent b53db67 commit 73bcf41

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

xdis/cross_dis.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ def pretty_flags(flags, is_pypy=False) -> str:
272272

273273

274274
def format_code_info(
275-
co, version_tuple: tuple, name=None, is_pypy=False, is_graal=False, file_offset: Optional[int]=None
275+
co, version_tuple: tuple, name=None, is_pypy=False, is_graal=False, file_offset: Optional[tuple]=None
276276
) -> str:
277277
if not name:
278278
name = co.co_name
@@ -286,7 +286,7 @@ def format_code_info(
286286
lines.append("# Filename: %s" % co.co_filename)
287287

288288
if file_offset:
289-
lines.append("# Offset in file: 0x%x" % file_offset)
289+
lines.append("# Offset in file: 0x%x" % file_offset[0])
290290

291291
if not is_graal:
292292
if version_tuple >= (1, 3):
@@ -350,6 +350,10 @@ def format_code_info(
350350
lines.append("# %4d: %s" % i_n)
351351
pass
352352
pass
353+
354+
if file_offset:
355+
lines.append("# co_code offset in file: 0x%x" % file_offset[1])
356+
353357
return "\n".join(lines)
354358

355359

xdis/unmarshal.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,11 @@ def t_code(self, save_ref, bytes_for_s: bool = False):
512512
else:
513513
co_flags = 0
514514

515+
# In recording the address of co_code_offset_in file, skip
516+
# the type code indicator, e.g. "bytes" in 3.x and the size
517+
# of the string.
518+
co_code_offset_in_file = self.fp.tell() + 5
519+
515520
co_code = self.r_object(bytes_for_s=True)
516521

517522
# FIXME: Check/verify that is true:
@@ -635,7 +640,7 @@ def t_code(self, save_ref, bytes_for_s: bool = False):
635640
version_triple=self.version_tuple,
636641
)
637642

638-
self.code_to_file_offsets[code] = code_offset_in_file
643+
self.code_to_file_offsets[code] = (code_offset_in_file, co_code_offset_in_file)
639644

640645
self.code_objects[str(code)] = code
641646
ret = code

0 commit comments

Comments
 (0)