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>
This commit is contained in:
hjk
2015-02-13 10:02:35 +01:00
parent a7fce39103
commit a081fee8f5
3 changed files with 25 additions and 35 deletions

View File

@@ -81,6 +81,22 @@ SeparateLatin1StringFormat, \
SeparateUtf8StringFormat \ SeparateUtf8StringFormat \
= range(100, 112) = 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. # matplot based display for array-like structures.
# #

View File

@@ -28,18 +28,15 @@
# #
############################################################################# #############################################################################
import atexit
import inspect import inspect
import os import os
import platform import platform
import re import re
import sys import sys
import subprocess
import threading import threading
import lldb import lldb
currentDir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) sys.path.insert(1, os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))))
sys.path.insert(1, currentDir)
from dumper import * from dumper import *
@@ -51,8 +48,6 @@ from dumper import *
qqWatchpointOffset = 10000 qqWatchpointOffset = 10000
lldb.theDumper = None
def warn(message): def warn(message):
print('\n\nWARNING="%s",\n' % message.encode("latin1").replace('"', "'")) print('\n\nWARNING="%s",\n' % message.encode("latin1").replace('"', "'"))
@@ -66,22 +61,6 @@ def fileName(file):
return str(file) if file.IsValid() else '' 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): def check(exp):
if not exp: if not exp:
raise RuntimeError("Check failed") raise RuntimeError("Check failed")
@@ -187,8 +166,6 @@ class Dumper(DumperBase):
def __init__(self): def __init__(self):
DumperBase.__init__(self) DumperBase.__init__(self)
lldb.theDumper = self
self.outputLock = threading.Lock() self.outputLock = threading.Lock()
self.debugger = lldb.SBDebugger.Create() self.debugger = lldb.SBDebugger.Create()
#self.debugger.SetLoggingCallback(loggingCallback) #self.debugger.SetLoggingCallback(loggingCallback)
@@ -255,6 +232,9 @@ class Dumper(DumperBase):
self.qmlBreakpointResolvers = {} self.qmlBreakpointResolvers = {}
self.qmlTriggeredBreakpoint = None self.qmlTriggeredBreakpoint = None
self.report('lldbversion=\"%s\"' % lldb.SBDebugger.GetVersionString())
self.reportState("enginesetupok")
def enterSubItem(self, item): def enterSubItem(self, item):
if isinstance(item.name, lldb.SBValue): if isinstance(item.name, lldb.SBValue):
# Avoid $$__synth__ suffix on Mac. # Avoid $$__synth__ suffix on Mac.
@@ -1719,7 +1699,6 @@ class Dumper(DumperBase):
# Used in dumper auto test. # Used in dumper auto test.
# Usage: python lldbbridge.py /path/to/testbinary comma-separated-inames
class Tester(Dumper): class Tester(Dumper):
def __init__(self, binary, expandedINames): def __init__(self, binary, expandedINames):
Dumper.__init__(self) Dumper.__init__(self)

View File

@@ -118,7 +118,6 @@ LldbEngine::~LldbEngine()
m_stubProc.disconnect(); // Avoid spurious state transitions from late exiting stub m_stubProc.disconnect(); // Avoid spurious state transitions from late exiting stub
} }
void LldbEngine::executeDebuggerCommand(const QString &command, DebuggerLanguages) void LldbEngine::executeDebuggerCommand(const QString &command, DebuggerLanguages)
{ {
DebuggerCommand cmd("executeDebuggerCommand"); DebuggerCommand cmd("executeDebuggerCommand");
@@ -133,7 +132,7 @@ void LldbEngine::runCommand(const DebuggerCommand &command)
QByteArray token = QByteArray::number(m_lastToken); QByteArray token = QByteArray::number(m_lastToken);
QByteArray cmd = command.function + "({" + command.args + "})"; QByteArray cmd = command.function + "({" + command.args + "})";
showMessage(_(token + cmd + '\n'), LogInput); showMessage(_(token + cmd + '\n'), LogInput);
m_lldbProc.write("sc db." + cmd + "\n"); m_lldbProc.write("script theDumper." + cmd + "\n");
} }
void LldbEngine::debugLastCommand() void LldbEngine::debugLastCommand()
@@ -269,14 +268,10 @@ void LldbEngine::startLldb()
const QByteArray dumperSourcePath = const QByteArray dumperSourcePath =
ICore::resourcePath().toLocal8Bit() + "/debugger/"; ICore::resourcePath().toLocal8Bit() + "/debugger/";
m_lldbProc.write("sc sys.path.insert(1, '" + dumperSourcePath + "')\n"); m_lldbProc.write("script sys.path.insert(1, '" + dumperSourcePath + "')\n");
m_lldbProc.write("sc from lldbbridge import *\n"); m_lldbProc.write("script from lldbbridge import *\n");
m_lldbProc.write("sc print(dir())\n"); m_lldbProc.write("script print(dir())\n");
m_lldbProc.write("sc db = Dumper()\n"); m_lldbProc.write("script theDumper = Dumper()\n"); // This triggers reportState("enginesetupok")
m_lldbProc.write("sc db.report('lldbversion=\"%s\"' % lldb.SBDebugger.GetVersionString())\n");
showMessage(_("ENGINE SUCCESSFULLY STARTED"));
notifyEngineSetupOk();
} }
void LldbEngine::setupInferior() void LldbEngine::setupInferior()