| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
#!/usr/bin/perl |
|
2
|
|
|
|
|
|
|
# |
|
3
|
|
|
|
|
|
|
# Copyright (C) 2011 by Opera Software Australia Pty Ltd |
|
4
|
|
|
|
|
|
|
# |
|
5
|
|
|
|
|
|
|
# This library is free software; you can redistribute it and/or modify |
|
6
|
|
|
|
|
|
|
# it under the same terms as Perl itself. |
|
7
|
|
|
|
|
|
|
# |
|
8
|
|
|
|
|
|
|
|
|
9
|
2
|
|
|
2
|
|
14
|
use strict; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
95
|
|
|
10
|
2
|
|
|
2
|
|
9
|
use warnings; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
65
|
|
|
11
|
2
|
|
|
2
|
|
10
|
use File::Basename; |
|
|
2
|
|
|
|
|
7
|
|
|
|
2
|
|
|
|
|
319
|
|
|
12
|
2
|
|
|
2
|
|
2031
|
use lib dirname($0); |
|
|
2
|
|
|
|
|
1692
|
|
|
|
2
|
|
|
|
|
255
|
|
|
13
|
2
|
|
|
2
|
|
328
|
use lib dirname($0) . "/lib"; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
61
|
|
|
14
|
2
|
|
|
2
|
|
1323
|
use Devel::Plumber; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
use Getopt::Long qw(:config no_ignore_case bundling); |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
my $binfile; |
|
18
|
|
|
|
|
|
|
my $corefile; |
|
19
|
|
|
|
|
|
|
my $pid; |
|
20
|
|
|
|
|
|
|
my $verbose = 0; |
|
21
|
|
|
|
|
|
|
my $progress = 0; |
|
22
|
|
|
|
|
|
|
my $dodump = 0; |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub usage |
|
25
|
|
|
|
|
|
|
{ |
|
26
|
|
|
|
|
|
|
print STDERR <
|
|
27
|
|
|
|
|
|
|
Usage: dumpit.pl [options] bin-file core-file |
|
28
|
|
|
|
|
|
|
dumpit.pl [options] bin-file pid |
|
29
|
|
|
|
|
|
|
options are: |
|
30
|
|
|
|
|
|
|
--verbose be more verbose |
|
31
|
|
|
|
|
|
|
--progress give a progress report |
|
32
|
|
|
|
|
|
|
EOF |
|
33
|
|
|
|
|
|
|
exit 1; |
|
34
|
|
|
|
|
|
|
} |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub parse_arguments |
|
37
|
|
|
|
|
|
|
{ |
|
38
|
|
|
|
|
|
|
GetOptions( |
|
39
|
|
|
|
|
|
|
'verbose+' => \$verbose, |
|
40
|
|
|
|
|
|
|
'progress' => \$progress, |
|
41
|
|
|
|
|
|
|
'dump-blocks' => \$dodump, |
|
42
|
|
|
|
|
|
|
) or usage; |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
$binfile = shift @ARGV || usage; |
|
45
|
|
|
|
|
|
|
die "No such binary file: $binfile" |
|
46
|
|
|
|
|
|
|
unless -f $binfile; |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
$corefile = shift @ARGV || usage; |
|
49
|
|
|
|
|
|
|
if ($corefile =~ m/^\d+$/) |
|
50
|
|
|
|
|
|
|
{ |
|
51
|
|
|
|
|
|
|
$pid = $corefile; |
|
52
|
|
|
|
|
|
|
$corefile = undef; |
|
53
|
|
|
|
|
|
|
} |
|
54
|
|
|
|
|
|
|
else |
|
55
|
|
|
|
|
|
|
{ |
|
56
|
|
|
|
|
|
|
die "No such core file: $corefile" |
|
57
|
|
|
|
|
|
|
unless -f $corefile; |
|
58
|
|
|
|
|
|
|
} |
|
59
|
|
|
|
|
|
|
usage if scalar(@ARGV); |
|
60
|
|
|
|
|
|
|
} |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
parse_arguments(); |
|
63
|
|
|
|
|
|
|
# print "binfile=$binfile\n"; |
|
64
|
|
|
|
|
|
|
# print "corefile=$corefile\n" if defined $corefile; |
|
65
|
|
|
|
|
|
|
# print "pid=$pid\n" if defined $pid; |
|
66
|
|
|
|
|
|
|
# print "verbose=$verbose\n"; |
|
67
|
|
|
|
|
|
|
# print "progress=$progress\n"; |
|
68
|
|
|
|
|
|
|
# exit 0; |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
my $plumber = new Devel::Plumber(binfile => $binfile, |
|
71
|
|
|
|
|
|
|
corefile => $corefile, |
|
72
|
|
|
|
|
|
|
pid => $pid, |
|
73
|
|
|
|
|
|
|
progress => $progress, |
|
74
|
|
|
|
|
|
|
verbose => $verbose); |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
$plumber->find_leaks(); |
|
77
|
|
|
|
|
|
|
if ($dodump) |
|
78
|
|
|
|
|
|
|
{ |
|
79
|
|
|
|
|
|
|
$plumber->dump_blocks(); |
|
80
|
|
|
|
|
|
|
} |
|
81
|
|
|
|
|
|
|
else |
|
82
|
|
|
|
|
|
|
{ |
|
83
|
|
|
|
|
|
|
$plumber->report_leaks(); |
|
84
|
|
|
|
|
|
|
} |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head1 NAME |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
plumber - memory leak finder for C programs |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
B [ I ] I I |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
B [ I ] I I |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
B is a memory leak finder for C programs, implemented in |
|
99
|
|
|
|
|
|
|
Perl. It uses GDB to walk internal glibc heap structures, so it can |
|
100
|
|
|
|
|
|
|
work on either a live process (the first synopsis) or a core file |
|
101
|
|
|
|
|
|
|
(the second synopsis). |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
Compared to Valgrind, Purify, or various malloc debugging libraries, |
|
104
|
|
|
|
|
|
|
B |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=over |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=item * |
|
109
|
|
|
|
|
|
|
is very slow, |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=item * |
|
112
|
|
|
|
|
|
|
does not provide stack traces showing how memory was allocated, |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=item * |
|
115
|
|
|
|
|
|
|
does not work on multi-threaded programs (although this could be fixed). |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=back |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
However B is much easier to use in a production environment |
|
120
|
|
|
|
|
|
|
(rather than a test environment) because the program under test |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=over |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=item * |
|
125
|
|
|
|
|
|
|
does not require any special building or instrumentation before running, |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=item * |
|
128
|
|
|
|
|
|
|
does not need to be launched specially, |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=item * |
|
131
|
|
|
|
|
|
|
can already be running, for any length of time, or |
|
132
|
|
|
|
|
|
|
may have already crashed and left a core, |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=item * |
|
135
|
|
|
|
|
|
|
will continue unmolested after B has finished. |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=back |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=head1 OPTIONS |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
B accepts the following options |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=over |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=item B<--progress> |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
Cause a progress indicator to be emitted to stderr. B |
|
148
|
|
|
|
|
|
|
can be quite slow. |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=item B<--verbose> |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
Cause debugging messages to be emitted to stderr. |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=back |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=head1 CAVEATS |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
See CAVEATS for B(3perl). |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=head1 AUTHOR |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
Greg Banks |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=head1 COPYRIGHT |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
Copyright (C) 2011 by Opera Software Australia Pty Ltd |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
|
169
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
B(3perl). |
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=cut |