Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^2: How/can one do save/restore CORE::caller inside an eval?

by rockyb (Scribe)
on Dec 04, 2013 at 02:47 UTC ( #1065523=note: print w/replies, xml ) Need Help??


in reply to Re: How/can one to save/restore CORE::caller inside an eval?
in thread How/can one do save/restore CORE::caller inside an eval?

This is fantastic — almost. The first problem I have is that adding the BEGIN code causes Devel::Trepan to run so slowly that I've not had the patience to wait until it is done. I've tried without the BEGIN, and overwriting caller() still works.

More serious is the fact that my replaced version of caller() needs to call the original caller (after it strips off the call stack entries on top that are inside the debugger). I tried for bar():

    sub bar {
        local *orig_caller = *CORE::GLOBAL::caller;
        local *CORE::GLOBAL::caller = sub { orig_caller($_[0]+1)} # simplified somewhat
    }

But I'm getting:
  Deep recursion on anonymous subroutine at .. DB::Eval.pm 
because I guess that glob assignment has the same address.

Help!

Replies are listed 'Best First'.
Re^3: How/can one to save/restore CORE::caller inside an eval?
by educated_foo (Vicar) on Dec 04, 2013 at 03:05 UTC
    Would it work to just call CORE::caller() from your override?

      YES! That works for me.

      There is still one wafer-thin problem...

      When I use this in an array context, I am getting the function name (and possibly other further parameters) one level above what the package, file, and line number are. I can code around this, but I also wonder if this is a bug or not. Here is a run using Perl 5.18.1:

      ./bin/trepan.pl example/gcd.pl 3 5
      -- main::(example/gcd.pl:18)
      die sprintf "Need two integer arguments, got %d", scalar(@ARGV) unless
          @ARGV == 2;
      $DB::D[0] = 0
      (trepanpl): @ caller
      $DB::D1 =
      @{[
          [0]  "main",
          1  "example/gcd.pl",
          2  18,
          3  "DB::DB", <---- WRONG!
          4  "",
          5  1,
          6  undef,
          7  undef,
          8  2018,
          9  "UUUUUUUUUUUUUUUU",
          10 undef
      ]}
      (trepanpl): @ caller 1
      $DB::D2 =
      @{<undef>}
      (trepanpl): c gcd
      -> main::(example/gcd.pl:8)
      {
          my ($a, $b) = @_;
      trepanpl: s   # there is a "feature" here in my program where I need to step one more
      x1 main::(example/gcd.pl:9)
          my ($a, $b) = @_;
      (trepanpl): @ caller
      $DB::D2 =
      @{[
          [0]  "main",
          1  "example/gcd.pl",
          2  9,
          3  "DB::DB",  <--- still wrong
          4  "",
          5  1,
          6  undef,
          7  undef,
          8  1762,
          9  "UUUUUUUUUUUUUUUU",
          10 undef
      ]}
      (trepanpl): @ caller 1
      $DB::D3 =
      @{[
          [0]  "main",
          1  "example/gcd.pl",
          2  21,
          3  "main::gcd",
          4  1,
          5  1,
          6  undef,
          7  undef,
          8  2018,
          9  "UUUUUUUUUUUUUUUU",
          10 undef
      ]}
      (trepanpl): @ caller 2
      $DB::D4 =
      @{<undef>}
      (trepanpl): q
      Really quit? (N/y) y
      trepan.pl: That's all, folks...
      

      If you want to try the code yourself, see the github Devel::Trepan repo with a commit after 0babe47e08831a9d5b1099a9971fc2677f604331

        The last comment was a little long, so I wanted to add some other things here...

        • Why does this work?
        • What's the difference between CORE::GLOBAL::Caller and CORE::Caller.
        • Elaboration why one thought BEGIN was needed, and why in fact it isn't and why are things so slow when it is used?

        This is just icing on the cake. Just wondering what's going on.

        Thanks again, everbody!

        Unless monks (and non-monks) advise otherwise, I will take that reporting DB::DB as the calling function is a bug in Perl and create bug report for that.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1065523]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2021-01-27 20:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?