Skip to content

Commit

Permalink
Add address in backtrace. SIGWINCH no longer prints a message.
Browse files Browse the repository at this point in the history
Prefix signal print messages with debugger name.
  • Loading branch information
Rocky Bernstein committed Oct 31, 2015
1 parent d74c57c commit d0977ec
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 9 deletions.
1 change: 1 addition & 0 deletions lib/Devel/Trepan/CmdProcessor/Command/Backtrace.pm
Expand Up @@ -70,6 +70,7 @@ sub run($$)
current_pos => $proc->{frame_index},
maxstack => $proc->{settings}{maxstack},
maxwidth => $proc->{settings}{maxwidth},
displayop => $proc->{settings}{displayop},
};
my $stack_size = $proc->{stack_size};
my $count = $stack_size;
Expand Down
14 changes: 9 additions & 5 deletions lib/Devel/Trepan/CmdProcessor/Frame.pm
Expand Up @@ -53,21 +53,25 @@ sub print_stack_entry()
}

# Short report uses trimmed file and sub names.
my $wa;
my $want_array;
if (exists($frame->{wantarray})) {
$wa = "$frame->{wantarray} = ";
$want_array = "$frame->{wantarray} = ";
} else {
$not_last_frame = 0;
$wa = '' ;
$want_array = '' ;
}

my $lineno = $frame->{line} || '??';
my $addr = $opts->{displayop} ? sprintf("0x%x ", $frame->{addr}) : '';
if ($opts->{short}) {
my $fn = $s; # @_ >= 4 ? $_[3] : $s;
$self->msg("$wa$fn$args from $file:$lineno");
my $msg = sprintf("%s%s%s%s from %s:%d",
$want_array, $addr, $fn, $args, $file, $lineno);
$self->msg($msg);
} else {
# Non-short report includes full names.
# Lose the DB::DB hook call if frame is 0.
my $call_str = $not_last_frame ? "$wa$s$args in " : '';
my $call_str = $not_last_frame ? "$addr$want_array$s$args in " : $addr;
my $prefix_call = "$prefix$call_str";
my $file_line = $file . " at line $lineno";

Expand Down
4 changes: 4 additions & 0 deletions lib/Devel/Trepan/DB/Backtrace.pm
Expand Up @@ -63,6 +63,7 @@ sub backtrace($;$$$) {

my $i=0;
if ($scan_for_DB_sub) {
no warnings qw(once uninitialized); # For $DB::event
my $db_fn = ($DB::event eq 'post-mortem') ? 'catch' : 'DB';
# Warning: There is a bug caller that lists DB:DB as the function
# name rather than the name the debugged program may have been in
Expand Down Expand Up @@ -94,6 +95,8 @@ sub backtrace($;$$$) {
($pkg, $file, $line, $fn, $hasargs, $wantarray, $evaltext,
$is_require) = caller($i))
{
my $addr = Devel::Callsite::callsite($i);

## print "++file: $file, line $line $fn\n" if $DB::DEBUGME;
$i++;
next if $pkg eq 'DB' && ($fn eq 'sub' || $fn eq 'lsub' ||
Expand Down Expand Up @@ -170,6 +173,7 @@ sub backtrace($;$$$) {
# Stick the collected information into @callstack a hash reference.
push(@callstack,
{
addr => $addr,
args => $args_ary,
evaltext => $evaltext,
file => $file,
Expand Down
8 changes: 6 additions & 2 deletions lib/Devel/Trepan/SigHandler.pm
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2011, 2014 Rocky Bernstein <rocky@gnu.org>
# Copyright (C) 2011, 2014-2015 Rocky Bernstein <rocky@gnu.org>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -202,6 +202,10 @@ sub new($$$$$$)
$self->check_and_adjust_sighandler($signame);
}
$self->action('INT stop print nostack nopass');

# printing WINCH is annoying, especially in Emacs
$self->action('WINCH nostop noprint nostack pass');

# for my $sig ('CHLD', 'CLD') {
# $self->action("$sig nostop noprint nostack pass") if exists $SIG{$sig};
# }
Expand Down Expand Up @@ -472,7 +476,7 @@ sub handle
my ($self) = @_;
my $signame = $self->{signame};
if (exists($self->{print_fn}) && $self->{print_fn}) {
my $msg = sprintf("\nProgram received signal $signame.");
my $msg = sprintf("\ntrepan.pl: Program received signal $signame.");
$self->{print_fn}->($msg);
}

Expand Down
2 changes: 1 addition & 1 deletion t/data/sig.right
Expand Up @@ -7,4 +7,4 @@ Signal Stop Print Stack Pass Description
-----------------------------------------------
HUP No Yes No Yes Hangup

Program received signal HUP.
trepan.pl: Program received signal HUP.
2 changes: 1 addition & 1 deletion t/data/sig2.right
Expand Up @@ -8,7 +8,7 @@ Signal Stop Print Stack Pass Description
-----------------------------------------------
HUP Yes Yes No No Hangup

Program received signal HUP.
trepan.pl: Program received signal HUP.
!! main::(signal.pl:21)
sleep 1;
-- main::(signal.pl:21)
Expand Down

0 comments on commit d0977ec

Please sign in to comment.