Debian Codegraph @

infra/bots/recipe_modules/flavor/resources/dump_adb_log.py

raw
1 # Copyright 2024 Google LLC
2 #
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
5
6 import os
7 import subprocess
8 import sys
9
10 out = sys.argv[1]
11 adb = sys.argv[2]
12 log = subprocess.check_output([
13 adb, 'logcat', '-d']).decode('utf-8', errors='ignore')
14 for line in log.split('\\n'):
15 tokens = line.split()
16 if len(tokens) == 11 and tokens[-7] == 'F' and tokens[-3] == 'pc':
17 addr, path = tokens[-2:]
18 local = os.path.join(out, os.path.basename(path))
19 if os.path.exists(local):
20 try:
21 sym = subprocess.check_output([
22 'addr2line', '-Cfpe', local, addr]).decode('utf-8')
23 line = line.replace(addr, addr + ' ' + sym.strip())
24 except subprocess.CalledProcessError:
25 pass
26 print(line)