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