diff options
Diffstat (limited to 'malloc/mtrace.pl')
-rw-r--r-- | malloc/mtrace.pl | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/malloc/mtrace.pl b/malloc/mtrace.pl index a254c6e860..e3ed5771dd 100644 --- a/malloc/mtrace.pl +++ b/malloc/mtrace.pl @@ -68,6 +68,21 @@ if ($#ARGV == 0) { } elsif ($#ARGV == 1) { $binary=$ARGV[0]; $data=$ARGV[1]; + + if ($binary =~ /^.*[\/].*$/) { + $prog = $binary; + } else { + $prog = "./$binary"; + } + if (open (LOCS, "env LD_TRACE_LOADED_OBJECTS=1 $prog |")) { + while (<LOCS>) { + chop; + if (/^.*=> (.*) .(0x[0123456789abcdef]*).$/) { + $locs{$1} = $2; + } + } + close (LOCS); + } } else { die "Wrong number of arguments, run $progname --help for help."; } @@ -89,10 +104,18 @@ sub location { } } $cache{$addr} = $str = "$fct @ $addr"; - } elsif ($str =~ /^.*[[](0x[^]]*)]$/) { - my $addr = $1; + } elsif ($str =~ /^(.*):.*[[](0x[^]]*)]$/) { + my $prog = $1; + my $addr = $2; + my $searchaddr; return $cache{$addr} if (exists $cache{$addr}); - if ($binary ne "" && open (ADDR, "addr2line -e $binary $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); |