xref: /aosp_15_r20/external/skia/infra/bots/recipe_modules/flavor/resources/dump_adb_log.py (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
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
6import os
7import subprocess
8import sys
9
10out = sys.argv[1]
11adb = sys.argv[2]
12log = subprocess.check_output([
13    adb, 'logcat', '-d']).decode('utf-8', errors='ignore')
14for 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)
27