From ac17b73c20cd83798196f2ccb1eca8ad5d27cfd2 Mon Sep 17 00:00:00 2001
From: Fawzi Mohamed <fawzi.mohamed@digia.com>
Date: Thu, 31 Oct 2013 10:06:14 +0100
Subject: [PATCH] lldb: allow lldbbridge.py to be directly imported in python

Change-Id: Ib0bcb4dd708e89cebe12407a3f8e375c79664a74
Reviewed-by: Eike Ziller <eike.ziller@digia.com>
---
 share/qtcreator/debugger/lldbbridge.py | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/share/qtcreator/debugger/lldbbridge.py b/share/qtcreator/debugger/lldbbridge.py
index 765af26686a..96e1a9cd9d2 100644
--- a/share/qtcreator/debugger/lldbbridge.py
+++ b/share/qtcreator/debugger/lldbbridge.py
@@ -48,12 +48,13 @@ from misctypes import *
 from boosttypes import *
 from creatortypes import *
 
-
-proc = subprocess.Popen(args=[sys.argv[1], '-P'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+lldbCmd = 'lldb'
+if len(sys.argv) > 1:
+    lldbCmd = sys.argv[1]
+proc = subprocess.Popen(args=[lldbCmd, '-P'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
 (path, error) = proc.communicate()
-
 if error.startswith('lldb: invalid option -- P'):
-    sys.stdout.write('msg=\'Could not run "%s -P". Trying to find lldb.so from Xcode.\'\n' % sys.argv[1])
+    sys.stdout.write('msg=\'Could not run "%s -P". Trying to find lldb.so from Xcode.\'\n' % lldbCmd)
     proc = subprocess.Popen(args=['xcode-select', '--print-path'],
         stdout=subprocess.PIPE, stderr=subprocess.PIPE)
     (path, error) = proc.communicate()
@@ -65,7 +66,6 @@ if error.startswith('lldb: invalid option -- P'):
         path = path.strip() + '/../SharedFrameworks/LLDB.framework/Versions/A/Resources/Python/'
         sys.stdout.write('msg=\'Using fallback at %s\'\n' % path)
 
-#sys.path.append(path)
 sys.path.insert(1, path.strip())
 
 import lldb
@@ -1729,9 +1729,9 @@ def testit():
     db.reportVariables()
     #db.report("DUMPER=%s" % qqDumpers)
 
-
-if len(sys.argv) > 2:
-    testit()
-else:
-    doit()
+if __name__ == "__main__":
+    if len(sys.argv) > 2:
+        testit()
+    else:
+        doit()
 
-- 
GitLab