Created
February 11, 2015 09:20
-
-
Save aufflick/3254d5fb0d094d2e4c62 to your computer and use it in GitHub Desktop.
Script to symbolicate output from Activity Monitor.app's sample dumps
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl -w | |
use strict; | |
use warnings; | |
# The human has to determine the UUID from the binary images section for now. Sue me. | |
my ($uuid, $sample_file_path) = @ARGV; | |
die "Usage:\n $0 'main bundle uuid' 'path to sample.txt'" | |
unless $uuid && -f $sample_file_path; | |
# CAVEAT: This cannot symbolicate bundled frameworks atm. Sorry! Apps with multiple dSYMs - for now just hope the right one is alphabetically first... | |
# just need to find and set the load address | |
my $load_address; | |
my $code_type; | |
my $dwarf_path; | |
open my $fh, '<', $sample_file_path | |
or die $!; | |
while (my $line = <$fh>) { | |
if ($line =~ /^Load Address:\s+(0x[a-f0-9]+)$/) { | |
$load_address = $1; | |
} elsif ($line =~ /^Code Type:\s+(.+)/) { | |
if ($1 eq 'X86-64') { | |
$code_type = 'x86_64'; | |
} elsif ($1 eq 'X86') { | |
$code_type = 'i386'; | |
} else { | |
die "Unknown Code Type: '$1'"; | |
} | |
} | |
if ($line =~ /\?\?\? .* \[(0x[a-f0-9]+)\]/) { | |
my $address = $1; | |
my $replacement = symbolicate_address($address); | |
$line =~ s/\?\?\?.* load address/$replacement load address/; | |
} | |
print $line; | |
} | |
exit(0); | |
sub dSYM_dwarf_paths { | |
my $matches = `mdfind 'com_apple_xcode_dsym_uuids = "$uuid"'`; | |
my @matches = split /\n/, $matches; | |
die "No dsym found for uuid ($uuid) in spotlight." | |
unless @matches > 0; | |
my $archive_path = $matches[0]; | |
my $dwarf_paths = `find "$archive_path" -path '*.dSYM/*/DWARF/*'`; | |
return split /\n/, $dwarf_paths; | |
} | |
sub symbolicate_address { | |
my $address = shift; | |
die "Couldn't determine Code Type" | |
unless $code_type; | |
die "Couldn't determine Load Address" | |
unless $load_address; | |
if (!$dwarf_path) { | |
my @dwarf_paths = dSYM_dwarf_paths; | |
die "No dSYMs found" | |
unless @dwarf_paths > 0; | |
$dwarf_path = $dwarf_paths[0]; | |
} | |
die "bad path found: '$dwarf_path'" | |
unless -f $dwarf_path; | |
my $ret = `xcrun atos -arch $code_type -o '$dwarf_path' -l '$load_address' '$address'`; | |
chomp $ret; | |
return $ret; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment