Skip to content

Commit

Permalink
Fix bugs in showing backtrace when stopped in a call
Browse files Browse the repository at this point in the history
  • Loading branch information
Rocky Bernstein committed Nov 22, 2015
1 parent da78d63 commit bc781fd
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 21 deletions.
2 changes: 1 addition & 1 deletion lib/Devel/Trepan/CmdProcessor/Frame.pm
Expand Up @@ -62,7 +62,7 @@ sub print_stack_entry()
}

my $lineno = $frame->{line} || '??';
my $addr = $opts->{displayop} ? sprintf("0x%x ", $frame->{addr}) : '';
my $addr = $opts->{displayop} && $frame->{addr} ? sprintf("0x%x ", $frame->{addr}) : '';
if ($opts->{short}) {
my $fn = $s; # @_ >= 4 ? $_[3] : $s;
my $msg = sprintf("%s%s%s%s from %s:%d",
Expand Down
36 changes: 28 additions & 8 deletions lib/Devel/Trepan/DB/Backtrace.pm
@@ -1,5 +1,6 @@
use warnings; no warnings 'redefine';
use English qw( -no_match_vars );
use B;

=pod
Expand Down Expand Up @@ -76,7 +77,8 @@ sub backtrace($;$$$) {
}

$count += $i;
# print "++count: $count, i $i\n";
# print "++count: $count, i $i $DB::event\n"; # XX debug
$i -= 2 if $DB::event eq 'call';

my ( @a, $args_ary );
my @callstack = ();
Expand All @@ -97,7 +99,7 @@ sub backtrace($;$$$) {
{
my $addr = Devel::Callsite::callsite($i);

## print "++file: $file, line $line $fn\n" if $DB::DEBUGME;
## print "++file: $file, line $line $fn\n"; # XX if $DB::DEBUGME;
$i++;
next if $pkg eq 'DB' && ($fn eq 'sub' || $fn eq 'lsub' ||
$file =~ m{Devel/Trepan/DB/Sub\.pm$});
Expand Down Expand Up @@ -188,18 +190,36 @@ sub backtrace($;$$$) {
# last if $signal;
} ## end for ($i = $skip ; $i < ...

## use Data::Printer; Data::Printer::p @callstack; # XXX

# The function and args for the stopped line is DB::DB,
# but we want it to be the function and args of the last call.
# Se we need to adjust those in @callstack.
# And the function and args for the file and line that called us
# should also be the prior function and args.
if ($scan_for_DB_sub) {
for (my $i=1; $i <= $#callstack; $i++) {
$callstack[$i-1]->{args} = $callstack[$i]->{args};
$callstack[$i-1]->{fn} = $callstack[$i]->{fn};
}
$callstack[$i]{args} = undef;
$callstack[$i]{fn} = undef;
my $len = @callstack;
if ($len) {
for (my $i=1; $i < $len; $i++) {
$callstack[$i-1]->{args} = $callstack[$i]->{args};
$callstack[$i-1]->{fn} = $callstack[$i]->{fn};
}
# $callstack[$len]->{args} = undef;
# $callstack[$len]->{fn} = undef;
}
}

if ($DB::event eq 'call') {
unshift @callstack, {
addr => $DB::addr,
file => $DB::filename,
fn => $DB::subroutine,
line => $DB::lineno,
pkg => $DB::package,
wantarray => $DB::wantarray ? $DB::wantarray : '',
};
}
# use Data::Printer; Data::Printer::p @callstack;

@callstack;
}
Expand Down
10 changes: 10 additions & 0 deletions lib/Devel/Trepan/DB/Sub.pm
Expand Up @@ -6,6 +6,7 @@ use warnings; no warnings 'redefine'; use utf8;
no warnings 'once';
use English qw( -no_match_vars );
use version;
use B;

use constant SINGLE_STEPPING_EVENT => 1;
use constant NEXT_STEPPING_EVENT => 2;
Expand Down Expand Up @@ -236,9 +237,14 @@ sub DB::sub {
if (defined($DB::running) && $DB::running == 1) {
local @DB::_ = @_;
local(*DB::dbline) = "::_<$DB::filename";

# FIXME: this isn't quite right;
$DB::addr = +B::svref_2object(\$DB::subroutine);

check_for_stop();
}

$DB::wantarray = wantarray;
if ($DB::sub eq 'DESTROY' or
substr($DB::sub, -9) eq '::DESTROY' or not defined wantarray) {
&$DB::sub;
Expand Down Expand Up @@ -335,6 +341,10 @@ sub DB::lsub : lvalue {
push_DB_single_and_set();

local(*DB::dbline) = "::_<$DB::filename";

# FIXME: this isn't quite right;
$DB::addr = +B::svref_2object(\$DB::subroutine);

check_for_stop();

if (wantarray) {
Expand Down
13 changes: 1 addition & 12 deletions lib/Devel/Trepan/Processor/Frame.pm
Expand Up @@ -105,18 +105,7 @@ sub frame_setup($$)
$self->{gave_stack_trunc_warning} = 1;
}
$stack_size = $computed_stack_depth;
if ($self->{event} eq 'call') {
no warnings 'once'; # for DB:: names below
$frames[0] =
{
file => $DB::filename,
fn => $DB::subroutine,
line => $DB::lineno,
pkg => $DB::package,
# FIXME: more later...
};

}
$stack_size++ if $self->{event} eq 'call';
}
$self->{frames} = \@frames;
$self->{stack_size} = $stack_size;
Expand Down
1 change: 1 addition & 0 deletions t/data/breakcall.cmd
@@ -1,6 +1,7 @@
# Test "To see that we can break on a subroutine call"
# use with example/callbug.pl
c iamnotok
where
$_[0]
break 6
quit
2 changes: 2 additions & 0 deletions t/data/breakcall.right
Expand Up @@ -2,6 +2,8 @@
if (scalar @ARGV) {
-> main::(callbug.pl:4)
sub iamnotok {
--> #0 1 = main::iamnotok in file `callbug.pl' at line 4
#1 file `callbug.pl' at line 9
$DB::D[0] = foo
Breakpoint 2 set in callbug.pl at line 6
trepan.pl: That's all, folks...

0 comments on commit bc781fd

Please sign in to comment.