Krzysztof Kosiński | b136111 | 2021-03-11 18:05:01 -0800 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Iliyan Malchev | 4929d6a | 2011-08-04 17:44:40 -0700 | [diff] [blame] | 2 | # |
Ben Cheng | b42dad0 | 2013-04-25 15:14:04 -0700 | [diff] [blame] | 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. |
Iliyan Malchev | 4929d6a | 2011-08-04 17:44:40 -0700 | [diff] [blame] | 16 | |
| 17 | """stack symbolizes native crash dumps.""" |
| 18 | |
Andreas Gampe | 3c9db52 | 2019-04-08 12:04:40 -0700 | [diff] [blame] | 19 | import argparse |
Elliott Hughes | 409282b | 2021-09-09 17:51:50 -0700 | [diff] [blame] | 20 | import atexit |
| 21 | import glob |
Iliyan Malchev | 4929d6a | 2011-08-04 17:44:40 -0700 | [diff] [blame] | 22 | import sys |
Elliott Hughes | 409282b | 2021-09-09 17:51:50 -0700 | [diff] [blame] | 23 | import tempfile |
| 24 | import zipfile |
Iliyan Malchev | 4929d6a | 2011-08-04 17:44:40 -0700 | [diff] [blame] | 25 | |
Ben Cheng | b42dad0 | 2013-04-25 15:14:04 -0700 | [diff] [blame] | 26 | import stack_core |
Iliyan Malchev | 4929d6a | 2011-08-04 17:44:40 -0700 | [diff] [blame] | 27 | import symbol |
| 28 | |
Iliyan Malchev | 4929d6a | 2011-08-04 17:44:40 -0700 | [diff] [blame] | 29 | def main(): |
Andreas Gampe | 3c9db52 | 2019-04-08 12:04:40 -0700 | [diff] [blame] | 30 | parser = argparse.ArgumentParser(description='Parse and symbolize crashes') |
| 31 | parser.add_argument('--arch', help='the target architecture') |
Elliott Hughes | 409282b | 2021-09-09 17:51:50 -0700 | [diff] [blame] | 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') |
David Srbecky | 80547ae | 2021-11-01 21:59:59 +0000 | [diff] [blame] | 35 | parser.add_argument('-v', '--verbose', action='store_true', help="include function parameters") |
Andreas Gampe | 3c9db52 | 2019-04-08 12:04:40 -0700 | [diff] [blame] | 36 | parser.add_argument('file', |
| 37 | metavar='FILE', |
| 38 | default='-', |
Andreas Gampe | dcf9800 | 2019-04-30 10:07:24 -0700 | [diff] [blame] | 39 | nargs='?', # Required for default. |
Andreas Gampe | 3c9db52 | 2019-04-08 12:04:40 -0700 | [diff] [blame] | 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.') |
Iliyan Malchev | 4929d6a | 2011-08-04 17:44:40 -0700 | [diff] [blame] | 44 | |
Andreas Gampe | 3c9db52 | 2019-04-08 12:04:40 -0700 | [diff] [blame] | 45 | args = parser.parse_args() |
Andreas Gampe | 3c9db52 | 2019-04-08 12:04:40 -0700 | [diff] [blame] | 46 | if args.arch: |
| 47 | symbol.ARCH = args.arch |
Elliott Hughes | 409282b | 2021-09-09 17:51:50 -0700 | [diff] [blame] | 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] |
David Srbecky | 80547ae | 2021-11-01 21:59:59 +0000 | [diff] [blame] | 56 | symbol.VERBOSE = args.verbose |
Andreas Gampe | 3c9db52 | 2019-04-08 12:04:40 -0700 | [diff] [blame] | 57 | if args.file == '-': |
Krzysztof Kosiński | b136111 | 2021-03-11 18:05:01 -0800 | [diff] [blame] | 58 | print("Reading native crash info from stdin") |
Iliyan Malchev | 4929d6a | 2011-08-04 17:44:40 -0700 | [diff] [blame] | 59 | f = sys.stdin |
| 60 | else: |
Krzysztof Kosiński | b136111 | 2021-03-11 18:05:01 -0800 | [diff] [blame] | 61 | print("Searching for native crashes in %s" % args.file) |
Andreas Gampe | 3c9db52 | 2019-04-08 12:04:40 -0700 | [diff] [blame] | 62 | f = open(args.file, "r") |
Iliyan Malchev | 4929d6a | 2011-08-04 17:44:40 -0700 | [diff] [blame] | 63 | |
| 64 | lines = f.readlines() |
| 65 | f.close() |
| 66 | |
Ben Cheng | b42dad0 | 2013-04-25 15:14:04 -0700 | [diff] [blame] | 67 | stack_core.ConvertTrace(lines) |
Iliyan Malchev | 4929d6a | 2011-08-04 17:44:40 -0700 | [diff] [blame] | 68 | |
| 69 | if __name__ == "__main__": |
| 70 | main() |
| 71 | |
| 72 | # vi: ts=2 sw=2 |