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