OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # | 2 # |
3 # Copyright (C) 2013 The Android Open Source Project | 3 # Copyright (C) 2013 The Android Open Source Project |
4 # | 4 # |
5 # Licensed under the Apache License, Version 2.0 (the "License"); | 5 # Licensed under the Apache License, Version 2.0 (the "License"); |
6 # you may not use this file except in compliance with 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 | 7 # You may obtain a copy of the License at |
8 # | 8 # |
9 # http://www.apache.org/licenses/LICENSE-2.0 | 9 # http://www.apache.org/licenses/LICENSE-2.0 |
10 # | 10 # |
11 # Unless required by applicable law or agreed to in writing, software | 11 # Unless required by applicable law or agreed to in writing, software |
12 # distributed under the License is distributed on an "AS IS" BASIS, | 12 # distributed under the License is distributed on an "AS IS" BASIS, |
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
14 # See the License for the specific language governing permissions and | 14 # See the License for the specific language governing permissions and |
15 # limitations under the License. | 15 # limitations under the License. |
16 | 16 |
17 """stack symbolizes native crash dumps.""" | 17 """stack symbolizes native crash dumps.""" |
18 | 18 |
19 import getopt | 19 import getopt |
20 import glob | 20 import glob |
21 import os | 21 import os |
22 import re | |
23 import sys | 22 import sys |
24 | 23 |
25 import stack_core | 24 import stack_core |
26 import subprocess | 25 import subprocess |
27 import symbol | 26 import symbol |
28 import sys | 27 import sys |
29 | 28 |
30 DEFAULT_SYMROOT='/tmp/symbols' | 29 DEFAULT_SYMROOT='/tmp/symbols' |
31 | 30 |
32 def PrintUsage(): | 31 def PrintUsage(): |
33 """Print usage and exit with error.""" | 32 """Print usage and exit with error.""" |
34 # pylint: disable-msg=C6310 | 33 # pylint: disable-msg=C6310 |
35 print | 34 print |
36 print " usage: " + sys.argv[0] + " [options] [FILE]" | 35 print " usage: " + sys.argv[0] + " [options] [FILE]" |
37 print | 36 print |
38 print " --symbols-dir=path" | 37 print " --symbols-dir=path" |
39 print " the path to a symbols dir, this is generally for system level" | 38 print " the path to a symbols dir, such as =/tmp/out/target/product/drea
m/symbols" |
40 print " symbols" | |
41 print | 39 print |
42 print " --mojo-symbols-dir=path" | 40 print " --chrome-symbols-dir=path" |
43 print " the path to a directory containing Mojo symbols (can be" | 41 print " the path to a Chrome symbols dir (can be absolute or relative" |
44 print " absolute or relative to src), such as =out/android_Debug" | 42 print " to src), such as =out/Debug/lib" |
45 print " If not specified, will look for the newest lib in " | 43 print " If not specified, will look for the newest lib in out/Debug or" |
46 print " out/android_Debug or out/android_Release" | 44 print " out/Release" |
47 print | 45 print |
48 print " --symbols-zip=path" | 46 print " --symbols-zip=path" |
49 print " the path to a symbols zip file, such as =dream-symbols-12345.zip
" | 47 print " the path to a symbols zip file, such as =dream-symbols-12345.zip
" |
50 print | 48 print |
51 print " --more-info" | 49 print " --more-info" |
52 print " --less-info" | 50 print " --less-info" |
53 print " Change the level of detail in the output." | 51 print " Change the level of detail in the output." |
54 print " --more-info is slower and more verbose, but more functions will" | 52 print " --more-info is slower and more verbose, but more functions will" |
55 print " be fully qualified with namespace/classname and have full" | 53 print " be fully qualified with namespace/classname and have full" |
56 print " argument information. Also, the 'stack data' section will be" | 54 print " argument information. Also, the 'stack data' section will be" |
57 print " printed." | 55 print " printed." |
58 print | 56 print |
59 print " --arch=arm|arm64|x64|x86|mips" | 57 print " --arch=arm|arm64|x86_64|x86|mips" |
60 print " the target architecture" | 58 print " the target architecture" |
61 print | 59 print |
62 print " FILE should contain a stack trace in it somewhere" | 60 print " FILE should contain a stack trace in it somewhere" |
63 print " the tool will find that and re-print it with" | 61 print " the tool will find that and re-print it with" |
64 print " source files and line numbers. If you don't" | 62 print " source files and line numbers. If you don't" |
65 print " pass FILE, or if file is -, it reads from" | 63 print " pass FILE, or if file is -, it reads from" |
66 print " stdin." | 64 print " stdin." |
67 print | 65 print |
68 # pylint: enable-msg=C6310 | 66 # pylint: enable-msg=C6310 |
69 sys.exit(1) | 67 sys.exit(1) |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 android_symbols = glob.glob("%s/out/target/product/*/symbols" % symdir) | 101 android_symbols = glob.glob("%s/out/target/product/*/symbols" % symdir) |
104 if android_symbols: | 102 if android_symbols: |
105 return (symdir, android_symbols[0]) | 103 return (symdir, android_symbols[0]) |
106 else: | 104 else: |
107 # This is a zip of Chrome symbols, so symbol.CHROME_SYMBOLS_DIR needs to be | 105 # This is a zip of Chrome symbols, so symbol.CHROME_SYMBOLS_DIR needs to be |
108 # updated to point here. | 106 # updated to point here. |
109 symbol.CHROME_SYMBOLS_DIR = symdir | 107 symbol.CHROME_SYMBOLS_DIR = symdir |
110 return (symdir, symdir) | 108 return (symdir, symdir) |
111 | 109 |
112 | 110 |
113 def GetBasenameFromMojoApp(url): | |
114 """Used by GetSymbolMapping() to extract the basename from the location the | |
115 mojo app was downloaded from. The location is a URL, e.g. | |
116 http://foo/bar/x.so.""" | |
117 index = url.rfind('/') | |
118 return url[(index + 1):] if index != -1 else url | |
119 | |
120 | |
121 def GetSymbolMapping(lines): | |
122 """Returns a mapping (dictionary) from download file to .so.""" | |
123 regex = re.compile('Caching mojo app (\S+) at (\S+)') | |
124 mappings = {} | |
125 for line in lines: | |
126 result = regex.search(line) | |
127 if result: | |
128 mappings[result.group(2)] = GetBasenameFromMojoApp(result.group(1)) | |
129 return mappings | |
130 | |
131 | |
132 def main(): | 111 def main(): |
133 try: | 112 try: |
134 options, arguments = getopt.getopt(sys.argv[1:], "", | 113 options, arguments = getopt.getopt(sys.argv[1:], "", |
135 ["more-info", | 114 ["more-info", |
136 "less-info", | 115 "less-info", |
137 "mojo-symbols-dir=", | 116 "chrome-symbols-dir=", |
138 "symbols-dir=", | 117 "symbols-dir=", |
139 "symbols-zip=", | 118 "symbols-zip=", |
140 "arch=", | 119 "arch=", |
141 "help"]) | 120 "help"]) |
142 except getopt.GetoptError, unused_error: | 121 except getopt.GetoptError, unused_error: |
143 PrintUsage() | 122 PrintUsage() |
144 | 123 |
145 zip_arg = None | 124 zip_arg = None |
146 more_info = False | 125 more_info = False |
147 for option, value in options: | 126 for option, value in options: |
148 if option == "--help": | 127 if option == "--help": |
149 PrintUsage() | 128 PrintUsage() |
150 elif option == "--symbols-dir": | 129 elif option == "--symbols-dir": |
151 symbol.SYMBOLS_DIR = os.path.expanduser(value) | 130 symbol.SYMBOLS_DIR = os.path.expanduser(value) |
152 elif option == "--symbols-zip": | 131 elif option == "--symbols-zip": |
153 zip_arg = os.path.expanduser(value) | 132 zip_arg = os.path.expanduser(value) |
154 elif option == "--arch": | 133 elif option == "--arch": |
155 symbol.ARCH = value | 134 symbol.ARCH = value |
156 elif option == "--mojo-symbols-dir": | 135 elif option == "--chrome-symbols-dir": |
157 symbol.CHROME_SYMBOLS_DIR = os.path.join(symbol.CHROME_SYMBOLS_DIR, value) | 136 symbol.CHROME_SYMBOLS_DIR = os.path.join(symbol.CHROME_SYMBOLS_DIR, value) |
158 elif option == "--more-info": | 137 elif option == "--more-info": |
159 more_info = True | 138 more_info = True |
160 elif option == "--less-info": | 139 elif option == "--less-info": |
161 more_info = False | 140 more_info = False |
162 | 141 |
163 if len(arguments) > 1: | 142 if len(arguments) > 1: |
164 PrintUsage() | 143 PrintUsage() |
165 | 144 |
166 if not arguments or arguments[0] == "-": | 145 if not arguments or arguments[0] == "-": |
167 print "Reading native crash info from stdin" | 146 print "Reading native crash info from stdin" |
168 f = sys.stdin | 147 f = sys.stdin |
169 else: | 148 else: |
170 print "Searching for native crashes in %s" % arguments[0] | 149 print "Searching for native crashes in %s" % arguments[0] |
171 f = open(arguments[0], "r") | 150 f = open(arguments[0], "r") |
172 | 151 |
173 lines = f.readlines() | 152 lines = f.readlines() |
174 f.close() | 153 f.close() |
175 | 154 |
176 rootdir = None | 155 rootdir = None |
177 if zip_arg: | 156 if zip_arg: |
178 rootdir, symbol.SYMBOLS_DIR = UnzipSymbols(zip_arg) | 157 rootdir, symbol.SYMBOLS_DIR = UnzipSymbols(zip_arg) |
179 | 158 |
180 print "Reading Android symbols from", symbol.SYMBOLS_DIR | 159 print "Reading Android symbols from", symbol.SYMBOLS_DIR |
181 print "Reading Chrome symbols from", symbol.CHROME_SYMBOLS_DIR | 160 print "Reading Chrome symbols from", symbol.CHROME_SYMBOLS_DIR |
182 stack_core.ConvertTrace(lines, more_info, GetSymbolMapping(lines)) | 161 stack_core.ConvertTrace(lines, more_info) |
183 | 162 |
184 if rootdir: | 163 if rootdir: |
185 # be a good citizen and clean up...os.rmdir and os.removedirs() don't work | 164 # be a good citizen and clean up...os.rmdir and os.removedirs() don't work |
186 cmd = "rm -rf \"%s\"" % rootdir | 165 cmd = "rm -rf \"%s\"" % rootdir |
187 print "\ncleaning up (%s)" % cmd | 166 print "\ncleaning up (%s)" % cmd |
188 os.system(cmd) | 167 os.system(cmd) |
189 | 168 |
190 if __name__ == "__main__": | 169 if __name__ == "__main__": |
191 main() | 170 main() |
192 | 171 |
193 # vi: ts=2 sw=2 | 172 # vi: ts=2 sw=2 |
OLD | NEW |