blob: 256d7e977c5b4f881251d3c437ba67e1e2c537ac [file] [log] [blame]
Iliyan Malchev4929d6a2011-08-04 17:44:40 -07001#!/usr/bin/env python
2#
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
19import getopt
Iliyan Malchev4929d6a2011-08-04 17:44:40 -070020import sys
Iliyan Malchev4929d6a2011-08-04 17:44:40 -070021
Ben Chengb42dad02013-04-25 15:14:04 -070022import stack_core
Iliyan Malchev4929d6a2011-08-04 17:44:40 -070023import symbol
24
25
26def 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 Chengb42dad02013-04-25 15:14:04 -070032 print " --arch=arm|x86"
33 print " the target architecture"
Iliyan Malchev4929d6a2011-08-04 17:44:40 -070034 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 Malchev4929d6a2011-08-04 17:44:40 -070045def main():
46 try:
47 options, arguments = getopt.getopt(sys.argv[1:], "",
Ben Chengb42dad02013-04-25 15:14:04 -070048 ["arch=",
Iliyan Malchev4929d6a2011-08-04 17:44:40 -070049 "help"])
50 except getopt.GetoptError, unused_error:
51 PrintUsage()
52
Iliyan Malchev4929d6a2011-08-04 17:44:40 -070053 for option, value in options:
54 if option == "--help":
55 PrintUsage()
Ben Chengb42dad02013-04-25 15:14:04 -070056 elif option == "--arch":
57 symbol.ARCH = value
Iliyan Malchev4929d6a2011-08-04 17:44:40 -070058
59 if len(arguments) > 1:
60 PrintUsage()
61
Iliyan Malchev4929d6a2011-08-04 17:44:40 -070062 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 Chengb42dad02013-04-25 15:14:04 -070072 stack_core.ConvertTrace(lines)
Iliyan Malchev4929d6a2011-08-04 17:44:40 -070073
74if __name__ == "__main__":
75 main()
76
77# vi: ts=2 sw=2