diff options
author | Greg Clayton <gclayton@apple.com> | 2012-01-21 04:26:24 +0000 |
---|---|---|
committer | Greg Clayton <gclayton@apple.com> | 2012-01-21 04:26:24 +0000 |
commit | 53b43b07983fd2c6cdd7014cdf394968b5a9928d (patch) | |
tree | 98017e447173b6f51462c01e64a8c415c7e406ae /lldb/examples/python | |
parent | 64a2beca52163bce53cae3967d3625e81d4f2a80 (diff) | |
download | bcm5719-llvm-53b43b07983fd2c6cdd7014cdf394968b5a9928d.tar.gz bcm5719-llvm-53b43b07983fd2c6cdd7014cdf394968b5a9928d.zip |
Use the "shlex" module to parse the command line that was passed down into
python so that single and double quotes and other standard shell like argument
parsing happens as expected before passing stuff along to option parsing.
Also handle exceptions so that we don't accidentally exit lldb if an uncaught
exception occurs.
llvm-svn: 148623
Diffstat (limited to 'lldb/examples/python')
-rwxr-xr-x | lldb/examples/python/crashlog.py | 31 |
1 files changed, 25 insertions, 6 deletions
diff --git a/lldb/examples/python/crashlog.py b/lldb/examples/python/crashlog.py index bab338c22c9..329b1c3a34e 100755 --- a/lldb/examples/python/crashlog.py +++ b/lldb/examples/python/crashlog.py @@ -33,6 +33,7 @@ import os import plistlib #import pprint # pp = pprint.PrettyPrinter(indent=4); pp.pprint(command_args) import re +import shlex import sys import time import uuid @@ -245,7 +246,7 @@ class CrashLog: def __init__(self, path): """CrashLog constructor that take a path to a darwin crash log file""" - self.path = path; + self.path = os.path.expanduser(path); self.info_lines = list() self.system_profile = list() self.threads = list() @@ -253,8 +254,14 @@ class CrashLog: self.idents = list() # A list of the required identifiers for doing all stack backtraces self.crashed_thread_idx = -1 self.version = -1 + self.error = None # With possible initial component of ~ or ~user replaced by that user's home directory. - f = open(os.path.expanduser(self.path)) + try: + f = open(self.path) + except IOError: + self.error = 'error: cannot open "%s"' % self.path + return + self.file_lines = f.read().splitlines() parse_mode = PARSE_MODE_NORMAL thread = None @@ -475,10 +482,12 @@ def usage(): sys.exit(0) def Symbolicate(debugger, command, result, dict): - SymbolicateCrashLog (command.split()) - + try: + SymbolicateCrashLog (shlex.split(command)) + except: + result.PutCString ("error: python exception %s" % sys.exc_info()[0]) + def SymbolicateCrashLog(command_args): - print 'command_args = %s' % command_args usage = "usage: %prog [options] <FILE> [FILE ...]" description='''Symbolicate one or more darwin crash log files to provide source file and line information, inlined stack frames back to the concrete functions, and disassemble the location of the crash @@ -497,9 +506,16 @@ be disassembled and lookups can be performed using the addresses found in the cr parser.add_option('--debug-delay', type='int', dest='debug_delay', metavar='NSEC', help='pause for NSEC seconds for debugger', default=0) parser.add_option('--crashed-only', action='store_true', dest='crashed_only', help='only symbolicate the crashed thread', default=False) loaded_addresses = False - (options, args) = parser.parse_args(command_args) + try: + (options, args) = parser.parse_args(command_args) + except: + return + if options.verbose: + print 'command_args = %s' % command_args print 'options', options + print 'args', args + if options.debug_delay > 0: print "Waiting %u seconds for debugger to attach..." % options.debug_delay time.sleep(options.debug_delay) @@ -507,6 +523,9 @@ be disassembled and lookups can be performed using the addresses found in the cr if args: for crash_log_file in args: crash_log = CrashLog(crash_log_file) + if crash_log.error: + print crash_log.error + return if options.verbose: crash_log.dump() if not crash_log.images: |