• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python
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 getopt
20import sys
21
22import stack_core
23import 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
32  print "  --arch=arm|arm64|mips|mips64|x86|x86_64"
33  print "       the target architecture"
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
45def main():
46  try:
47    options, arguments = getopt.getopt(sys.argv[1:], "",
48                                       ["arch=",
49                                        "help"])
50  except getopt.GetoptError, unused_error:
51    PrintUsage()
52
53  for option, value in options:
54    if option == "--help":
55      PrintUsage()
56    elif option == "--arch":
57      symbol.ARCH = value
58
59  if len(arguments) > 1:
60    PrintUsage()
61
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
72  stack_core.ConvertTrace(lines)
73
74if __name__ == "__main__":
75  main()
76
77# vi: ts=2 sw=2
78