[Lldb-commits] [lldb] r148623 - /lldb/trunk/examples/python/crashlog.py

Greg Clayton gclayton at apple.com
Fri Jan 20 20:26:24 PST 2012


Author: gclayton
Date: Fri Jan 20 22:26:24 2012
New Revision: 148623

URL: http://llvm.org/viewvc/llvm-project?rev=148623&view=rev
Log:
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.


Modified:
    lldb/trunk/examples/python/crashlog.py

Modified: lldb/trunk/examples/python/crashlog.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/examples/python/crashlog.py?rev=148623&r1=148622&r2=148623&view=diff
==============================================================================
--- lldb/trunk/examples/python/crashlog.py (original)
+++ lldb/trunk/examples/python/crashlog.py Fri Jan 20 22:26:24 2012
@@ -33,6 +33,7 @@
 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 @@
         
     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 @@
         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 @@
     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 @@
     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 @@
     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:





More information about the lldb-commits mailing list