• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2#
3# Copyright (C) 2013 The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9#      http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17"""stack symbolizes native crash dumps."""
18
19import argparse
20import atexit
21import glob
22import sys
23import tempfile
24import zipfile
25
26import stack_core
27import symbol
28
29def main():
30  parser = argparse.ArgumentParser(description='Parse and symbolize crashes')
31  parser.add_argument('--arch', help='the target architecture')
32  group = parser.add_mutually_exclusive_group()
33  group.add_argument('--symbols-dir', '--syms', '--symdir', help='the symbols directory')
34  group.add_argument('--symbols-zip', help='the symbols.zip file from a build')
35  parser.add_argument('-v', '--verbose', action='store_true', help="include function parameters")
36  parser.add_argument('file',
37                      metavar='FILE',
38                      default='-',
39                      nargs='?',  # Required for default.
40                      help='should contain a stack trace in it somewhere the '
41                           'tool will find that and re-print it with source '
42                           'files and line numbers. If you don\'t pass FILE, '
43                           'or if file is -, it reads from stdin.')
44
45  args = parser.parse_args()
46  if args.arch:
47    symbol.ARCH_IS_32BIT = not "64" in args.arch
48  if args.symbols_dir:
49    symbol.SYMBOLS_DIR = args.symbols_dir
50  if args.symbols_zip:
51    tmp = tempfile.TemporaryDirectory()
52    atexit.register(tmp.cleanup)
53    with zipfile.ZipFile(args.symbols_zip) as zf:
54      zf.extractall(tmp.name)
55    symbol.SYMBOLS_DIR = glob.glob("%s/out/target/product/*/symbols" % tmp.name)[0]
56  symbol.VERBOSE = args.verbose
57  if args.file == '-':
58    print("Reading native crash info from stdin")
59    sys.stdin.reconfigure(errors='ignore')
60    f = sys.stdin
61  else:
62    print("Searching for native crashes in %s" % args.file)
63    f = open(args.file, "r", errors='ignore')
64
65  lines = f.readlines()
66  f.close()
67
68  stack_core.ConvertTrace(lines)
69
70if __name__ == "__main__":
71  main()
72
73# vi: ts=2 sw=2
74