Debugger: Move LLDB state reporting to separate function

Change-Id: I4e250173efc1c0df002d2ce94f7e8df57339544b
Reviewed-by: Christian Stenger <christian.stenger@digia.com>
This commit is contained in:
hjk
2014-03-19 12:12:24 +01:00
parent 05d7dd1bb9
commit 358500e7fc

View File

@@ -667,24 +667,24 @@ class Dumper(DumperBase):
attachInfo = lldb.SBAttachInfo(self.attachPid_) attachInfo = lldb.SBAttachInfo(self.attachPid_)
self.process = self.target.Attach(attachInfo, error) self.process = self.target.Attach(attachInfo, error)
if not error.Success(): if not error.Success():
self.report('state="inferiorrunfailed"') self.reportState("inferiorrunfailed")
return return
self.report('pid="%s"' % self.process.GetProcessID()) self.report('pid="%s"' % self.process.GetProcessID())
# even if it stops it seems that lldb assumes it is running and later detects that # Even if it stops it seems that LLDB assumes it is running
# it did stop after all, so it is be better to mirror that and wait for the spontaneous # and later detects that it did stop after all, so it is be
# stop # better to mirror that and wait for the spontaneous stop.
self.report('state="enginerunandinferiorrunok"') self.reportState("enginerunandinferiorrunok")
elif len(self.remoteChannel_) > 0: elif len(self.remoteChannel_) > 0:
self.process = self.target.ConnectRemote( self.process = self.target.ConnectRemote(
self.debugger.GetListener(), self.debugger.GetListener(),
self.remoteChannel_, None, error) self.remoteChannel_, None, error)
if not error.Success(): if not error.Success():
self.report('state="inferiorrunfailed"') self.reportState("inferiorrunfailed")
return return
# even if it stops it seems that lldb assumes it is running and later detects that # Even if it stops it seems that LLDB assumes it is running
# it did stop after all, so it is be better to mirror that and wait for the spontaneous # and later detects that it did stop after all, so it is be
# stop # better to mirror that and wait for the spontaneous stop.
self.report('state="enginerunandinferiorrunok"') self.reportState("enginerunandinferiorrunok")
else: else:
launchInfo = lldb.SBLaunchInfo(self.processArgs_) launchInfo = lldb.SBLaunchInfo(self.processArgs_)
launchInfo.SetWorkingDirectory(os.getcwd()) launchInfo.SetWorkingDirectory(os.getcwd())
@@ -695,10 +695,10 @@ class Dumper(DumperBase):
self.process = self.target.Launch(launchInfo, error) self.process = self.target.Launch(launchInfo, error)
if not error.Success(): if not error.Success():
self.reportError(error) self.reportError(error)
self.report('state="enginerunfailed"') self.reportState("enginerunfailed")
return return
self.report('pid="%s"' % self.process.GetProcessID()) self.report('pid="%s"' % self.process.GetProcessID())
self.report('state="enginerunandinferiorrunok"') self.reportState("enginerunandinferiorrunok")
event = lldb.SBEvent() event = lldb.SBEvent()
while True: while True:
@@ -732,7 +732,8 @@ class Dumper(DumperBase):
frame = thread.GetSelectedFrame() frame = thread.GetSelectedFrame()
file = fileName(frame.line_entry.file) file = fileName(frame.line_entry.file)
line = frame.line_entry.line line = frame.line_entry.line
self.report('location={file="%s",line="%s",addr="%s"}' % (file, line, frame.pc)) self.report('location={file="%s",line="%s",addr="%s"}'
% (file, line, frame.pc))
def firstStoppedThread(self): def firstStoppedThread(self):
for i in xrange(0, self.process.GetNumThreads()): for i in xrange(0, self.process.GetNumThreads()):
@@ -1202,7 +1203,7 @@ class Dumper(DumperBase):
self.reportError(error) self.reportError(error)
def quitDebugger(self, _ = None): def quitDebugger(self, _ = None):
self.report('state="inferiorshutdownrequested"') self.reportState("inferiorshutdownrequested")
self.process.Kill() self.process.Kill()
def handleEvent(self, event): def handleEvent(self, event):
@@ -1219,22 +1220,22 @@ class Dumper(DumperBase):
self.eventState = state self.eventState = state
if state == lldb.eStateExited: if state == lldb.eStateExited:
if self.isShuttingDown_: if self.isShuttingDown_:
self.report('state="inferiorshutdownok"') self.reportState("inferiorshutdownok")
else: else:
self.report('state="inferiorexited"') self.reportState("inferiorexited")
self.report('exited={status="%s",desc="%s"}' self.report('exited={status="%s",desc="%s"}'
% (self.process.GetExitStatus(), self.process.GetExitDescription())) % (self.process.GetExitStatus(), self.process.GetExitDescription()))
elif state == lldb.eStateStopped: elif state == lldb.eStateStopped:
if self.isInterrupting_: if self.isInterrupting_:
self.isInterrupting_ = False self.isInterrupting_ = False
self.report('state="inferiorstopok"') self.reportState("inferiorstopok")
elif self.ignoreStops > 0: elif self.ignoreStops > 0:
self.ignoreStops -= 1 self.ignoreStops -= 1
self.process.Continue() self.process.Continue()
else: else:
self.report('state="stopped"') self.reportState("stopped")
else: else:
self.report('state="%s"' % stateNames[state]) self.reportState(stateNames[state])
if type == lldb.SBProcess.eBroadcastBitStateChanged: if type == lldb.SBProcess.eBroadcastBitStateChanged:
state = self.process.GetState() state = self.process.GetState()
if state == lldb.eStateStopped: if state == lldb.eStateStopped:
@@ -1260,6 +1261,9 @@ class Dumper(DumperBase):
elif type == lldb.SBProcess.eBroadcastBitProfileData: elif type == lldb.SBProcess.eBroadcastBitProfileData:
pass pass
def reportState(self, state):
self.report('state="%s"' % state)
def describeBreakpoint(self, bp): def describeBreakpoint(self, bp):
isWatch = isinstance(bp, lldb.SBWatchpoint) isWatch = isinstance(bp, lldb.SBWatchpoint)
if isWatch: if isWatch:
@@ -1457,7 +1461,7 @@ class Dumper(DumperBase):
self.process.Kill() self.process.Kill()
def quit(self, _ = None): def quit(self, _ = None):
self.report('state="engineshutdownok"') self.reportState("engineshutdownok")
self.process.Kill() self.process.Kill()
def executeStepI(self, _ = None): def executeStepI(self, _ = None):
@@ -1476,8 +1480,8 @@ class Dumper(DumperBase):
line = int(args['line']) line = int(args['line'])
error = self.currentThread().StepOverUntil(frame, lldb.SBFileSpec(file), line) error = self.currentThread().StepOverUntil(frame, lldb.SBFileSpec(file), line)
if error.GetType(): if error.GetType():
self.report('state="running"') self.reportState("running")
self.report('state="stopped"') self.reportState("stopped")
self.reportError(error) self.reportError(error)
self.reportLocation() self.reportLocation()
else: else:
@@ -1485,7 +1489,7 @@ class Dumper(DumperBase):
def executeJumpToLocation(self, args): def executeJumpToLocation(self, args):
frame = self.currentFrame() frame = self.currentFrame()
self.report('state="stopped"') self.reportSate("stopped")
if not frame: if not frame:
self.reportStatus("No frame available.") self.reportStatus("No frame available.")
self.reportLocation() self.reportLocation()
@@ -1676,7 +1680,7 @@ def doit():
db = Dumper() db = Dumper()
db.report('lldbversion="%s"' % lldb.SBDebugger.GetVersionString()) db.report('lldbversion="%s"' % lldb.SBDebugger.GetVersionString())
db.report('state="enginesetupok"') db.reportState("enginesetupok")
line = sys.stdin.readline() line = sys.stdin.readline()
while line: while line: