Skip to content
Create a gist now

Instantly share code, notes, and snippets.

# Symbolize AddressSanitizer stacktraces via objdump -Sd.
# Expands the 0 frame srcline and for subsequent frames only the function name.
# -l prints all lines, without -l only the expanded stacktraces.
# -f<n> disassembles the first n stackframes, not only the first
# -f0 disassembles all stackframes
# Copyright 2011 Reini Urban, BSD License
use Getopt::Std;
our ($opt_l, $opt_f);
while (<>) {
/^==\d+== ERROR: AddressSanitizer/ && do {print; next};
/^(READ|WRITE) of size / && do {print; next};
# /usr/local/lib/perl5/5.15.5/x86_64-linux-debug-asan@a7d2e0/CORE/
# => objdump -Sd --start-address=$2 $1|head
if (my ($frame, $absaddr, $path, $reladdr) = /^ +#(\d+) +(0x[0-9a-f]+) +\((.*)\+(0x[0-9a-f]+)\)/) {
next unless $absaddr and $path;
my $dump = `objdump -Sd --start-address=$reladdr $path|head -n40`;
my ($ok,$name,$addr);
my $fullframe = $frame == 0;
$fullframe++ if defined($opt_f) and ($opt_f == 0 or $opt_f > $frame);
for (split /\n/,$dump) { # look at the first dump lines
next DUMP unless $_;
if (/^[0-9a-f]+\s+<(.+)\+(0x[0-9a-f]+)>:/) {
($name,$addr) = ($1,$2);
print "\n" if $fullframe;
print " #$frame " if $fullframe;
if ($ok) {
if ($fullframe) { #print until 2nd asm
print "$_\n";
} else { #print only function name
print " #$frame $name+$addr\n";
last DUMP;
if (/^\s{0,3}[0-9a-f]+:\s+[0-9a-f][0-9a-f] /) { #skip further asm
last DUMP if $ok; $ok = 0;
/^0x[0-9a-f]+ is located/ && do {print; next};
/^allocated by thread/ && do {print; next};
print if $opt_l;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.