/usr/bin/memprobe is in libroot-core-dev 5.34.00-2.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
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 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 | #!/usr/bin/env perl
################################################################################
#
# Authors : D.Bertini and M.Ivanov
# Date: 23/10/2000
# Updated: 10/05/2001 D.Bertini, v2.0 port to gdb5.0 + glibc2.2
#
#
# To activate the memory checker you have to set in the .rootrc file
# the resource Root.MemCheck to 1 (e.g.: Root.MemCheck: 1) and you
# have to link with libNew.so (e.g. use root-config --new --libs) or
# use rootn.exe. When all this is the case you will find at the end
# of the program execution a file "memcheck.out" in the directory
# where you started your ROOT program. Alternatively you can set
# the resource Root.MemCheckFile to the name of a file to which
# the leak information will be written. The contents of this
# "memcheck.out" file can be analyzed and transformed into printable
# text via the memprobe program (in $ROOTSYS/bin).
#
################################################################################
if ( ( $#ARGV < 0 )) {
Usage();
}
use Getopt::Std;
getopt "h,e,m,d,f";
#Usage("exec file is mandatory !\n") if ( !($opt_h or $opt_e) );
if ( $opt_h ) { Usage();}
if ( $opt_e ) { $ExeFile=$opt_e;
}else {
if (!$opt_h){ Usage("an exec file must be provided !\n");}
}
if ( $opt_m ) { $MemStatFile=$opt_m;
}else{
$MemStatFile="memcheck.out";
}
if ( $opt_d ) { $MemDescFile=$opt_d;
}else{
$MemDescFile="memcheckdesc.out";
}
if ( $opt_f ) { $MemFiltFile=$opt_f;
}else{
$MemFiltFile="analfilter";
}
sub Usage
{
my ($txt) = @_;
print "MemProbe v2.0 Usage:\n";
print "\t $0 -e exec-file [options] [files] \n ";
print "\t-e \t\t\tname of analyzed program\n";
print "Options: \n";
print "\t-h \t\t\tthis usage help\n";
print "\t-m \t\tname of analyzed program output file\n";
print "\t-d \t\tname of the stat description file\n";
print "\t-f \t\tname of the filter file\n";
print "\nWarning: $txt\n" if $txt;
exit 2;
}
# old version
#$ExeFile = shift @ARGV;
#$MemStatFile = $#ARGV >= 0 ? shift @ARGV : "memcheck.out";
open (MEMSTAT, $MemStatFile) or die "-E- Could not open leaks data file $MemStatFile: $!";
if ($#ARGV >= 0) {
$BreakOn = shift @ARGV;
# Rest in @ARGV are program arguments
}
##############################################################################
# Read filter expression
##############################################################################
open (FILTERFILE, $MemFiltFile);
@FILTER = <FILTERFILE>;
close (FILTERFILE);
for ($j = 0; $j <= $#FILTER; ++$j){
chop $FILTER[$j];
# print $FILTER[$j];
}
##############################################################################
# Find leak adresses
##############################################################################
$n = $u = 0;
$nfull = $ufull = 0;
while (<MEMSTAT>) {
# remove newline
chop $_ ;
if (/\s*(stack:)\s*/) {
$addrfull = $'; #obtain stack info
$_ = $addrfull;
s/(st)//g;
s/(0x)/:0x/g;
@arr = split(/:/); #obtain different leak points
for ($i = 1; $i < $#arr; ++$i){
$addr = $arr[$i];
$u++ if not exists $Size{$addr};
$Size{$addr} += 0;
$n++;
}
}
}
close (MEMSTAT);
##############################################################################
# FIND debug info for addresses - information stored
# in file leak.desc.C
##############################################################################
# redirect standard output to the trash
open (STDERR,">/dev/null");
# Redirect list of commands to a file
# using unix pipes (needed for RH.7.1 & gdb5.0)
open (myFile,">commands");
# Change set listsize 2 to something else to show more lines
print myFile "set prompt\nset listsize 1\nset height 0\nset verbose off\n";
if (defined($BreakOn)) {
print myFile "break $BreakOn\n";
print myFile "run ", join(" ", @ARGV), " \n";
}
else{
print myFile "break main \n ";
print myFile "run ", join(" ", @ARGV), " \n";
}
foreach (sort keys %Size) {
print myFile "l \*$_\n ";
}
if (defined($BreakOn)) {
print myFile "kill\n";
}
close (myFile);
##############################################################################
# Calling now gdb services in batch mode using
# dumped list of commands.
# ==> works with gdb-4.18 gdb-5.0 release versions
##############################################################################
open (PIPE, "| gdb -n -q $ExeFile < commands > $MemDescFile")
or die "-E- Cannot start gdb !!!";
close (PIPE);
##############################################################################
# ASIGN debug info to address
##############################################################################
open (DBGinfo, $MemDescFile) or die "-E- Could not open desc file $MemDescFile: $!";
$addr =0;
while (<DBGinfo>){
# if (/(0x[0-9a-f]+)\s*/){
if (/(^0x[0-9a-f]+)/){
$addr = $1;
#print $addr;
/is in /;
# print $';
# print "\n";
$filename{$addr} =$';
# print "$addr $filename{$addr}\n";
}else{
$line{$addr} = $_ if ! /^\s*l/;
}
for ($j = 0; $j <= $#FILTER; ++$j){
if ( ( $line{$addr} =~ /(${FILTER[$j]})/ ) ||
( $filename{$addr} =~ /(${FILTER[$j]})/ )){
$line{$addr} = "filtered";
}
}
}
close (DBGinfo);
##############################################################################
# FIND unique leak stack sequences
##############################################################################
open (MEMSTAT, $MemStatFile) or die "-E- Could not open leaks data file $MemStatFile: $!";
while (<MEMSTAT>) {
# remove newline
chop $_ ;
if (/\s*(stack:)\s*/) {
$addrfull = $'; #obtain stack info
$info =$`;
$info =~ s/size //; #obtain mem info for given stack sequence
$_ = $addrfull;
s/(st)//g;
s/(0x)/:0x/g;
s/ //g;
@arr = split(/:/); #obtain leak points
$addrfull ="stack";
$FilterOut=0;
for ($i = 1; ($i <= $#arr)&&($FilterOut==0); ++$i){
$addr = $arr[$i];
if ( $line{$addr} =~ /filtered/)
{
$FilterOut=1;
}
if ( $filename{$addr} =~ /\)/)
{
$addrfull .= ":";
$addrfull .= $addr;
}
}
if ($FilterOut==0){
$_= $info;
@meminfo = split(/:/);
$ufull++ if not exists $Sizefull{$addrfull};
$SizeTotal{$addrfull} += $meminfo[1];
$CountTotal{$addrfull}+= $meminfo[0];
$SizeLeak{$addrfull} += $meminfo[3];
$CountLeak{$addrfull}+= $meminfo[2];
$nfull++;
}
}
}
print STDERR "total memory corrupted at point==> ($nfull) \n";
print STDERR "unique allocations ==> ($ufull) \n";
close (MEMSTAT);
##############################################################################
# PRINT output leak information to leak.info.C output file
##############################################################################
open (LEAKinfo,">leak.info");
open (MULTI,">multidelete.info");
open (MEMSTAT,">memcheck.info");
# sort by size of leak
sub bysize {
$SizeLeak{$b} <=> $SizeLeak{$a}; # presuming integers
}
sub bysizetotal {
$SizeTotal{$b} <=> $SizeTotal{$a}; # presuming integers
}
foreach (sort bysizetotal keys %SizeTotal) {
print MEMSTAT "Count: $CountTotal{$_}($CountLeak{$_}) Size: $SizeTotal{$_}($SizeLeak{$_}) \n";
s/stack://g;
@arr = split(/:/); #obtain leak points
for ($i = 0; $i <= $#arr; ++$i){
$addr = $arr[$i];
print MEMSTAT "$filename{$addr}$line{$addr}";
}
print MEMSTAT "\n\n";
}
foreach (sort bysize keys %SizeLeak) {
if ($CountLeak{$_}<0){
print MULTI "Multiple deallocation :$CountLeak{$_}\n";
s/stack://g;
@arr = split(/:/); #obtain leak points
for ($i = 0; $i <= $#arr; ++$i){
$addr = $arr[$i];
print MULTI "$filename{$addr}$line{$addr}";
}
print MULTI "\n\n";
}
if ($SizeLeak{$_}!=0){
print LEAKinfo "Leaked allocations: $CountLeak{$_} \t Leaked size: $SizeLeak{$_} \n";
s/stack://g;
@arr = split(/:/); #obtain leak points
for ($i = 0; $i <= $#arr; ++$i){
$addr = $arr[$i];
print LEAKinfo "$filename{$addr}$line{$addr}";
}
print LEAKinfo "\n\n";
}
}
close(LEAKinfo);
close(MULTI);
close(MEMSTAT);
$remove = 'rm -rf commands';
exec $remove;
die " -E- no commands file !";
|