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 logging | 21 import logging |
22 import os | 22 import os |
23 import sys | 23 import sys |
24 | 24 |
25 import stack_core | 25 import stack_core |
26 import stack_libs | |
26 import subprocess | 27 import subprocess |
27 import symbol | 28 import symbol |
28 import sys | 29 import sys |
29 | 30 |
30 DEFAULT_SYMROOT='/tmp/symbols' | 31 DEFAULT_SYMROOT='/tmp/symbols' |
32 DEFAULT_APK_DIR='chrome_apk' | |
33 # From: https://source.android.com/source/build-numbers.html | |
34 _ANDROID_M_MAJOR_VERSION=6 | |
31 | 35 |
32 def PrintUsage(): | 36 def PrintUsage(): |
33 """Print usage and exit with error.""" | 37 """Print usage and exit with error.""" |
34 # pylint: disable-msg=C6310 | 38 # pylint: disable-msg=C6310 |
35 print | 39 print |
36 print " usage: " + sys.argv[0] + " [options] [FILE]" | 40 print " usage: " + sys.argv[0] + " [options] [FILE]" |
37 print | 41 print |
38 print " --symbols-dir=path" | 42 print " --symbols-dir=path" |
39 print " the path to a symbols dir, such as =/tmp/out/target/product/drea m/symbols" | 43 print " the path to a symbols dir, such as =/tmp/out/target/product/drea m/symbols" |
40 print | 44 print |
41 print " --chrome-symbols-dir=path" | 45 print " --chrome-symbols-dir=path" |
42 print " the path to a Chrome symbols dir (can be absolute or relative" | 46 print " the path to a Chrome symbols dir (can be absolute or relative" |
43 print " to src), such as =out/Debug/lib" | 47 print " to src), such as =out/Debug/lib" |
44 print " If not specified, will look for the newest lib in out/Debug or" | 48 print " If not specified, will look for the newest lib in out/Debug or" |
45 print " out/Release" | 49 print " out/Release" |
46 print | 50 print |
51 print " --packed-relocation-adjustments" | |
52 print " --no-packed-relocation-adjustments" | |
53 print " turn packed relocation adjustment on and off (default is off)" | |
54 print " If running on pre-M Android and the stack trace appears to" | |
55 print " make no sense, try turning this feature on." | |
56 print | |
57 print " --chrome-apk-dir=path" | |
58 print " the path to the APK staging dir (can be absolute or relative" | |
59 print " to src), such as =out/Debug/chrome_apk" | |
60 print " If not specified, uses =|chrome-symbols-dir|/../chrome_apk" | |
61 print " Parses libraries here to find data for adjusting debuggerd" | |
62 print " tombstones where relocations are packed." | |
63 print " Enable/disable with --[no-]packed-relocation-adjustments." | |
64 print | |
47 print " --symbols-zip=path" | 65 print " --symbols-zip=path" |
48 print " the path to a symbols zip file, such as =dream-symbols-12345.zip " | 66 print " the path to a symbols zip file, such as =dream-symbols-12345.zip " |
49 print | 67 print |
50 print " --more-info" | 68 print " --more-info" |
51 print " --less-info" | 69 print " --less-info" |
52 print " Change the level of detail in the output." | 70 print " Change the level of detail in the output." |
53 print " --more-info is slower and more verbose, but more functions will" | 71 print " --more-info is slower and more verbose, but more functions will" |
54 print " be fully qualified with namespace/classname and have full" | 72 print " be fully qualified with namespace/classname and have full" |
55 print " argument information. Also, the 'stack data' section will be" | 73 print " argument information. Also, the 'stack data' section will be" |
56 print " printed." | 74 print " printed." |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
108 else: | 126 else: |
109 # This is a zip of Chrome symbols, so symbol.CHROME_SYMBOLS_DIR needs to be | 127 # This is a zip of Chrome symbols, so symbol.CHROME_SYMBOLS_DIR needs to be |
110 # updated to point here. | 128 # updated to point here. |
111 symbol.CHROME_SYMBOLS_DIR = symdir | 129 symbol.CHROME_SYMBOLS_DIR = symdir |
112 return (symdir, symdir) | 130 return (symdir, symdir) |
113 | 131 |
114 | 132 |
115 def main(argv): | 133 def main(argv): |
116 try: | 134 try: |
117 options, arguments = getopt.getopt(argv, "", | 135 options, arguments = getopt.getopt(argv, "", |
118 ["more-info", | 136 ["packed-relocation-adjustments", |
137 "no-packed-relocation-adjustments", | |
138 "more-info", | |
119 "less-info", | 139 "less-info", |
120 "chrome-symbols-dir=", | 140 "chrome-symbols-dir=", |
141 "chrome-apk-dir=", | |
121 "symbols-dir=", | 142 "symbols-dir=", |
122 "symbols-zip=", | 143 "symbols-zip=", |
123 "arch=", | 144 "arch=", |
124 "verbose", | 145 "verbose", |
125 "help"]) | 146 "help"]) |
126 except getopt.GetoptError, unused_error: | 147 except getopt.GetoptError, unused_error: |
127 PrintUsage() | 148 PrintUsage() |
128 | 149 |
129 zip_arg = None | 150 zip_arg = None |
130 more_info = False | 151 more_info = False |
152 chrome_apk_symbols_dir = symbol.CHROME_SYMBOLS_DIR | |
153 chrome_apk_dir_suffix = '' | |
154 packed_relocation_adjustments = "unknown" | |
131 for option, value in options: | 155 for option, value in options: |
132 if option == "--help": | 156 if option == "--help": |
133 PrintUsage() | 157 PrintUsage() |
134 elif option == "--symbols-dir": | 158 elif option == "--symbols-dir": |
135 symbol.SYMBOLS_DIR = os.path.expanduser(value) | 159 symbol.SYMBOLS_DIR = os.path.expanduser(value) |
136 elif option == "--symbols-zip": | 160 elif option == "--symbols-zip": |
137 zip_arg = os.path.expanduser(value) | 161 zip_arg = os.path.expanduser(value) |
138 elif option == "--arch": | 162 elif option == "--arch": |
139 symbol.ARCH = value | 163 symbol.ARCH = value |
140 elif option == "--chrome-symbols-dir": | 164 elif option == "--chrome-symbols-dir": |
141 symbol.CHROME_SYMBOLS_DIR = os.path.join(symbol.CHROME_SYMBOLS_DIR, value) | 165 symbol.CHROME_SYMBOLS_DIR = os.path.join(symbol.CHROME_SYMBOLS_DIR, value) |
166 elif option == "--chrome-apk-dir": | |
167 chrome_apk_dir_suffix = os.path.join(chrome_apk_dir_suffix, value) | |
168 elif option == "--packed-relocation-adjustments": | |
169 packed_relocation_adjustments = True | |
170 elif option == "--no-packed-relocation-adjustments": | |
171 packed_relocation_adjustments = False | |
142 elif option == "--more-info": | 172 elif option == "--more-info": |
143 more_info = True | 173 more_info = True |
144 elif option == "--less-info": | 174 elif option == "--less-info": |
145 more_info = False | 175 more_info = False |
146 elif option == "--verbose": | 176 elif option == "--verbose": |
147 logging.basicConfig(level=logging.DEBUG) | 177 logging.basicConfig(level=logging.DEBUG) |
148 | 178 |
179 if chrome_apk_dir_suffix: | |
180 chrome_apk_dir = os.path.join(chrome_apk_symbols_dir, | |
181 chrome_apk_dir_suffix) | |
182 else: | |
183 chrome_apk_dir = os.path.join(symbol.CHROME_SYMBOLS_DIR, | |
184 '..', DEFAULT_APK_DIR) | |
185 | |
149 if len(arguments) > 1: | 186 if len(arguments) > 1: |
150 PrintUsage() | 187 PrintUsage() |
151 | 188 |
152 if not arguments or arguments[0] == "-": | 189 if not arguments or arguments[0] == "-": |
153 print "Reading native crash info from stdin" | 190 print "Reading native crash info from stdin" |
154 f = sys.stdin | 191 f = sys.stdin |
155 else: | 192 else: |
156 print "Searching for native crashes in %s" % arguments[0] | 193 print "Searching for native crashes in: " + os.path.realpath(arguments[0]) |
Andrew Hayden (chromium.org)
2015/10/29 07:44:35
Nit only: Just out of curiosity, why convert this
simonb (inactive)
2015/10/29 11:47:12
Matches the way the other trace-like messages are
| |
157 f = open(arguments[0], "r") | 194 f = open(arguments[0], "r") |
158 | 195 |
159 lines = f.readlines() | 196 lines = f.readlines() |
160 f.close() | 197 f.close() |
161 | 198 |
162 rootdir = None | 199 rootdir = None |
163 if zip_arg: | 200 if zip_arg: |
164 rootdir, symbol.SYMBOLS_DIR = UnzipSymbols(zip_arg) | 201 rootdir, symbol.SYMBOLS_DIR = UnzipSymbols(zip_arg) |
165 | 202 |
166 print "Reading Android symbols from", symbol.SYMBOLS_DIR | 203 if packed_relocation_adjustments == "unknown": |
167 print "Reading Chrome symbols from", symbol.CHROME_SYMBOLS_DIR | 204 version = stack_libs.GetTargetAndroidVersionNumber(lines) |
168 stack_core.ConvertTrace(lines, more_info) | 205 if version == None: |
206 print ("Unknown Android release, " | |
207 + "consider --[no-]packed-relocation-adjustments options") | |
208 packed_relocation_adjustments = False | |
209 elif version >= _ANDROID_M_MAJOR_VERSION: | |
210 packed_relocation_adjustments = False | |
211 else: | |
212 packed_relocation_adjustments = True | |
213 print ("Pre-M Android release detected, " | |
214 + "added --packed-relocation-adjustments option") | |
215 | |
216 if packed_relocation_adjustments: | |
217 print ("Reading Chrome APK library data from: " | |
218 + os.path.normpath(chrome_apk_dir)) | |
219 load_vaddrs = stack_libs.GetLoadVaddrs(chrome_apk_dir) | |
220 else: | |
221 load_vaddrs = {} | |
222 | |
223 print ("Reading Android symbols from: " | |
224 + os.path.normpath(symbol.SYMBOLS_DIR)) | |
225 print ("Reading Chrome symbols from: " | |
226 + os.path.normpath(symbol.CHROME_SYMBOLS_DIR)) | |
227 stack_core.ConvertTrace(lines, load_vaddrs, more_info) | |
169 | 228 |
170 if rootdir: | 229 if rootdir: |
171 # be a good citizen and clean up...os.rmdir and os.removedirs() don't work | 230 # be a good citizen and clean up...os.rmdir and os.removedirs() don't work |
172 cmd = "rm -rf \"%s\"" % rootdir | 231 cmd = "rm -rf \"%s\"" % rootdir |
173 print "\ncleaning up (%s)" % cmd | 232 print "\ncleaning up (%s)" % cmd |
174 os.system(cmd) | 233 os.system(cmd) |
175 | 234 |
176 if __name__ == "__main__": | 235 if __name__ == "__main__": |
177 sys.exit(main(sys.argv[1:])) | 236 sys.exit(main(sys.argv[1:])) |
178 | 237 |
179 # vi: ts=2 sw=2 | 238 # vi: ts=2 sw=2 |
OLD | NEW |