http://www.perlmonks.org?node_id=204156


in reply to PadWalker and Safe - getting the lexicals

Well, this is certainly a new one! I've never even dreamed of using PadWalker with a Safe compartment before :-)

I'm not familiar with the details of how Safe works internally, but it's almost certainly fair to say that PadWalker will need to be modified to detect the Safe compartment and behave appropriately. In other words you'll need to dirty your hands with perlguts a little, to make this work. Probably.

The only other idea I have is that it might work if you can load PadWalker and Devel::Trace inside the same Safe compartment as the code you're executing. Have you tried that?

  • Comment on Re: PadWalker and Safe - getting the lexicals

Replies are listed 'Best First'.
Re: Re: PadWalker and Safe - getting the lexicals
by Anonymous Monk on Oct 10, 2002 at 13:41 UTC
    Thanks for the answer.
    Regarding to your idea - I was sure I can execute the debugger only via "perl -d", but since you reffered as if it is possible other way I looked again.

    From "perldebguts" under "Debugger Internals":
    "These mechanisms are enabled by calling Perl with the -d switch."
    It seems that the sub DB::DB is not executed unless you use the "-d" flag.
    Do I miss something here ???

    Thanks,
    shushu
      And another note (sorry I do it in parts...)

      From looking around I understand that the problem to enable the debugger. In Apache, when wanted to enable the debugger, it seems that special code was needed:
      From modperl archive (http://www.geocrawler.com/archives/3/182/2000/12/0/4895655/) -
      > there is quite a bit of overhead when -d is enabled. have a look at
      > Apache::DB.xs, there's in init_debugger() function todo what -d does. if
      > another method was added to turn it off, after the registry script was
      > compiled, the overhead would be reduced a great deal.

      shushu
getting the lexicals - the overloading option
by shushu (Scribe) on Oct 10, 2002 at 15:43 UTC
    Before I jump into the cold water of perlguts I wanted to check another option to get what I want.
    In short - all I want it to print to a file the value of every lexical variable used in the executed code.

    The second idea was to overload all of the operators, and make them just print before doing their job.
    Well, we thought about this option only because we never actually did overloading.
    After reading the stuff I understand that overloading is done only for specific types, so to use it the code shoud have something like:
    my $a = new OVERLOADED "value";
    Which is impossible in our case.

    The question is - is there a way to overload ALL of the basic types of Perl and inherit it "quietly" to the Safe compartement ?

    TIA,
    shushu
Re: Re: PadWalker and Safe - getting the lexicals
by shushu (Scribe) on Oct 13, 2002 at 15:33 UTC
    Hi (all and robin),
    Well, we had a good "fight", but now we are sure that in order to get the lexical information we do need to get into perlguts.
    The question now is - how to do it ?
    From where do we start ?
    Unfortunately we don't have the time to play around, and we need to understand fast whether it will take us 2 days or 2 weeks. Too many deadlines...

    - Do we need to get into Perl code, or do we need only PadWalker code ?
    - Where do we get PadWalker code ?
    - Does a standard RH 7.3 installation is enough, or should we get some other development environment ?

    TIA,
    shushu

      I haven't been motivated enough to see what the inside of a Safe::Hole->reval looks like but now that you've decided to go perlguts your first thing to do is to look at the B module. In my sig you'll notice an example of a script getting the current CV via B::svref_2object(sub {} )->OUTSIDE. I would initially recommend you read Gisle Aas' Illustrated PerlGuts, then Simon Cozens' internals tutorial and if that isn't enough descend into perlguts and perlhack. The key here is you're just walking structures. You aren't going to have to alter stuff so the documentation is to guide you in using B to walk all over.

      __SIG__ printf "You are here %08x\n", unpack "L!", unpack "P4", pack "L!", B:: +svref_2object(sub{})->OUTSIDE