From 7e73f7a7b43bc2548909feecdcb8671502fc8f54 Mon Sep 17 00:00:00 2001 From: Shibin George Date: Fri, 5 Oct 2018 18:02:54 +0530 Subject: [PATCH] Prevent "index out of range" crash when addr2line aborts in between addr2line may abort and "result" may be incomplete. This leads to "index out of range" exceptions. Enclose this in a try & except block and on exception, default to function:location = ---:--- Test: "python native_heapdump_viewer_tests.py" (after CL:780974) passes. BUG: 117306194 Change-Id: I4fd5c784949f279550aec95b68045df4a671da74 --- scripts/native_heapdump_viewer.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/scripts/native_heapdump_viewer.py b/scripts/native_heapdump_viewer.py index 05df0a6bc..e888e8f42 100755 --- a/scripts/native_heapdump_viewer.py +++ b/scripts/native_heapdump_viewer.py @@ -16,6 +16,7 @@ """Generates a human-interpretable view of a native heap dump from 'am dumpheap -n'.""" +import logging import os import os.path import re @@ -320,11 +321,18 @@ def ResolveAddrs(html_output, symboldir, app_symboldir, backtraces, mappings): p = subprocess.Popen(["addr2line", "-C", "-j", ".text", "-e", sofile, "-f"], stdout=subprocess.PIPE, stdin=subprocess.PIPE) result = p.communicate(input_addrs)[0] + addr2line_rc = p.returncode + if addr2line_rc and (addr2line_rc < 0): + logging.warn("addr2line on " + sofile + " terminated by signal " + str(-1 * addr2line_rc)) splitted = result.split("\n") for x in range(0, len(addrs_by_lib[lib])): - function = splitted[2*x]; - location = splitted[2*x+1]; - resolved_addrs[addrs_by_lib[lib][x]] = FrameDescription(function, location, lib) + try: + function = splitted[2*x]; + location = splitted[2*x+1]; + resolved_addrs[addrs_by_lib[lib][x]] = FrameDescription(function, location, lib) + except Exception: + logging.warn("exception while resolving symbols", exc_info=True) + resolved_addrs[addrs_by_lib[lib][x]] = FrameDescription("---", "---", lib) else: if html_output == False: print "%s not found for symbol resolution" % lib