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

Greg Clayton gclayton at apple.com
Tue Sep 18 18:59:34 PDT 2012


Author: gclayton
Date: Tue Sep 18 20:59:34 2012
New Revision: 164192

URL: http://llvm.org/viewvc/llvm-project?rev=164192&view=rev
Log:
Added auto LLDB import to the crashlog script.


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=164192&r1=164191&r2=164192&view=diff
==============================================================================
--- lldb/trunk/examples/python/crashlog.py (original)
+++ lldb/trunk/examples/python/crashlog.py Tue Sep 18 20:59:34 2012
@@ -26,7 +26,6 @@
 #   PYTHONPATH=/path/to/LLDB.framework/Resources/Python ./crashlog.py ~/Library/Logs/DiagnosticReports/a.crash
 #----------------------------------------------------------------------
 
-import lldb
 import commands
 import cmd
 import datetime
@@ -42,6 +41,38 @@
 import sys
 import time
 import uuid
+
+try: 
+    # Just try for LLDB in case PYTHONPATH is already correctly setup
+    import lldb
+except ImportError:
+    lldb_python_dirs = list()
+    # lldb is not in the PYTHONPATH, try some defaults for the current platform
+    platform_system = platform.system()
+    if platform_system == 'Darwin':
+        # On Darwin, try the currently selected Xcode directory
+        xcode_dir = commands.getoutput("xcode-select --print-path")
+        if xcode_dir:
+            lldb_python_dirs.append(os.path.realpath(xcode_dir + '/../SharedFrameworks/LLDB.framework/Resources/Python'))
+            lldb_python_dirs.append(xcode_dir + '/Library/PrivateFrameworks/LLDB.framework/Resources/Python')
+        lldb_python_dirs.append('/System/Library/PrivateFrameworks/LLDB.framework/Resources/Python')
+    success = False
+    for lldb_python_dir in lldb_python_dirs:
+        if os.path.exists(lldb_python_dir):
+            if not (sys.path.__contains__(lldb_python_dir)):
+                sys.path.append(lldb_python_dir)
+                try: 
+                    import lldb
+                except ImportError:
+                    pass
+                else:
+                    print 'imported lldb from: "%s"' % (lldb_python_dir)
+                    success = True
+                    break
+    if not success:
+        print "error: couldn't locate the 'lldb' module, please set PYTHONPATH correctly"
+        sys.exit(1)
+
 from lldb.utils import symbolication
 
 PARSE_MODE_NORMAL = 0
@@ -740,7 +771,6 @@
                 SymbolicateCrashLog (crash_log, options)
 if __name__ == '__main__':
     # Create a new debugger instance
-    print 'main'
     lldb.debugger = lldb.SBDebugger.Create()
     SymbolicateCrashLogs (sys.argv[1:])
 elif getattr(lldb, 'debugger', None):





More information about the lldb-commits mailing list