petdance/scratch — Issue #914: pbc_dump: Indicate sub/method boundaries in -d mode
Author: petdance
Created: 2011-11-01 05:37:22+00:00
State: open
Labels: Pri-normal, Sev-medium, todo, tools

The disassembled output of pbc_dump run with -d is a long string of hex numbers and opcodes. To determine where a sub starts or ends requires a trip to the constants table, where the Sub constants have their starting and ending offsets recorded.

Please modify pbc_dump so that when dumping it emits indicators for the beginning/end of subs:
{{{
0000: 000004c8 00000001 00000009 00000001 get_hll_global_p_pc_sc
0004: 00000021 00000001 capture_lex_p
0006: 000004c8 00000001 00000009 00000001 get_hll_global_p_pc_sc
000a: 00000021 00000001 capture_lex_p
000c: 00000023 00000006 set_args_pc
000e: 00000024 00000003 get_results_pc
0011: 0000001c 00000001 invokecc_p
0013: 00000026 00000003 set_returns_pc
0016: 00000020 returncc
0017: 00000384 00000003 0000000b set_p_pc
001a: 00000385 00000002 00000003 set_p_p
001d: 00000009 00000011 load_bytecode_sc
001f: 000001d1 0000001b say_sc
0021: 000004c4 00000000 00000014 get_hll_global_p_sc
0024: 00000023 00000018 set_args_pc
0028: 00000024 00000006 get_results_pc
002a: 000002c4 00000000 0000001a callmethodcc_p_sc
002d: 000004ce 00000001 0000001d 00000014 get_root_global_p_pc_sc
0031: 00000023 00000015 set_args_pc
0037: 00000024 00000006 get_results_pc
0039: 000002c4 00000001 0000000f callmethodcc_p_sc
003c: 00000026 00000006 set_returns_pc
003e: 00000020 returncc
003f: 000004c8 00000002 00000025 00000023 get_hll_global_p_pc_sc
0043: 00000021 00000002 capture_lex_p
0045: 00000384 00000000 00000039 set_p_pc
0048: 00000021 00000000 capture_lex_p
004a: 000004c8 00000002 00000025 00000023 get_hll_global_p_pc_sc
004e: 00000021 00000002 capture_lex_p
0050: 00000023 00000006 set_args_pc
0052: 00000024 00000003 get_results_pc
0055: 0000001c 00000002 invokecc_p
0057: 00000026 00000003 set_returns_pc
005a: 00000020 returncc
}}}
could become:
{{{
----: Begin sub '_block11' :subid('')
0000: 000004c8 00000001 00000009 00000001 get_hll_global_p_pc_sc
0004: 00000021 00000001 capture_lex_p
0006: 000004c8 00000001 00000009 00000001 get_hll_global_p_pc_sc
000a: 00000021 00000001 capture_lex_p
000c: 00000023 00000006 set_args_pc
000e: 00000024 00000003 get_results_pc
0011: 0000001c 00000001 invokecc_p
0013: 00000026 00000003 set_returns_pc
0016: 00000020 returncc
----: End sub '_block11' :subid('')
----: Begin sub '' :subid('post15')
0017: 00000384 00000003 0000000b set_p_pc
001a: 00000385 00000002 00000003 set_p_p
001d: 00000009 00000011 load_bytecode_sc
001f: 000001d1 0000001b say_sc
0021: 000004c4 00000000 00000014 get_hll_global_p_sc
0024: 00000023 00000018 set_args_pc
0028: 00000024 00000006 get_results_pc
002a: 000002c4 00000000 0000001a callmethodcc_p_sc
002d: 000004ce 00000001 0000001d 00000014 get_root_global_p_pc_sc
0031: 00000023 00000015 set_args_pc
0037: 00000024 00000006 get_results_pc
0039: 000002c4 00000001 0000000f callmethodcc_p_sc
003c: 00000026 00000006 set_returns_pc
003e: 00000020 returncc
----: End sub '' :subid('post15')
----: Begin sub '_block13' :subid('')
003f: 000004c8 00000002 00000025 00000023 get_hll_global_p_pc_sc
0043: 00000021 00000002 capture_lex_p
0045: 00000384 00000000 00000039 set_p_pc
0048: 00000021 00000000 capture_lex_p
004a: 000004c8 00000002 00000025 00000023 get_hll_global_p_pc_sc
004e: 00000021 00000002 capture_lex_p
0050: 00000023 00000006 set_args_pc
0052: 00000024 00000003 get_results_pc
0055: 0000001c 00000002 invokecc_p
0057: 00000026 00000003 set_returns_pc
005a: 00000020 returncc
----: End sub '_block13' :subid('')
}}}

Note that a hypothetical future optimizer might arrange the bytecode so that subs are not discrete. Marking beginnings and endings separately should handle this.
Trac ID #1438