File: addr2line.pl

package info (click to toggle)
notion 4.0.2%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 4,676 kB
  • sloc: ansic: 47,508; sh: 2,096; makefile: 603; perl: 270
file content (49 lines) | stat: -rwxr-xr-x 918 bytes parent folder | download | duplicates (6)
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
#!/usr/bin/perl

use strict;
use warnings;

my $executable = $ARGV[0];

my %lines = ();
my %functionNames = ();

sub getline {
  my $addr = shift;

  if ($addr eq "") {
    return "?? ??:0";
  }
  if ($addr !~ /^0x/) {
    return $addr;
  }

  my $line = $lines{$addr};
  if (!defined($line)) {
    $line = `addr2line -f -e $executable $addr`;
    chomp($line);
    $line =~ s/\n/ /g;
    $lines{$addr} = $line;
  }
  return $line;
}

while (<STDIN> =~ /(\w)\t([^\t]+)\t([^t]*)\t(\S+)/) {
  my ($action, $calledaddr, $calleraddr, $time) = ($1, $2, $3, $4);

  my $called = getline($calledaddr);
  my $caller = getline($calleraddr);

  if ($called =~ /^\(null\) (.*)/) {
    if (defined $functionNames{$1}) {
       $called = "$functionNames{$1} $1";
    } else {
       $called = "$1 $1";
    }
  }
  elsif ($called =~ /^(\S+) (.*)/) {
    $functionNames{$2} = $1;
  }

  print "$action\t$called\t$caller\t$time\n";
}