3 # Copyright (C) 2013 The Android Open Source Project
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
9 # http://www.apache.org/licenses/LICENSE-2.0
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.
17 """stack symbolizes native crash dumps."""
30 DEFAULT_SYMROOT
='/tmp/symbols'
33 """Print usage and exit with error."""
34 # pylint: disable-msg=C6310
36 print " usage: " + sys
.argv
[0] + " [options] [FILE]"
38 print " --symbols-dir=path"
39 print " the path to a symbols dir, such as =/tmp/out/target/product/dream/symbols"
41 print " --chrome-symbols-dir=path"
42 print " the path to a Chrome symbols dir (can be absolute or relative"
43 print " to src), such as =out/Debug/lib"
44 print " If not specified, will look for the newest lib in out/Debug or"
47 print " --symbols-zip=path"
48 print " the path to a symbols zip file, such as =dream-symbols-12345.zip"
52 print " Change the level of detail in the output."
53 print " --more-info is slower and more verbose, but more functions will"
54 print " be fully qualified with namespace/classname and have full"
55 print " argument information. Also, the 'stack data' section will be"
58 print " --arch=arm|arm64|x64|x86|mips"
59 print " the target architecture"
62 print " enable extra logging, particularly for debugging failed symbolization"
64 print " FILE should contain a stack trace in it somewhere"
65 print " the tool will find that and re-print it with"
66 print " source files and line numbers. If you don't"
67 print " pass FILE, or if file is -, it reads from"
70 # pylint: enable-msg=C6310
73 def UnzipSymbols(symbolfile
, symdir
=None):
74 """Unzips a file to DEFAULT_SYMROOT and returns the unzipped location.
77 symbolfile: The .zip file to unzip
78 symdir: Optional temporary directory to use for extraction
81 A tuple containing (the directory into which the zip file was unzipped,
82 the path to the "symbols" directory in the unzipped file). To clean
83 up, the caller can delete the first element of the tuple.
86 SymbolDownloadException: When the unzip fails.
89 symdir
= "%s/%s" % (DEFAULT_SYMROOT
, hash(symbolfile
))
90 if not os
.path
.exists(symdir
):
93 print "extracting %s..." % symbolfile
94 saveddir
= os
.getcwd()
97 unzipcode
= subprocess
.call(["unzip", "-qq", "-o", symbolfile
])
100 raise SymbolDownloadException("failed to extract symbol files (%s)."
105 android_symbols
= glob
.glob("%s/out/target/product/*/symbols" % symdir
)
107 return (symdir
, android_symbols
[0])
109 # This is a zip of Chrome symbols, so symbol.CHROME_SYMBOLS_DIR needs to be
110 # updated to point here.
111 symbol
.CHROME_SYMBOLS_DIR
= symdir
112 return (symdir
, symdir
)
117 options
, arguments
= getopt
.getopt(argv
, "",
120 "chrome-symbols-dir=",
126 except getopt
.GetoptError
, unused_error
:
131 for option
, value
in options
:
132 if option
== "--help":
134 elif option
== "--symbols-dir":
135 symbol
.SYMBOLS_DIR
= os
.path
.expanduser(value
)
136 elif option
== "--symbols-zip":
137 zip_arg
= os
.path
.expanduser(value
)
138 elif option
== "--arch":
140 elif option
== "--chrome-symbols-dir":
141 symbol
.CHROME_SYMBOLS_DIR
= os
.path
.join(symbol
.CHROME_SYMBOLS_DIR
, value
)
142 elif option
== "--more-info":
144 elif option
== "--less-info":
146 elif option
== "--verbose":
147 logging
.basicConfig(level
=logging
.DEBUG
)
149 if len(arguments
) > 1:
152 if not arguments
or arguments
[0] == "-":
153 print "Reading native crash info from stdin"
156 print "Searching for native crashes in %s" % arguments
[0]
157 f
= open(arguments
[0], "r")
159 lines
= f
.readlines()
164 rootdir
, symbol
.SYMBOLS_DIR
= UnzipSymbols(zip_arg
)
166 print "Reading Android symbols from", symbol
.SYMBOLS_DIR
167 print "Reading Chrome symbols from", symbol
.CHROME_SYMBOLS_DIR
168 stack_core
.ConvertTrace(lines
, more_info
)
171 # be a good citizen and clean up...os.rmdir and os.removedirs() don't work
172 cmd
= "rm -rf \"%s\"" % rootdir
173 print "\ncleaning up (%s)" % cmd
176 if __name__
== "__main__":
177 sys
.exit(main(sys
.argv
[1:]))