Skip to content

Instantly share code, notes, and snippets.

@ntrrgc
Created July 25, 2018 17:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ntrrgc/b8489edd611b6ebd5c558aea9b8f1be4 to your computer and use it in GitHub Desktop.
Save ntrrgc/b8489edd611b6ebd5c558aea9b8f1be4 to your computer and use it in GitHub Desktop.
Add library offsets to otherwise useless WebKit crash tracebacks (requires saving /proc/{pid}/maps somewhere before the crash)
import os
import re
from collections import namedtuple
path_maps = os.path.expanduser("~/tmp/rpi-crash-maps")
path_stack = os.path.expanduser("~/tmp/rpi-crash-stack")
MapsLine = namedtuple("MapsLine", ["start", "end", "file"])
def parse_maps_line(line):
fields = re.split("\s+", line.strip())
start, end = [int(pointer, 16) for pointer in fields[0].split("-")]
file = fields[5] if len(fields) >= 6 else ""
return MapsLine(start, end, file)
memory_maps = [
parse_maps_line(line)
for line in open(path_maps, "r").readlines()
if line.strip() != "" and " r-xp " in line
]
def find_map_containing(pointer):
assert isinstance(pointer, int)
matches = [
map
for map in memory_maps
if map.start < pointer < map.end
]
assert len(matches) == 1, "Could not find a match for %x" % pointer
return matches[0]
def parse_stack_line(line):
match = re.match(r"\d+\s+(0x[a-f0-9]+).*", line)
assert match, "Could not parse: %s" % repr(line)
return int(match.groups()[0], 16)
stack_lines = [
parse_stack_line(line)
for line in open(path_stack, "r").readlines()
if line.strip() != ""
]
for i, pointer in enumerate(stack_lines, 1):
memory_map = find_map_containing(pointer)
print(" #%d 0x%x " % (i, pointer), end="")
if memory_map:
print("(%s+0x%x)" % (memory_map.file, pointer - memory_map.start))
else:
print("[GARBAGE]")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment