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! | [reply] [d/l] [select] |
Would it work to just call CORE::caller() from your override?
| [reply] [d/l] |
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 | [reply] [d/l] |