From bb8701b51462102868de3b0a6fb91ba11df4f768 Mon Sep 17 00:00:00 2001 From: Omar A Rodriguez Date: Fri, 14 Feb 2014 00:31:41 -0800 Subject: [PATCH] Print backtrace after a native crash --- pidcat.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pidcat.py b/pidcat.py index 28bf9fd..e514445 100755 --- a/pidcat.py +++ b/pidcat.py @@ -93,6 +93,7 @@ KNOWN_TAGS = { 'AndroidRuntime': CYAN, 'jdwp': WHITE, 'StrictMode': WHITE, + 'DEBUG': YELLOW, } def allocate_color(tag): @@ -137,6 +138,7 @@ PID_LEAVE = re.compile(r'^No longer want ([a-zA-Z0-9._]+) \(pid (\d+)\): .*$') PID_DEATH = re.compile(r'^Process ([a-zA-Z0-9._]+) \(pid (\d+)\) has died.?$') LOG_LINE = re.compile(r'^([A-Z])/(.+?)\( *(\d+)\): (.*?)$') BUG_LINE = re.compile(r'.*nativeGetEnabledTags.*') +BACKTRACE_LINE = re.compile(r'^#(.*?)pc\s(.*?)$') adb_command = ['adb'] if args.device_serial: @@ -150,6 +152,7 @@ adb_command.append('logcat') adb = subprocess.Popen(adb_command, stdin=PIPE, stdout=PIPE, stderr=PIPE) pids = set() last_tag = None +app_pid = None def match_packages(token): if len(args.package) == 0: @@ -202,6 +205,8 @@ while adb.poll() is None: if match_packages(line_package): pids.add(line_pid) + app_pid = line_pid + linebuf = '\n' linebuf += colorize(' ' * (header_size - 1), bg=WHITE) linebuf += indent_wrap(' Process created for %s\n' % target) @@ -221,6 +226,13 @@ while adb.poll() is None: print(linebuf) last_tag = None # Ensure next log gets a tag printed + # Make sure the backtrace is printed after a native crash + if tag.strip() == 'DEBUG': + bt_line = BACKTRACE_LINE.match(message.lstrip()) + if bt_line is not None: + message = message.lstrip() + owner = app_pid + if owner not in pids: continue if level in LOG_LEVELS_MAP and LOG_LEVELS_MAP[level] < min_level: