Commit 61bf74be authored by hjk's avatar hjk

Debugger: Work on LLDB event handling

Change-Id: Ie97c628ece272249c23aab6d5438555c051f5aa8
Reviewed-by: default avatarhjk <hjk121@nokiamail.com>
parent cccc39cc
......@@ -325,7 +325,7 @@ lldb.SBType.unqualified = lambda self: self.GetUnqualifiedType()
lldb.SBType.pointer = lambda self: self.GetPointerType()
lldb.SBType.code = lambda self: self.GetTypeClass()
lldb.SBType.sizeof = property(lambda self: self.GetByteSize())
lldb.SBType.strip_typedefs = lambda self: self
lldb.SBType.strip_typedefs = lambda self: self.GetCanonicalType()
def simpleEncoding(typeobj):
code = typeobj.GetTypeClass()
......@@ -504,6 +504,7 @@ class Dumper:
self.useLldbDumpers = False
self.ns = ""
self.autoDerefPointers = True
self.useLoop = True
self.currentIName = None
self.currentValuePriority = -100
......@@ -517,6 +518,7 @@ class Dumper:
self.currentChildType = None
self.currentChildNumChild = None
self.executable_ = None
self.charType_ = None
self.intType_ = None
self.sizetType_ = None
......@@ -564,12 +566,12 @@ class Dumper:
def intType(self):
if self.intType_ is None:
self.intType_ = self.target.GetModuleAtIndex(0).FindFirstType('int')
self.intType_ = self.target.FindFirstType('int')
return self.intType_
def charType(self):
if self.charType_ is None:
self.charType_ = self.target.GetModuleAtIndex(0).FindFirstType('char')
self.charType_ = self.target.FindFirstType('char')
return self.charType_
def charPtrType(self):
......@@ -578,9 +580,11 @@ class Dumper:
return self.charPtrType_
def voidPtrType(self):
return None
return self.charPtrType() # FIXME
def voidPtrSize(self):
return None
return self.charPtrType().GetByteSize()
def sizetType(self):
......@@ -676,43 +680,75 @@ class Dumper:
return xrange(min(self.currentMaxNumChild, self.currentNumChild))
def lookupType(self, name):
#warn("LOOKUP: %s" % self.target.GetModuleAtIndex(0).FindFirstType(name))
return self.target.GetModuleAtIndex(0).FindFirstType(name)
#warn("LOOKUP: %s" % self.target.FindFirstType(name))
return self.target.FindFirstType(name)
def setupInferior(self, args):
fileName = args['executable']
executable = args['executable']
self.executable_ = executable
error = lldb.SBError()
self.target = self.debugger.CreateTarget(fileName, None, None, True, error)
self.target = self.debugger.CreateTarget(executable, None, None, True, error)
if self.target.IsValid():
self.report('state="inferiorsetupok",msg="%s",exe="%s"' % (error, fileName))
self.report('state="inferiorsetupok",msg="%s",exe="%s"' % (error, executable))
else:
self.report('state="inferiorsetupfailed",msg="%s",exe="%s"' % (error, fileName))
self.report('state="inferiorsetupfailed",msg="%s",exe="%s"' % (error, executable))
self.importDumpers()
if False:
self.process = self.target.LaunchSimple(None, None, os.getcwd())
self.broadcaster = self.process.GetBroadcaster()
self.listener = lldb.SBListener('my listener')
rc = self.broadcaster.AddListener(self.listener, 15)
warn("ADD LISTENER: %s" % rc)
if True:
self.listener = self.target.GetDebugger().GetListener()
self.process = self.target.Launch(self.listener, None, None,
None, None, None,
None, 0, True, error)
self.broadcaster = self.process.GetBroadcaster()
rc = self.broadcaster.AddListener(self.listener, 15)
warn("ADD LISTENER: %s" % rc)
#self.process = self.target.Launch(self.listener, None, None,
# None, None, None,
# os.getcwd(),
# lldb.eLaunchFlagExec
# + lldb.eLaunchFlagDebug
# #+ lldb.eLaunchFlagDebug
# #+ lldb.eLaunchFlagStopAtEntry
# #+ lldb.eLaunchFlagDisableSTDIO
# #+ lldb.eLaunchFlagLaunchInSeparateProcessGroup
# , False, error)
#self.reportError(error)
warn("STATE AFTER LAUNCH: %s" % self.process.GetState())
warn("STATE AFTER LAUNCH: %s" % stateNames[self.process.GetState()])
def runEngine(self, _):
error = lldb.SBError()
#launchInfo = lldb.SBLaunchInfo(["-s"])
#self.process = self.target.Launch(self.listener, None, None,
# None, '/tmp/stdout.txt', None,
# None, None, None,
# None, 0, True, error)
self.listener = lldb.SBListener("event_Listener")
self.process = self.target.Launch(self.listener, None, None,
None, None, None,
os.getcwd(),
lldb.eLaunchFlagExec
+ lldb.eLaunchFlagDebug
#+ lldb.eLaunchFlagDebug
#+ lldb.eLaunchFlagStopAtEntry
#+ lldb.eLaunchFlagDisableSTDIO
#+ lldb.eLaunchFlagLaunchInSeparateProcessGroup
, False, error)
self.reportError(error)
#self.listener = lldb.SBListener("event_Listener")
#self.process = self.target.Launch(self.listener, None, None,
# None, None, None,
# os.getcwd(),
# lldb.eLaunchFlagExec
# + lldb.eLaunchFlagDebug
# #+ lldb.eLaunchFlagDebug
# #+ lldb.eLaunchFlagStopAtEntry
# #+ lldb.eLaunchFlagDisableSTDIO
# #+ lldb.eLaunchFlagLaunchInSeparateProcessGroup
# , False, error)
self.pid = self.process.GetProcessID()
self.report('pid="%s"' % self.pid)
self.report('state="enginerunok"')
self.report('state="enginerunandinferiorstopok"')
error = self.process.Continue()
#self.reportError(error)
#self.report('state="enginerunandinferiorstopok"')
s = threading.Thread(target=self.loop, args=[])
s.start()
if self.useLoop:
s = threading.Thread(target=self.loop, args=[])
s.start()
def describeError(self, error):
desc = lldb.SBStream()
......@@ -811,13 +847,15 @@ class Dumper:
def readRawMemory(self, base, size):
error = lldb.SBError()
if size == 0:
return ""
#warn("BASE: %s " % base)
#warn("SIZE: %s " % size)
base = int(base) & 0xFFFFFFFFFFFFFFFF
size = int(size) & 0xFFFFFFFF
#warn("BASEX: %s " % base)
#warn("SIZEX: %s " % size)
error = lldb.SBError()
contents = self.process.ReadMemory(base, size, error)
return binascii.hexlify(contents)
......@@ -1010,9 +1048,10 @@ class Dumper:
if state != self.eventState:
self.report('state="%s"' % stateNames[state])
self.eventState = state
#if state == lldb.eStateExited:
# warn("PROCESS EXITED. %d: %s"
# % (self.process.GetExitStatus(), self.process.GetExitDescription()))
if state == lldb.eStateExited:
warn("PROCESS EXITED. %d: %s"
% (self.process.GetExitStatus(), self.process.GetExitDescription()))
self.report('state="inferiorexited"')
if type == lldb.SBProcess.eBroadcastBitStateChanged:
#if state == lldb.eStateStopped:
self.reportData()
......@@ -1127,8 +1166,9 @@ class Dumper:
def listModules(self, args):
result = 'modules=['
for module in self.target.modules:
result += '{file="%s"' % module.file.fullpath
for i in xrange(self.target.GetNumModules()):
module = self.target.GetModuleAtIndex(i)
result += '{file="%s"' % module.file.GetFullPath()
result += ',name="%s"' % module.file.basename
result += ',addrsize="%s"' % module.addr_size
result += ',triple="%s"' % module.triple
......@@ -1146,8 +1186,9 @@ class Dumper:
moduleName = args['module']
#file = lldb.SBFileSpec(moduleName)
#module = self.target.FindModule(file)
for module in self.target.modules:
if module.file.fullpath == moduleName:
for i in xrange(self.target.GetNumModules()):
module = self.target.GetModuleAtIndex(i)
if module.file.GetFullPath() == moduleName:
break
result = 'symbols={module="%s"' % moduleName
result += ',valid="%s"' % module.IsValid()
......@@ -1279,19 +1320,41 @@ class Dumper:
def execute(self, args):
getattr(self, args['cmd'])(args)
self.report('token="%s"' % args['token'])
try:
if 'continuation' in args:
cont = args['continuation']
self.report('continuation="%s"' % cont)
except:
pass
currentDir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
execfile(os.path.join(currentDir, "qttypes.py"))
def doit():
def doit1():
db = Dumper()
db.useLoop = False
db.report('state="enginesetupok"')
while True:
readable, _, _ = select.select([sys.stdin], [], [], 0.1)
event = lldb.SBEvent()
if db.listener and db.listener.PeekAtNextEvent(event):
db.listener.GetNextEvent(event)
db.handleEvent(event)
if sys.stdin in readable:
line = raw_input()
if line.startswith("db "):
db.execute(eval(line[3:]))
event = lldb.SBEvent()
if db.listener and db.listener.PeekAtNextEvent(event):
db.listener.GetNextEvent(event)
db.handleEvent(event)
def doit2():
db = Dumper()
db.useLoop = True
db.report('state="enginesetupok"')
while True:
......@@ -1304,9 +1367,9 @@ def doit():
db.execute(eval(line[3:]))
def testit():
db = Dumper()
db.useLoop = False
error = lldb.SBError()
db.target = db.debugger.CreateTarget(sys.argv[2], None, None, True, error)
......@@ -1344,4 +1407,4 @@ def testit():
if len(sys.argv) > 2:
testit()
else:
doit()
doit2()
......@@ -985,8 +985,12 @@ void LldbEngine::refreshState(const GdbMi &reportedState)
notifyInferiorSpontaneousStop();
else if (newState == "inferiorsetupok")
notifyInferiorSetupOk();
else if (newState == "enginerunok")
else if (newState == "enginerunandinferiorrunok")
notifyEngineRunAndInferiorRunOk();
else if (newState == "enginerunandinferiorstopok")
notifyEngineRunAndInferiorStopOk();
else if (newState == "inferiorexited")
notifyInferiorExited();
}
void LldbEngine::refreshLocation(const GdbMi &reportedLocation)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment