#! @PERL@
eval "exec @PERL@ -S $0 $@"
if 0;
-# Copyright (C) 1997-2015 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 <drepper@gnu.org>, 1997.
# Based on the mtrace.awk script.
# The GNU C Library is free software; you can redistribute it and/or
# You should have received a copy of the GNU Lesser General Public
# License along with the GNU C Library; if not, see
-# <http://www.gnu.org/licenses/>.
+# <https://www.gnu.org/licenses/>.
$VERSION = "@VERSION@";
$PKGVERSION = "@PKGVERSION@";
$ARGV[0] eq "--vers" || $ARGV[0] eq "--versi" ||
$ARGV[0] eq "--versio" || $ARGV[0] eq "--version") {
print "mtrace $PKGVERSION$VERSION\n";
- print "Copyright (C) 2014 Free Software Foundation, Inc.\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 <drepper\@gnu.org>\n";
} else {
$prog = "./$binary";
}
- if (open (LOCS, "env LD_TRACE_LOADED_OBJECTS=1 $prog |")) {
- while (<LOCS>) {
+ # 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 (<locs>) {
chop;
if (/^.*=> (.*) .(0x[0123456789abcdef]*).$/) {
$locs{$1} = $2;
+ $rel{$1} = hex($2);
}
}
close (LOCS);
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 = <ADDR>;
+ chomp $line;
+ close (ADDR);
+ if ($line ne '??:0') {
+ return $line
+ }
+ }
+}
sub location {
my $str = pop(@_);
return $str if ($str eq "");
my $addr = $1;
my $fct = $2;
return $cache{$addr} if (exists $cache{$addr});
- if ($binary ne "" && open (ADDR, "addr2line -e $binary $addr|")) {
- my $line = <ADDR>;
- chomp $line;
- close (ADDR);
- if ($line ne '??:0') {
+ if ($binary ne "") {
+ my $line = &addr2line($binary, $addr);
+ if ($line) {
$cache{$addr} = $line;
return $cache{$addr};
}
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 = <ADDR>;
- 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 = <ADDR>;
- chomp $line;
- close (ADDR);
- if ($line ne '??:0') {
+ if ($binary ne "") {
+ my $line = &addr2line($binary, $addr);
+ if ($line) {
$cache{$addr} = $line;
return $cache{$addr};
}
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;
}