blob: 713bbc3c40beb7d81b92600d9d66451a484846d5 [file] [log] [blame]
Krzysztof Kosińskib1361112021-03-11 18:05:01 -08001#!/usr/bin/env python3
Iliyan Malchev4929d6a2011-08-04 17:44:40 -07002#
Ben Chengb42dad02013-04-25 15:14:04 -07003# 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.
Iliyan Malchev4929d6a2011-08-04 17:44:40 -070016
17"""stack symbolizes native crash dumps."""
18
Andreas Gampe3c9db522019-04-08 12:04:40 -070019import argparse
Elliott Hughes409282b2021-09-09 17:51:50 -070020import atexit
21import glob
Iliyan Malchev4929d6a2011-08-04 17:44:40 -070022import sys
Elliott Hughes409282b2021-09-09 17:51:50 -070023import tempfile
24import zipfile
Iliyan Malchev4929d6a2011-08-04 17:44:40 -070025
Ben Chengb42dad02013-04-25 15:14:04 -070026import stack_core
Iliyan Malchev4929d6a2011-08-04 17:44:40 -070027import symbol
28
Iliyan Malchev4929d6a2011-08-04 17:44:40 -070029def main():
Andreas Gampe3c9db522019-04-08 12:04:40 -070030 parser = argparse.ArgumentParser(description='Parse and symbolize crashes')
31 parser.add_argument('--arch', help='the target architecture')
Elliott Hughes409282b2021-09-09 17:51:50 -070032 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')
David Srbecky80547ae2021-11-01 21:59:59 +000035 parser.add_argument('-v', '--verbose', action='store_true', help="include function parameters")
Andreas Gampe3c9db522019-04-08 12:04:40 -070036 parser.add_argument('file',
37 metavar='FILE',
38 default='-',
Andreas Gampedcf98002019-04-30 10:07:24 -070039 nargs='?', # Required for default.
Andreas Gampe3c9db522019-04-08 12:04:40 -070040 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.')
Iliyan Malchev4929d6a2011-08-04 17:44:40 -070044
Andreas Gampe3c9db522019-04-08 12:04:40 -070045 args = parser.parse_args()
Andreas Gampe3c9db522019-04-08 12:04:40 -070046 if args.arch:
Christopher Ferrisa47d6d02023-03-13 14:50:48 -070047 symbol.ARCH_IS_32BIT = not "64" in args.arch
Elliott Hughes409282b2021-09-09 17:51:50 -070048 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]
David Srbecky80547ae2021-11-01 21:59:59 +000056 symbol.VERBOSE = args.verbose
Andreas Gampe3c9db522019-04-08 12:04:40 -070057 if args.file == '-':
Krzysztof Kosińskib1361112021-03-11 18:05:01 -080058 print("Reading native crash info from stdin")
Christopher Ferrisf62a3be2023-03-09 16:13:57 -080059 sys.stdin.reconfigure(errors='ignore')
Iliyan Malchev4929d6a2011-08-04 17:44:40 -070060 f = sys.stdin
61 else:
Krzysztof Kosińskib1361112021-03-11 18:05:01 -080062 print("Searching for native crashes in %s" % args.file)
Christopher Ferrisf62a3be2023-03-09 16:13:57 -080063 f = open(args.file, "r", errors='ignore')
Iliyan Malchev4929d6a2011-08-04 17:44:40 -070064
65 lines = f.readlines()
66 f.close()
67
Ben Chengb42dad02013-04-25 15:14:04 -070068 stack_core.ConvertTrace(lines)
Iliyan Malchev4929d6a2011-08-04 17:44:40 -070069
70if __name__ == "__main__":
71 main()
72
73# vi: ts=2 sw=2