Hi Monks !
My task is to create a Perl reporting for unknown code.
The idea is to execute piece of Perl code in a place it can't harm anything, and create a "simple" report out of it.
The report should be a printout of every line, and (the hard work) the values of the variables in tihs line.
How do we do all of that ?
1. Before the execution we use "Xref.pm" to get detailed data regarding to every line and the variables in it, global and lexical.
2. Using "Safe.pm" and "Safe::Hole.pm" we create a compartment where we execute the code.
3. While executing we use a modified "Devel::Trace" to get every line executed.
- To get the global variables we use "dumpvar.pl", similar to the way perl5db do, giving it the list of the variables we took from Xref before.
Up to here (surprise) it all works fine. Here is the hard stuff...
- To get the lexical variables we needed something special and we found "PadWalker.pm", peek_my().
The problem is that PadWalker gives proper information up to the minute we try to use it via the Safe compartement. There, it seems it can't "penetrate" the compartement...
The new Trace relevant code is this, called from sub DB::DB -
sub peek_lexicals { my $h = peek_my(2); print "\nlexicals-----------------------\n"; print "keys=", join (", ", keys %$h), "-\n"; print "values=", join (", ", values %$h), "-\n"; print "end of lexicals-----------------------\n"; }
The unsafe code is "unsafe.pl":
my $b = 42; $c = "Hallo world\n"; print "printing lexical $b\n"; print "printing global $c\n";
The checking code is "check_code.pl":
use Safe; use Safe::Hole; my $SCRIPT_NAME = "unsafe.pl"; $QTL_HOLE_CPT = new Safe::Hole; $QTL_CPT = new Safe("QTL"); $Devel::Trace_shushu2::TRACE= 1; $QTL_CPT->rdo ( "$SCRIPT_NAME" );
When executed straight ("perl -d:Trace unsafe.pl") I get:
lexicals----------------------- keys=$b- values=SCALAR(0x810811c)- end of lexicals----------------------- lexicals----------------------- keys=$b- values=SCALAR(0x810811c)- end of lexicals----------------------- printing lexical 42 lexicals----------------------- keys=$b- values=SCALAR(0x810811c)- end of lexicals----------------------- printing global Hallo world
When executed via the checker ("perl -d:Trace_shushu2 check_code.pl") I get:
lexicals----------------------- keys=$SCRIPT_NAME- values=SCALAR(0x8108144)- end of lexicals----------------------- lexicals----------------------- keys=$SCRIPT_NAME- values=SCALAR(0x8108144)- end of lexicals----------------------- lexicals----------------------- keys=$SCRIPT_NAME- values=SCALAR(0x8108144)- end of lexicals----------------------- lexicals----------------------- keys=$default_share, $default_root, $VERSION- values=SCALAR(0x824f76c), SCALAR(0x810b704), SCALAR(0x8225304)- end of lexicals----------------------- lexicals----------------------- keys=$default_share, $default_root, $VERSION- values=SCALAR(0x824f76c), SCALAR(0x810b704), SCALAR(0x8225304)- end of lexicals----------------------- lexicals----------------------- keys=$default_share, $default_root, $VERSION- values=SCALAR(0x824f76c), SCALAR(0x810b704), SCALAR(0x8225304)- end of lexicals----------------------- printing lexical 42 lexicals----------------------- keys=$default_share, $default_root, $VERSION- values=SCALAR(0x824f76c), SCALAR(0x810b704), SCALAR(0x8225304)- end of lexicals----------------------- printing global Hallo world
* I tried to play with the level given to the &peek_my, with no good effect.
* robin (hopefully reading...) - In your jurnal (http://use.perl.org/~robin/journal) you wrote that PadWalker 0.8 is used in the new debugger to do exactly what I need. Can it be used here ?
Any suggestions ?
Thanks,
shushu

In reply to PadWalker and Safe - getting the lexicals by shushu

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.