X-Git-Url: http://git.ipfire.org/?a=blobdiff_plain;f=malloc%2Fmtrace.pl;h=075da0d9f11da15c32fb50dbe4a9d34b6e90e2cc;hb=1059defeee95e28c65b266a55eba6d47d852026b;hp=0036f33f5918ffacc3041d9ee5d34cc41678eecf;hpb=1b85ed0ce299a8044e8417ca82e85cf6267d520a;p=thirdparty%2Fglibc.git diff --git a/malloc/mtrace.pl b/malloc/mtrace.pl index 0036f33f591..075da0d9f11 100644 --- a/malloc/mtrace.pl +++ b/malloc/mtrace.pl @@ -1,9 +1,8 @@ #! @PERL@ -eval "exec @PERL@ -S $0 $*" +eval "exec @PERL@ -S $0 $@" if 0; -# Copyright (C) 1997-2002, 2003, 2004 Free Software Foundation, Inc. +# Copyright (C) 1997-2024 Free Software Foundation, Inc. # This file is part of the GNU C Library. -# Contributed by Ulrich Drepper , 1997. # Based on the mtrace.awk script. # The GNU C Library is free software; you can redistribute it and/or @@ -17,12 +16,12 @@ eval "exec @PERL@ -S $0 $*" # Lesser General Public License for more details. # You should have received a copy of the GNU Lesser General Public -# License along with the GNU C Library; if not, write to the Free -# Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -# 02111-1307 USA. +# License along with the GNU C Library; if not, see +# . $VERSION = "@VERSION@"; -$PACKAGE = "libc"; +$PKGVERSION = "@PKGVERSION@"; +$REPORT_BUGS_TO = '@REPORT_BUGS_TO@'; $progname = $0; sub usage { @@ -31,7 +30,7 @@ sub usage { print " --version print version number, then exit\n"; print "\n"; print "For bug reporting instructions, please see:\n"; - print ".\n"; + print "$REPORT_BUGS_TO.\n"; exit 0; } @@ -44,8 +43,8 @@ arglist: while (@ARGV) { if ($ARGV[0] eq "--v" || $ARGV[0] eq "--ve" || $ARGV[0] eq "--ver" || $ARGV[0] eq "--vers" || $ARGV[0] eq "--versi" || $ARGV[0] eq "--versio" || $ARGV[0] eq "--version") { - print "mtrace (GNU $PACKAGE) $VERSION\n"; - print "Copyright (C) 2005 Free Software Foundation, Inc.\n"; + print "mtrace $PKGVERSION$VERSION\n"; + print "Copyright (C) 2024 Free Software Foundation, Inc.\n"; print "This is free software; see the source for copying conditions. There is NO\n"; print "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"; print "Written by Ulrich Drepper \n"; @@ -75,11 +74,14 @@ if ($#ARGV == 0) { } else { $prog = "./$binary"; } - if (open (LOCS, "env LD_TRACE_LOADED_OBJECTS=1 $prog |")) { - while () { + # Set the environment variable LD_TRACE_LOADED_OBJECTS to 2 so the + # executable is also printed. + if (open (locs, "env LD_TRACE_LOADED_OBJECTS=2 $prog |")) { + while () { chop; if (/^.*=> (.*) .(0x[0123456789abcdef]*).$/) { $locs{$1} = $2; + $rel{$1} = hex($2); } } close (LOCS); @@ -88,6 +90,18 @@ if ($#ARGV == 0) { die "Wrong number of arguments, run $progname --help for help."; } +sub addr2line { + my $addr = pop(@_); + my $prog = pop(@_); + if (open (ADDR, "addr2line -e $prog $addr|")) { + my $line = ; + chomp $line; + close (ADDR); + if ($line ne '??:0') { + return $line + } + } +} sub location { my $str = pop(@_); return $str if ($str eq ""); @@ -95,11 +109,9 @@ sub location { my $addr = $1; my $fct = $2; return $cache{$addr} if (exists $cache{$addr}); - if ($binary ne "" && open (ADDR, "addr2line -e $binary $addr|")) { - my $line = ; - chomp $line; - close (ADDR); - if ($line ne '??:0') { + if ($binary ne "") { + my $line = &addr2line($binary, $addr); + if ($line) { $cache{$addr} = $line; return $cache{$addr}; } @@ -110,30 +122,23 @@ sub location { my $addr = $2; my $searchaddr; return $cache{$addr} if (exists $cache{$addr}); - if ($locs{$prog} ne "") { - $searchaddr = sprintf "%#x", $addr - $locs{$prog}; - } else { - $searchaddr = $addr; - $prog = $binary; - } - if ($binary ne "" && open (ADDR, "addr2line -e $prog $searchaddr|")) { - my $line = ; - chomp $line; - close (ADDR); - if ($line ne '??:0') { - $cache{$addr} = $line; - return $cache{$addr}; + $searchaddr = sprintf "%#x", hex($addr) + $rel{$prog}; + if ($binary ne "") { + for my $address ($searchaddr, $addr) { + my $line = &addr2line($prog, $address); + if ($line) { + $cache{$addr} = $line; + return $cache{$addr}; + } } } $cache{$addr} = $str = $addr; } elsif ($str =~ /^.*[[](0x[^]]*)]$/) { my $addr = $1; return $cache{$addr} if (exists $cache{$addr}); - if ($binary ne "" && open (ADDR, "addr2line -e $binary $addr|")) { - my $line = ; - chomp $line; - close (ADDR); - if ($line ne '??:0') { + if ($binary ne "") { + my $line = &addr2line($binary, $addr); + if ($line) { $cache{$addr} = $line; return $cache{$addr}; } @@ -167,7 +172,7 @@ while () { printf ("+ %#0@XXX@x Alloc %d duplicate: %s %s\n", hex($allocaddr), $nr, &location($addrwas{$allocaddr}), $where); - } else { + } elsif ($allocaddr =~ /^0x/) { $allocated{$allocaddr}=$howmuch; $addrwas{$allocaddr}=$where; }