Index: third_party/android_platform/development/scripts/symbol.py |
diff --git a/third_party/android_platform/development/scripts/symbol.py b/third_party/android_platform/development/scripts/symbol.py |
index 9eb248493419e9513d20ddee881bfdf6b92587d3..04822aeea44bb6c42bddcc926856360225b284e1 100755 |
--- a/third_party/android_platform/development/scripts/symbol.py |
+++ b/third_party/android_platform/development/scripts/symbol.py |
@@ -21,6 +21,7 @@ The information can include symbol names, offsets, and source locations. |
import os |
import re |
+import sys |
import subprocess |
CHROME_SRC = os.path.join(os.path.realpath(os.path.dirname(__file__)), |
@@ -33,6 +34,9 @@ ARCH = "arm" |
TOOLCHAIN_INFO = None |
+sys.path.insert(0, os.path.join(CHROME_SRC, 'build', 'android')) |
+from pylib.symbols import elf_symbolizer |
+ |
def Uname(): |
"""'uname' for constructing prebuilt/<...> and out/host/<...> paths.""" |
uname = os.uname()[0] |
@@ -240,42 +244,34 @@ def CallAddr2LineForSet(lib, unique_addrs): |
if not lib: |
return None |
- |
symbols = SYMBOLS_DIR + lib |
if not os.path.isfile(symbols): |
return None |
- (label, platform, target) = FindToolchain() |
- cmd = [ToolPath("addr2line"), "--functions", "--inlines", |
- "--demangle", "--exe=" + symbols] |
- child = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE) |
- |
- result = {} |
addrs = sorted(unique_addrs) |
- for addr in addrs: |
- child.stdin.write("0x%s\n" % addr) |
- child.stdin.flush() |
+ result = {} |
+ |
+ def _Callback(sym, addr): |
records = [] |
- first = True |
- while True: |
- symbol = child.stdout.readline().strip() |
- if symbol == "??": |
- symbol = None |
- location = child.stdout.readline().strip() |
- if location == "??:0": |
+ while sym: # Traverse all the inlines following the |inlined_by| chain. |
+ if sym.source_path: |
+ location = '%s:%d' % (sym.source_path, sym.source_line) |
+ else: |
location = None |
- if symbol is None and location is None: |
- break |
- records.append((symbol, location)) |
- if first: |
- # Write a blank line as a sentinel so we know when to stop |
- # reading inlines from the output. |
- # The blank line will cause addr2line to emit "??\n??:0\n". |
- child.stdin.write("\n") |
- first = False |
+ records += [(sym.name, location)] |
+ sym = sym.inlined_by |
result[addr] = records |
- child.stdin.close() |
- child.stdout.close() |
+ |
+ (label, platform, target) = FindToolchain() |
+ symbolizer = elf_symbolizer.ELFSymbolizer( |
+ elf_file_path=symbols, |
+ addr2line_path=ToolPath("addr2line"), |
+ callback=_Callback, |
+ inlines=True) |
+ |
+ for addr in addrs: |
+ symbolizer.SymbolizeAsync(int(addr, 16), addr) |
+ symbolizer.Join() |
return result |