Skip to content

Instantly share code, notes, and snippets.

@drewmccormack
Last active August 15, 2023 09:32
Show Gist options
  • Save drewmccormack/44e6511b3a96c53cdbc3cc9e358f7ab6 to your computer and use it in GitHub Desktop.
Save drewmccormack/44e6511b3a96c53cdbc3cc9e358f7ab6 to your computer and use it in GitHub Desktop.
Symbolicates a sample dump from Activity Monitor
#!/usr/bin/env python
#
# To use this, just put the DSYMS in the same directory as the sample dump file,
# and run the script from that directory, passing the sample dump file name as only argument
#
import re, sys, os, subprocess
sampleFile = sys.argv[1]
for sampleLine in open(sampleFile, 'r').readlines():
match = re.search(r'\?{3}\s*\(in\s+(.*?)\)\s+load address\s*([\d\w]+).*\[([\d\w]+)\]', sampleLine)
if match:
binary = match.group(1)
loadAddress = match.group(2)
offset = match.group(3)
script = "atos -arch x86_64 -o {0}.*.dSYM/Contents/Resources/DWARF/{1} -l {2} {3} > temp".format(binary, binary, loadAddress, offset)
os.system(script)
method = open('temp', 'r').read()
sampleLine = sampleLine.replace(r'???', method)
print sampleLine,
@AdamNorberg
Copy link

hey, thank you, this is very useful!

I tweaked it for Python3 -- https://gist.github.com/AdamNorberg/c0cd67ed956d2f1cb9f1b6a03b0ffd8c (feel free to merge the changes back in, of course). it only changes the shebang line and the final print statement.

@AnZhg
Copy link

AnZhg commented Aug 15, 2023

If you are on macOS Sonoma, there is a symbolicate button in Sample window. You can symbolicate the sample from there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment