Iliyan Malchev | 4929d6a | 2011-08-04 17:44:40 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 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 | |
| 19 | import getopt |
Iliyan Malchev | 4929d6a | 2011-08-04 17:44:40 -0700 | [diff] [blame] | 20 | import sys |
Iliyan Malchev | 4929d6a | 2011-08-04 17:44:40 -0700 | [diff] [blame] | 21 | |
Ben Cheng | b42dad0 | 2013-04-25 15:14:04 -0700 | [diff] [blame] | 22 | import stack_core |
Iliyan Malchev | 4929d6a | 2011-08-04 17:44:40 -0700 | [diff] [blame] | 23 | import symbol |
| 24 | |
| 25 | |
| 26 | def PrintUsage(): |
| 27 | """Print usage and exit with error.""" |
| 28 | # pylint: disable-msg=C6310 |
| 29 | print |
| 30 | print " usage: " + sys.argv[0] + " [options] [FILE]" |
| 31 | print |
Ben Cheng | b42dad0 | 2013-04-25 15:14:04 -0700 | [diff] [blame] | 32 | print " --arch=arm|x86" |
| 33 | print " the target architecture" |
Iliyan Malchev | 4929d6a | 2011-08-04 17:44:40 -0700 | [diff] [blame] | 34 | print |
| 35 | print " FILE should contain a stack trace in it somewhere" |
| 36 | print " the tool will find that and re-print it with" |
| 37 | print " source files and line numbers. If you don't" |
| 38 | print " pass FILE, or if file is -, it reads from" |
| 39 | print " stdin." |
| 40 | print |
| 41 | # pylint: enable-msg=C6310 |
| 42 | sys.exit(1) |
| 43 | |
| 44 | |
Iliyan Malchev | 4929d6a | 2011-08-04 17:44:40 -0700 | [diff] [blame] | 45 | def main(): |
| 46 | try: |
| 47 | options, arguments = getopt.getopt(sys.argv[1:], "", |
Ben Cheng | b42dad0 | 2013-04-25 15:14:04 -0700 | [diff] [blame] | 48 | ["arch=", |
Iliyan Malchev | 4929d6a | 2011-08-04 17:44:40 -0700 | [diff] [blame] | 49 | "help"]) |
| 50 | except getopt.GetoptError, unused_error: |
| 51 | PrintUsage() |
| 52 | |
Iliyan Malchev | 4929d6a | 2011-08-04 17:44:40 -0700 | [diff] [blame] | 53 | for option, value in options: |
| 54 | if option == "--help": |
| 55 | PrintUsage() |
Ben Cheng | b42dad0 | 2013-04-25 15:14:04 -0700 | [diff] [blame] | 56 | elif option == "--arch": |
| 57 | symbol.ARCH = value |
Iliyan Malchev | 4929d6a | 2011-08-04 17:44:40 -0700 | [diff] [blame] | 58 | |
| 59 | if len(arguments) > 1: |
| 60 | PrintUsage() |
| 61 | |
Iliyan Malchev | 4929d6a | 2011-08-04 17:44:40 -0700 | [diff] [blame] | 62 | if not arguments or arguments[0] == "-": |
| 63 | print "Reading native crash info from stdin" |
| 64 | f = sys.stdin |
| 65 | else: |
| 66 | print "Searching for native crashes in %s" % arguments[0] |
| 67 | f = open(arguments[0], "r") |
| 68 | |
| 69 | lines = f.readlines() |
| 70 | f.close() |
| 71 | |
Ben Cheng | b42dad0 | 2013-04-25 15:14:04 -0700 | [diff] [blame] | 72 | stack_core.ConvertTrace(lines) |
Iliyan Malchev | 4929d6a | 2011-08-04 17:44:40 -0700 | [diff] [blame] | 73 | |
| 74 | if __name__ == "__main__": |
| 75 | main() |
| 76 | |
| 77 | # vi: ts=2 sw=2 |