Since no comments yet, here's an update on where I have gotten so far.

Consider this code using B::Concise to disassemble a function and B::Deparse to reconstruct the code into Perl:

use B::Deparse; use B::Concise qw(set_style); sub foo() { my $x=1; $x+=1; $x *=2; my $z = 0; } my $walker = B::Concise::compile('-basic', 'foo', \&foo); B::Concise::set_style_standard('debug'); B::Concise::walk_output(\my $buf); $walker->(); # walks and renders into $buf; print($buf); my $deparse = B::Deparse->new("-p", "-sC"); foo(); $body = $deparse->coderef2text(\&foo); print $body, "\n";

When I debug step through function foo via the Trepan debugger, the addresses do match addresses in the assembly output. However when I step through a deparse I am getting different addresses for the instructions. So matching instructions seen inside the debugger with those seen in deparse seems hopeless. Here is an abbreviated log:

Command: trepan.pl /tmp/foo.pl
-- main::(/tmp/foo.pl:8 @0x161d800)
my $walker = B::Concise::compile('-basic', 'foo', \&foo);
(trepanpl): continue 15
main::foo:
UNOP (0x3a89838)
	op_next		0
	op_sibling	0
	op_ppaddr	PL_ppaddrOP_LEAVESUB
	op_type		175
	op_flags	4
	op_private	65
	op_first	0x161daa0
LISTOP (0x161daa0)
	op_next		0x3a89838
	op_sibling	0
	op_ppaddr	PL_ppaddrOP_LINESEQ
	op_type		181
	op_flags	12
	op_private	0
	op_first	0x161dae8
	op_last		0x3a898e0
COP (0x161dae8)
	op_next		0x161db90
	op_sibling	0x161db48
	op_ppaddr	PL_ppaddrOP_DBSTATE
	op_type		183
	op_flags	1
	op_private	0	0
BINOP (0x161db48)
...
x1 main::(/tmp/foo.pl:15 @0x5b2a818)
$body = $deparse->coderef2text(\&foo);
(trepanpl): s
-- B::Deparse::(/usr/share/perl/5.18/B/Deparse.pm:820 @0x3c8d8d8)
    my $self = shift;
(trepanpl): b deparse_sub
Breakpoint 2 set in /usr/share/perl/5.18.2/B/Deparse.pm at line 985
(trepanpl): continue
-> B::Deparse::(/usr/share/perl/5.18/B/Deparse.pm:985 @0x3c92b18)
sub deparse_sub {
    my $self = shift;
trepanpl: next 3
-- B::Deparse::(/usr/share/perl/5.18/B/Deparse.pm:988 @0x3cb0f68)
    my $proto = "";
(trepanpl): $cv
$DB::D[0] = B::CV=SCALAR(0x5c11da8)
(trepanpl): $cv->ROOT
$DB::D1 = B::UNOP=SCALAR(0x5d30648)
(trepanpl): $cv->ROOT->first
$DB::D2 = B::LISTOP=SCALAR(0x5d3f9c8)
(trepanpl): $cv->ROOT->first->name
$DB::D3 = lineseq
(trepanpl):

Note that the addresses 0x5c11da8 just don't match the disassembly. However When I run printf "%x\n", \&foo that does give me an address that does match values.


In reply to Re: RFC: Location via B::Deparse by rockyb
in thread RFC: Location via B::Deparse by rockyb

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.