| 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 | |
| 22 import os | 21 import os |
| 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 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 51 print " --less-info" | 50 print " --less-info" |
| 52 print " Change the level of detail in the output." | 51 print " Change the level of detail in the output." |
| 53 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" |
| 54 print " be fully qualified with namespace/classname and have full" | 53 print " be fully qualified with namespace/classname and have full" |
| 55 print " argument information. Also, the 'stack data' section will be" | 54 print " argument information. Also, the 'stack data' section will be" |
| 56 print " printed." | 55 print " printed." |
| 57 print | 56 print |
| 58 print " --arch=arm|arm64|x86_64|x86|mips" | 57 print " --arch=arm|arm64|x86_64|x86|mips" |
| 59 print " the target architecture" | 58 print " the target architecture" |
| 60 print | 59 print |
| 61 print " --verbose" | |
| 62 print " enable extra logging, particularly for debugging failed symboliz
ation" | |
| 63 print | |
| 64 print " FILE should contain a stack trace in it somewhere" | 60 print " FILE should contain a stack trace in it somewhere" |
| 65 print " the tool will find that and re-print it with" | 61 print " the tool will find that and re-print it with" |
| 66 print " source files and line numbers. If you don't" | 62 print " source files and line numbers. If you don't" |
| 67 print " pass FILE, or if file is -, it reads from" | 63 print " pass FILE, or if file is -, it reads from" |
| 68 print " stdin." | 64 print " stdin." |
| 69 print | 65 print |
| 70 # pylint: enable-msg=C6310 | 66 # pylint: enable-msg=C6310 |
| 71 sys.exit(1) | 67 sys.exit(1) |
| 72 | 68 |
| 73 def UnzipSymbols(symbolfile, symdir=None): | 69 def UnzipSymbols(symbolfile, symdir=None): |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 android_symbols = glob.glob("%s/out/target/product/*/symbols" % symdir) | 101 android_symbols = glob.glob("%s/out/target/product/*/symbols" % symdir) |
| 106 if android_symbols: | 102 if android_symbols: |
| 107 return (symdir, android_symbols[0]) | 103 return (symdir, android_symbols[0]) |
| 108 else: | 104 else: |
| 109 # 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 |
| 110 # updated to point here. | 106 # updated to point here. |
| 111 symbol.CHROME_SYMBOLS_DIR = symdir | 107 symbol.CHROME_SYMBOLS_DIR = symdir |
| 112 return (symdir, symdir) | 108 return (symdir, symdir) |
| 113 | 109 |
| 114 | 110 |
| 115 def main(argv): | 111 def main(): |
| 116 try: | 112 try: |
| 117 options, arguments = getopt.getopt(argv, "", | 113 options, arguments = getopt.getopt(sys.argv[1:], "", |
| 118 ["more-info", | 114 ["more-info", |
| 119 "less-info", | 115 "less-info", |
| 120 "chrome-symbols-dir=", | 116 "chrome-symbols-dir=", |
| 121 "symbols-dir=", | 117 "symbols-dir=", |
| 122 "symbols-zip=", | 118 "symbols-zip=", |
| 123 "arch=", | 119 "arch=", |
| 124 "verbose", | |
| 125 "help"]) | 120 "help"]) |
| 126 except getopt.GetoptError, unused_error: | 121 except getopt.GetoptError, unused_error: |
| 127 PrintUsage() | 122 PrintUsage() |
| 128 | 123 |
| 129 zip_arg = None | 124 zip_arg = None |
| 130 more_info = False | 125 more_info = False |
| 131 for option, value in options: | 126 for option, value in options: |
| 132 if option == "--help": | 127 if option == "--help": |
| 133 PrintUsage() | 128 PrintUsage() |
| 134 elif option == "--symbols-dir": | 129 elif option == "--symbols-dir": |
| 135 symbol.SYMBOLS_DIR = os.path.expanduser(value) | 130 symbol.SYMBOLS_DIR = os.path.expanduser(value) |
| 136 elif option == "--symbols-zip": | 131 elif option == "--symbols-zip": |
| 137 zip_arg = os.path.expanduser(value) | 132 zip_arg = os.path.expanduser(value) |
| 138 elif option == "--arch": | 133 elif option == "--arch": |
| 139 symbol.ARCH = value | 134 symbol.ARCH = value |
| 140 elif option == "--chrome-symbols-dir": | 135 elif option == "--chrome-symbols-dir": |
| 141 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) |
| 142 elif option == "--more-info": | 137 elif option == "--more-info": |
| 143 more_info = True | 138 more_info = True |
| 144 elif option == "--less-info": | 139 elif option == "--less-info": |
| 145 more_info = False | 140 more_info = False |
| 146 elif option == "--verbose": | |
| 147 logging.basicConfig(level=logging.DEBUG) | |
| 148 | 141 |
| 149 if len(arguments) > 1: | 142 if len(arguments) > 1: |
| 150 PrintUsage() | 143 PrintUsage() |
| 151 | 144 |
| 152 if not arguments or arguments[0] == "-": | 145 if not arguments or arguments[0] == "-": |
| 153 print "Reading native crash info from stdin" | 146 print "Reading native crash info from stdin" |
| 154 f = sys.stdin | 147 f = sys.stdin |
| 155 else: | 148 else: |
| 156 print "Searching for native crashes in %s" % arguments[0] | 149 print "Searching for native crashes in %s" % arguments[0] |
| 157 f = open(arguments[0], "r") | 150 f = open(arguments[0], "r") |
| 158 | 151 |
| 159 lines = f.readlines() | 152 lines = f.readlines() |
| 160 f.close() | 153 f.close() |
| 161 | 154 |
| 162 rootdir = None | 155 rootdir = None |
| 163 if zip_arg: | 156 if zip_arg: |
| 164 rootdir, symbol.SYMBOLS_DIR = UnzipSymbols(zip_arg) | 157 rootdir, symbol.SYMBOLS_DIR = UnzipSymbols(zip_arg) |
| 165 | 158 |
| 166 print "Reading Android symbols from", symbol.SYMBOLS_DIR | 159 print "Reading Android symbols from", symbol.SYMBOLS_DIR |
| 167 print "Reading Chrome symbols from", symbol.CHROME_SYMBOLS_DIR | 160 print "Reading Chrome symbols from", symbol.CHROME_SYMBOLS_DIR |
| 168 stack_core.ConvertTrace(lines, more_info) | 161 stack_core.ConvertTrace(lines, more_info) |
| 169 | 162 |
| 170 if rootdir: | 163 if rootdir: |
| 171 # 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 |
| 172 cmd = "rm -rf \"%s\"" % rootdir | 165 cmd = "rm -rf \"%s\"" % rootdir |
| 173 print "\ncleaning up (%s)" % cmd | 166 print "\ncleaning up (%s)" % cmd |
| 174 os.system(cmd) | 167 os.system(cmd) |
| 175 | 168 |
| 176 if __name__ == "__main__": | 169 if __name__ == "__main__": |
| 177 sys.exit(main(sys.argv[1:])) | 170 main() |
| 178 | 171 |
| 179 # vi: ts=2 sw=2 | 172 # vi: ts=2 sw=2 |
| OLD | NEW |