From a081fee8f5cc63bc49f6a62244c758d65e41c721 Mon Sep 17 00:00:00 2001
From: hjk <hjk@theqtcompany.com>
Date: Fri, 13 Feb 2015 10:02:35 +0100
Subject: [PATCH] Debugger: Cleanup lldbbridge.py

Move reusable Breakpoint enum to base, use 'theDumper' uniformly
across backends as name for the Dumper singleton. Signal
engine setup only if the Dumper successfully initializes.

Change-Id: If1b6be9d054f249d0d46061e4949cbecf4fd09cb
Reviewed-by: Christian Stenger <christian.stenger@theqtcompany.com>
---
 share/qtcreator/debugger/dumper.py       | 16 +++++++++++++
 share/qtcreator/debugger/lldbbridge.py   | 29 ++++--------------------
 src/plugins/debugger/lldb/lldbengine.cpp | 15 ++++--------
 3 files changed, 25 insertions(+), 35 deletions(-)

diff --git a/share/qtcreator/debugger/dumper.py b/share/qtcreator/debugger/dumper.py
index 3a37c4a9242..49d0b7537ef 100644
--- a/share/qtcreator/debugger/dumper.py
+++ b/share/qtcreator/debugger/dumper.py
@@ -81,6 +81,22 @@ SeparateLatin1StringFormat, \
 SeparateUtf8StringFormat \
     = range(100, 112)
 
+# Breakpoints. Keep synchronized with BreakpointType in breakpoint.h
+UnknownType, \
+BreakpointByFileAndLine, \
+BreakpointByFunction, \
+BreakpointByAddress, \
+BreakpointAtThrow, \
+BreakpointAtCatch, \
+BreakpointAtMain, \
+BreakpointAtFork, \
+BreakpointAtExec, \
+BreakpointAtSysCall, \
+WatchpointAtAddress, \
+WatchpointAtExpression, \
+BreakpointOnQmlSignalEmit, \
+BreakpointAtJavaScriptThrow, \
+    = range(0, 14)
 #
 # matplot based display for array-like structures.
 #
diff --git a/share/qtcreator/debugger/lldbbridge.py b/share/qtcreator/debugger/lldbbridge.py
index 47084e512c9..a986707f0f9 100644
--- a/share/qtcreator/debugger/lldbbridge.py
+++ b/share/qtcreator/debugger/lldbbridge.py
@@ -28,18 +28,15 @@
 #
 #############################################################################
 
-import atexit
 import inspect
 import os
 import platform
 import re
 import sys
-import subprocess
 import threading
 import lldb
 
-currentDir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
-sys.path.insert(1, currentDir)
+sys.path.insert(1, os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))))
 
 from dumper import *
 
@@ -51,8 +48,6 @@ from dumper import *
 
 qqWatchpointOffset = 10000
 
-lldb.theDumper = None
-
 def warn(message):
     print('\n\nWARNING="%s",\n' % message.encode("latin1").replace('"', "'"))
 
@@ -66,22 +61,6 @@ def fileName(file):
     return str(file) if file.IsValid() else ''
 
 
-# Breakpoints. Keep synchronized with BreakpointType in breakpoint.h
-UnknownType = 0
-BreakpointByFileAndLine = 1
-BreakpointByFunction = 2
-BreakpointByAddress = 3
-BreakpointAtThrow = 4
-BreakpointAtCatch = 5
-BreakpointAtMain = 6
-BreakpointAtFork = 7
-BreakpointAtExec = 8
-BreakpointAtSysCall = 9
-WatchpointAtAddress = 10
-WatchpointAtExpression = 11
-BreakpointOnQmlSignalEmit = 12
-BreakpointAtJavaScriptThrow = 13
-
 def check(exp):
     if not exp:
         raise RuntimeError("Check failed")
@@ -187,8 +166,6 @@ class Dumper(DumperBase):
     def __init__(self):
         DumperBase.__init__(self)
 
-        lldb.theDumper = self
-
         self.outputLock = threading.Lock()
         self.debugger = lldb.SBDebugger.Create()
         #self.debugger.SetLoggingCallback(loggingCallback)
@@ -255,6 +232,9 @@ class Dumper(DumperBase):
         self.qmlBreakpointResolvers = {}
         self.qmlTriggeredBreakpoint = None
 
+        self.report('lldbversion=\"%s\"' % lldb.SBDebugger.GetVersionString())
+        self.reportState("enginesetupok")
+
     def enterSubItem(self, item):
         if isinstance(item.name, lldb.SBValue):
             # Avoid $$__synth__ suffix on Mac.
@@ -1719,7 +1699,6 @@ class Dumper(DumperBase):
 
 
 # Used in dumper auto test.
-# Usage: python lldbbridge.py /path/to/testbinary comma-separated-inames
 class Tester(Dumper):
     def __init__(self, binary, expandedINames):
         Dumper.__init__(self)
diff --git a/src/plugins/debugger/lldb/lldbengine.cpp b/src/plugins/debugger/lldb/lldbengine.cpp
index 359403bfa4d..01c5d9651a3 100644
--- a/src/plugins/debugger/lldb/lldbengine.cpp
+++ b/src/plugins/debugger/lldb/lldbengine.cpp
@@ -118,7 +118,6 @@ LldbEngine::~LldbEngine()
     m_stubProc.disconnect(); // Avoid spurious state transitions from late exiting stub
 }
 
-
 void LldbEngine::executeDebuggerCommand(const QString &command, DebuggerLanguages)
 {
     DebuggerCommand cmd("executeDebuggerCommand");
@@ -133,7 +132,7 @@ void LldbEngine::runCommand(const DebuggerCommand &command)
     QByteArray token = QByteArray::number(m_lastToken);
     QByteArray cmd  = command.function + "({" + command.args + "})";
     showMessage(_(token + cmd + '\n'), LogInput);
-    m_lldbProc.write("sc db." + cmd + "\n");
+    m_lldbProc.write("script theDumper." + cmd + "\n");
 }
 
 void LldbEngine::debugLastCommand()
@@ -269,14 +268,10 @@ void LldbEngine::startLldb()
     const QByteArray dumperSourcePath =
         ICore::resourcePath().toLocal8Bit() + "/debugger/";
 
-    m_lldbProc.write("sc sys.path.insert(1, '" + dumperSourcePath + "')\n");
-    m_lldbProc.write("sc from lldbbridge import *\n");
-    m_lldbProc.write("sc print(dir())\n");
-    m_lldbProc.write("sc db = Dumper()\n");
-    m_lldbProc.write("sc db.report('lldbversion=\"%s\"' % lldb.SBDebugger.GetVersionString())\n");
-
-    showMessage(_("ENGINE SUCCESSFULLY STARTED"));
-    notifyEngineSetupOk();
+    m_lldbProc.write("script sys.path.insert(1, '" + dumperSourcePath + "')\n");
+    m_lldbProc.write("script from lldbbridge import *\n");
+    m_lldbProc.write("script print(dir())\n");
+    m_lldbProc.write("script theDumper = Dumper()\n"); // This triggers reportState("enginesetupok")
 }
 
 void LldbEngine::setupInferior()
-- 
GitLab