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_dir = None |
| 153 packed_relocation_adjustments = "unknown" |
131 for option, value in options: | 154 for option, value in options: |
132 if option == "--help": | 155 if option == "--help": |
133 PrintUsage() | 156 PrintUsage() |
134 elif option == "--symbols-dir": | 157 elif option == "--symbols-dir": |
135 symbol.SYMBOLS_DIR = os.path.expanduser(value) | 158 symbol.SYMBOLS_DIR = os.path.expanduser(value) |
136 elif option == "--symbols-zip": | 159 elif option == "--symbols-zip": |
137 zip_arg = os.path.expanduser(value) | 160 zip_arg = os.path.expanduser(value) |
138 elif option == "--arch": | 161 elif option == "--arch": |
139 symbol.ARCH = value | 162 symbol.ARCH = value |
140 elif option == "--chrome-symbols-dir": | 163 elif option == "--chrome-symbols-dir": |
141 symbol.CHROME_SYMBOLS_DIR = os.path.join(symbol.CHROME_SRC, value) | 164 symbol.CHROME_SYMBOLS_DIR = os.path.join(symbol.CHROME_SRC, value) |
| 165 elif option == "--chrome-apk-dir": |
| 166 chrome_apk_dir = os.path.join(symbol.CHROME_SRC, value) |
| 167 elif option == "--packed-relocation-adjustments": |
| 168 packed_relocation_adjustments = True |
| 169 elif option == "--no-packed-relocation-adjustments": |
| 170 packed_relocation_adjustments = False |
142 elif option == "--more-info": | 171 elif option == "--more-info": |
143 more_info = True | 172 more_info = True |
144 elif option == "--less-info": | 173 elif option == "--less-info": |
145 more_info = False | 174 more_info = False |
146 elif option == "--verbose": | 175 elif option == "--verbose": |
147 logging.basicConfig(level=logging.DEBUG) | 176 logging.basicConfig(level=logging.DEBUG) |
148 | 177 |
| 178 if symbol.CHROME_SYMBOLS_DIR and not chrome_apk_dir: |
| 179 chrome_apk_dir = os.path.join(symbol.CHROME_SYMBOLS_DIR, |
| 180 '..', DEFAULT_APK_DIR) |
| 181 |
149 if len(arguments) > 1: | 182 if len(arguments) > 1: |
150 PrintUsage() | 183 PrintUsage() |
151 | 184 |
152 if not arguments or arguments[0] == "-": | 185 if not arguments or arguments[0] == "-": |
153 print "Reading native crash info from stdin" | 186 print "Reading native crash info from stdin" |
154 f = sys.stdin | 187 f = sys.stdin |
155 else: | 188 else: |
156 print "Searching for native crashes in %s" % arguments[0] | 189 print "Searching for native crashes in: " + os.path.realpath(arguments[0]) |
157 f = open(arguments[0], "r") | 190 f = open(arguments[0], "r") |
158 | 191 |
159 lines = f.readlines() | 192 lines = f.readlines() |
160 f.close() | 193 f.close() |
161 | 194 |
162 rootdir = None | 195 rootdir = None |
163 if zip_arg: | 196 if zip_arg: |
164 rootdir, symbol.SYMBOLS_DIR = UnzipSymbols(zip_arg) | 197 rootdir, symbol.SYMBOLS_DIR = UnzipSymbols(zip_arg) |
165 | 198 |
166 print "Reading Android symbols from", symbol.SYMBOLS_DIR | 199 if packed_relocation_adjustments == "unknown": |
| 200 if chrome_apk_dir: |
| 201 version = stack_libs.GetTargetAndroidVersionNumber(lines) |
| 202 if version == None: |
| 203 packed_relocation_adjustments = False |
| 204 print ("Unknown Android release, " |
| 205 + "consider --[no-]packed-relocation-adjustments options") |
| 206 elif version >= _ANDROID_M_MAJOR_VERSION: |
| 207 packed_relocation_adjustments = False |
| 208 else: |
| 209 packed_relocation_adjustments = True |
| 210 print ("Pre-M Android release detected, " |
| 211 + "added --packed-relocation-adjustments option") |
| 212 else: |
| 213 packed_relocation_adjustments = False |
| 214 |
| 215 if packed_relocation_adjustments and not chrome_apk_dir: |
| 216 packed_relocation_adjustments = False |
| 217 print ("No APK directory given or defaulted, " |
| 218 + "--packed-relocation-adjustments option ignored") |
| 219 |
| 220 if packed_relocation_adjustments: |
| 221 print ("Reading Chrome APK library data from: " |
| 222 + os.path.normpath(chrome_apk_dir)) |
| 223 load_vaddrs = stack_libs.GetLoadVaddrs(chrome_apk_dir) |
| 224 else: |
| 225 load_vaddrs = {} |
| 226 |
| 227 print ("Reading Android symbols from: " |
| 228 + os.path.normpath(symbol.SYMBOLS_DIR)) |
167 chrome_search_path = symbol.GetLibrarySearchPaths() | 229 chrome_search_path = symbol.GetLibrarySearchPaths() |
168 print "Searching for Chrome symbols from within", ':'.join(chrome_search_path) | 230 print ("Searching for Chrome symbols from within: " |
169 stack_core.ConvertTrace(lines, more_info) | 231 + ':'.join((os.path.normpath(d) for d in chrome_search_path))) |
| 232 stack_core.ConvertTrace(lines, load_vaddrs, more_info) |
170 | 233 |
171 if rootdir: | 234 if rootdir: |
172 # be a good citizen and clean up...os.rmdir and os.removedirs() don't work | 235 # be a good citizen and clean up...os.rmdir and os.removedirs() don't work |
173 cmd = "rm -rf \"%s\"" % rootdir | 236 cmd = "rm -rf \"%s\"" % rootdir |
174 print "\ncleaning up (%s)" % cmd | 237 print "\ncleaning up (%s)" % cmd |
175 os.system(cmd) | 238 os.system(cmd) |
176 | 239 |
177 if __name__ == "__main__": | 240 if __name__ == "__main__": |
178 sys.exit(main(sys.argv[1:])) | 241 sys.exit(main(sys.argv[1:])) |
179 | 242 |
180 # vi: ts=2 sw=2 | 243 # vi: ts=2 sw=2 |
OLD | NEW |