[perl #39934] [PATCH] Make disassemble useful.

0 views
Skip to first unread message

Kevin Tew

unread,
Jul 24, 2006, 8:57:05 PM7/24/06
to bugs-bi...@rt.perl.org
# New Ticket Created by Kevin Tew
# Please include the string: [perl #39934]
# in the subject line of all future correspondence about this issue.
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=39934 >


embed.c | 34 ++++++++++++++++++++++++++++++++++
1 file changed, 34 insertions(+)

Feedback wanted.
Kevin

disassemble.patch

Kevin Tew

unread,
Jul 24, 2006, 10:10:25 PM7/24/06
to perl6-i...@perl.org
I've been wanting this little enhancement for quite some time.
I finally coded it up.
Suggestions welcome.

Kevin

The patch updates disassemble output to contain three useful pieces of
information.

FROM

load_bytecode_sc "TGE.pbc"
find_type_i_sc I0,"ASTGrammar"
ne_i_ic_ic I0,0,L1
subclass_p_sc_sc P0,"TGE::Grammar","ASTGrammar"
L1: set_returns_pc PMC_CONST(5)
returncc
get_params_pc PMC_CONST(14)
debug_init
defined_i_p_kc I0,P1[?]
unless_i_ic I0,L2
set_p_p_kc P1,P1[?]
set_args_pc PMC_CONST(19)
get_results_pc PMC_CONST(17)
callmethodcc_p_sc P3,"get"
set_returns_pc PMC_CONST(17)
returncc
L2: print_sc "The top-level node d"
end
get_params_pc PMC_CONST(14)
defined_i_p_kc I0,P1[?]
unless_i_ic I0,L3
set_p_p_kc P1,P1[?]
set_args_pc PMC_CONST(19)
get_results_pc PMC_CONST(17)
callmethodcc_p_sc P3,"get"
set_returns_pc PMC_CONST(17)
returncc
L3: print_sc "The compound_stateme"
end

TO

Seq_Op_Num- Relative-PC SrcLn#:
Current Source Filename src/ASTGrammar_gen.pir
000000000000-000000000000 000025: load_bytecode_sc "TGE.pbc"
000000000001-000000000002 000026: find_type_i_sc I0,"ASTGrammar"
000000000002-000000000005 000026: ne_i_ic_ic I0,0,L1
000000000003-000000000009 000028: subclass_p_sc_sc
P0,"TGE::Grammar","ASTGrammar"
000000000004-000000000013 000029: L1: set_returns_pc PMC_CONST(5)
000000000005-000000000015 000029: returncc
Current Source Filename src/ASTGrammar_gen.pir
000000000006-000000000016 000034: get_params_pc PMC_CONST(14)
000000000007-000000000021 000038: debug_init
000000000008-000000000022 000042: defined_i_p_kc I0,P1[?]
000000000009-000000000026 000042: unless_i_ic I0,L2
000000000010-000000000029 000043: set_p_p_kc P1,P1[?]
000000000011-000000000033 000045: set_args_pc PMC_CONST(19)
000000000012-000000000039 000045: get_results_pc PMC_CONST(17)
000000000013-000000000042 000045: callmethodcc_p_sc P3,"get"
000000000014-000000000045 000047: set_returns_pc PMC_CONST(17)
000000000015-000000000048 000047: returncc
000000000016-000000000049 000050: L2: print_sc "The top-level
node d"
000000000017-000000000051 000051: end
Current Source Filename src/ASTGrammar_gen.pir
000000000018-000000000052 000056: get_params_pc PMC_CONST(14)
000000000019-000000000057 000062: defined_i_p_kc I0,P1[?]
000000000020-000000000061 000062: unless_i_ic I0,L3
000000000021-000000000064 000063: set_p_p_kc P1,P1[?]
000000000022-000000000068 000065: set_args_pc PMC_CONST(19)
000000000023-000000000074 000065: get_results_pc PMC_CONST(17)
000000000024-000000000077 000065: callmethodcc_p_sc P3,"get"
000000000025-000000000080 000067: set_returns_pc PMC_CONST(17)
000000000026-000000000083 000067: returncc
000000000027-000000000084 000070: L3: print_sc "The
compound_stateme"
000000000028-000000000086 000071: end

Seq_Op_Num this is a sequential op number for each operation in the
code segment.
(The debug segment indexes both debug mappings and line numbers based on
this incrementing counter)
Relative-PC this is the op_code_t offset of the operation in the code
segement.
SrcLn# is the line number of the pir source code. (in this case
src/AST_Grammar_gen.pir)

When chasing PIR bugs and parrot segfauts. Run parrot in gdb.
cat > .rit_gdb_cmds <<EOF
set args cardinal.pbc t/00_if_unless_5.rb
run
set print pretty
EOF

gdb -x .rit_gdb_cmds ../../parrot

Find the runops_slow_core activation frame closes to the top of the
stack and execute these commands in gdb
(gdb) p interpreter->code->base.name
$48 = 0x82c23c8 "BYTECODE_src/ASTGrammar_gen.pir"

Tells you the source file where parrot most likely core dumped

(gdb) p pc - interpreter->code->base.data
$43 = 1022

1022 in this case is the Relative-PC in the src/ASTGrammar.pbc file.

(gdb) p interpreter->code->base.name
$48 = 0x82c23c8 "BYTECODE_src/ASTGrammar_gen.pir"

Given BYTECODE_src/ASTGrammar_gen.pir:
run disassemble on src/ASTGrammar.pbc

make disassemble
./disassemble languages/cardinal/src/ASTGrammar.pbc |less

And puff, smoke, magic:

I found out I was core dumping on line #459 of src/ASTGrammar_gen.pir

> ------------------------------------------------------------------------
>
> Index: src/embed.c
> ===================================================================
> --- src/embed.c (revision 13526)
> +++ src/embed.c (working copy)
> @@ -864,6 +864,10 @@
> PDB_t *pdb;
> PDB_line_t *line;
> char *c;
> + int op_code_seq_num = 0;
> + int debugs;
> + int num_mappings;
> + int curr_mapping = 0;
>
> pdb = (PDB_t *)mem_sys_allocate_zeroed(sizeof(PDB_t));
>
> @@ -873,7 +877,36 @@
> PDB_disassemble(interpreter, NULL);
> line = pdb->file->line;
>
> + debugs = (interpreter->code->debugs != NULL);
> +
> + PIO_printf(interpreter, "%12s-%12s", "Seq_Op_Num", "Relative-PC");
> + if ( debugs ) {
> + PIO_printf(interpreter, " %6s:\n","SrcLn#");
> + num_mappings = interpreter->code->debugs->num_mappings;
> + }
> + else {
> + PIO_printf(interpreter, "\n");
> + }
> while (line->next) {
> + /* PIO_printf(interpreter, "%i < %i %i == %i \n", curr_mapping, num_mappings, op_code_seq_num, interpreter->code->debugs->mappings[curr_mapping]->offset); */
> + if (debugs && curr_mapping < num_mappings)
> + {
> + if ( op_code_seq_num == interpreter->code->debugs->mappings[curr_mapping]->offset)
> + {
> + int filename_const_offset = interpreter->code->debugs->mappings[curr_mapping]->u.filename;
> + PIO_printf(interpreter, "Current Source Filename %Ss\n", interpreter->code->const_table->constants[filename_const_offset]->u.string);
> + curr_mapping++;
> + }
> + }
> +
> + PIO_printf(interpreter, "%012i-%012i", op_code_seq_num, line->opcode - interpreter->code->base.data);
> + if ( debugs ) {
> + PIO_printf(interpreter, " %06i: \t",interpreter->code->debugs->base.data[op_code_seq_num]);
> + }
> + else {
> + PIO_printf(interpreter, "\t");
> + }
> +
> /* If it has a label print it */
> if (line->label)
> PIO_printf(interpreter, "L%li:\t", line->label->number);
> @@ -882,6 +915,7 @@
> PIO_printf(interpreter, "%c", *(c++));
> PIO_printf(interpreter, "\n");
> line = line->next;
> + op_code_seq_num++;
> }
> return;
> }
>

Paul Cochrane via RT

unread,
Apr 1, 2007, 4:53:54 AM4/1/07
to perl6-i...@perl.org


Thanks! Applied as r17922. Note that 'interpreter' had to be changed
to 'interp' to get this to compile. This name change hadn't occurred
when you submitted the patch (so was not a problem with the patch), but
I thought it best to note it in the ticket.

Paul

Reply all
Reply to author
Forward
0 new messages