mirror of
https://github.com/WiVRn/WiVRn.git
synced 2026-11-20 00:51:32 -08:00
55 lines
1.5 KiB
Python
Executable File
55 lines
1.5 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
import os
|
|
import re
|
|
import subprocess
|
|
import sys
|
|
|
|
from elftools.elf.elffile import ELFFile
|
|
from elftools.elf.sections import NoteSection
|
|
|
|
|
|
def get_lib_list(path):
|
|
def get_build_id(filename):
|
|
with open(filename, "rb") as f:
|
|
for sect in ELFFile(f).iter_sections():
|
|
if not isinstance(sect, NoteSection):
|
|
continue
|
|
for note in sect.iter_notes():
|
|
if note["n_type"] in {"NT_GNU_BUILD_ID", "NT_GNU_GOLD_VERSION"}:
|
|
return note["n_desc"]
|
|
return None
|
|
|
|
libs = {}
|
|
|
|
for root, dirs, files in os.walk(path):
|
|
for name in files:
|
|
if name.endswith(".so"):
|
|
build_id = get_build_id(os.path.join(root, name))
|
|
if build_id:
|
|
libs[build_id] = os.path.join(root, name)
|
|
|
|
return libs
|
|
|
|
|
|
libs = get_lib_list("build/intermediates/merged_native_libs")
|
|
|
|
# stack trace
|
|
r = re.compile("^.*#[0-9]+ pc ([0-9a-f]+) .*BuildId: ([0-9a-f]*).*")
|
|
# address sanitizer
|
|
r1 = re.compile("^.*#[0-9]+ 0x[0-9a-f]+ .*\\+0x([0-9a-f]+).*BuildId: ([0-9a-f]*).*")
|
|
|
|
for line in sys.stdin:
|
|
m = r.match(line.rstrip())
|
|
if not m:
|
|
m = r1.match(line.rstrip())
|
|
if m:
|
|
address = m[1]
|
|
build_id = m[2]
|
|
|
|
if build_id in libs:
|
|
lib = libs[build_id]
|
|
subprocess.run(
|
|
["llvm-symbolizer"], input=(lib + " 0x" + address).encode("utf-8"), check=False
|
|
)
|