line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
######################################################################## |
2
|
|
|
|
|
|
|
# Signal::StackTrace - run a stack dump on a signal. |
3
|
|
|
|
|
|
|
######################################################################## |
4
|
|
|
|
|
|
|
######################################################################## |
5
|
|
|
|
|
|
|
# housekeeping |
6
|
|
|
|
|
|
|
######################################################################## |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
package Signal::StackTrace; |
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
1000
|
use 5.006; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
36
|
|
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
32
|
|
13
|
|
|
|
|
|
|
|
14
|
1
|
|
|
1
|
|
15
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
71
|
|
15
|
1
|
|
|
1
|
|
5
|
use Config; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
31
|
|
16
|
|
|
|
|
|
|
|
17
|
1
|
|
|
1
|
|
1138
|
use Data::Dumper; |
|
1
|
|
|
|
|
6913
|
|
|
1
|
|
|
|
|
445
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
######################################################################## |
20
|
|
|
|
|
|
|
# package variables |
21
|
|
|
|
|
|
|
######################################################################## |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
our $VERSION = 0.04; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
my %known_sigz = (); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
@known_sigz{ split ' ', $Config{ sig_name } } = (); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# see perldoc -f caller for the correct order. |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
my @headerz = |
32
|
|
|
|
|
|
|
qw |
33
|
|
|
|
|
|
|
( |
34
|
|
|
|
|
|
|
Package |
35
|
|
|
|
|
|
|
Filename |
36
|
|
|
|
|
|
|
Line-No |
37
|
|
|
|
|
|
|
Subroutine |
38
|
|
|
|
|
|
|
Hasargs |
39
|
|
|
|
|
|
|
Wantarray |
40
|
|
|
|
|
|
|
Evaltext |
41
|
|
|
|
|
|
|
Require |
42
|
|
|
|
|
|
|
Hints |
43
|
|
|
|
|
|
|
Bitmask |
44
|
|
|
|
|
|
|
); |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
######################################################################## |
47
|
|
|
|
|
|
|
# private utility subs |
48
|
|
|
|
|
|
|
######################################################################## |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
my $print_list |
51
|
|
|
|
|
|
|
= sub |
52
|
|
|
|
|
|
|
{ |
53
|
|
|
|
|
|
|
local $Data::Dumper::Purity = 0; |
54
|
|
|
|
|
|
|
local $Data::Dumper::Terse = 1; |
55
|
|
|
|
|
|
|
local $Data::Dumper::Indent = 1; |
56
|
|
|
|
|
|
|
local $Data::Dumper::Deparse = 1; |
57
|
|
|
|
|
|
|
local $Data::Dumper::Sortkeys = 1; |
58
|
|
|
|
|
|
|
local $Data::Dumper::Deepcopy = 0; |
59
|
|
|
|
|
|
|
local $Data::Dumper::Quotekeys = 0; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
print STDERR join "\n", map { ref $_ ? Dumper $_ : $_ } @_ |
62
|
|
|
|
|
|
|
}; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
my $stack_trace |
65
|
|
|
|
|
|
|
= sub |
66
|
|
|
|
|
|
|
{ |
67
|
|
|
|
|
|
|
my %data = (); |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
for( my $i = 0 ; my @caller = caller $i ; ++$i ) |
70
|
|
|
|
|
|
|
{ |
71
|
|
|
|
|
|
|
@data{ @headerz } = @caller; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
$print_list->( "Caller level $i:", \%data ); |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
$print_list->( "End of trace" ); |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
return |
79
|
|
|
|
|
|
|
}; |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
######################################################################## |
82
|
|
|
|
|
|
|
# install the signal handlers |
83
|
|
|
|
|
|
|
######################################################################## |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub import |
86
|
|
|
|
|
|
|
{ |
87
|
|
|
|
|
|
|
# discard this package; |
88
|
|
|
|
|
|
|
# remainder of the stack are signal names. |
89
|
|
|
|
|
|
|
|
90
|
1
|
|
|
1
|
|
10
|
shift; |
91
|
|
|
|
|
|
|
|
92
|
1
|
50
|
|
|
|
5
|
if( @_ ) |
93
|
|
|
|
|
|
|
{ |
94
|
0
|
0
|
|
|
|
0
|
if( my @junk = grep { ! exists $known_sigz{ $_ } } @_ ) |
|
0
|
|
|
|
|
0
|
|
95
|
|
|
|
|
|
|
{ |
96
|
0
|
|
|
|
|
0
|
croak "Unknown signals: unknown signals @junk"; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
# all the signals are known, install them all |
100
|
|
|
|
|
|
|
# with the stack_trace handler. |
101
|
|
|
|
|
|
|
|
102
|
0
|
|
|
|
|
0
|
@SIG{ @_ } = ( $stack_trace ) x @_; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
else |
105
|
|
|
|
|
|
|
{ |
106
|
1
|
|
|
|
|
31
|
$SIG{ USR1 } = $stack_trace; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
return |
110
|
1
|
|
|
|
|
13
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
# keep require happy |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
1 |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
__END__ |