1 ##===-- debuggerdriver.py ------------------------------------*- Python -*-===##
3 # Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 # See https://llvm.org/LICENSE.txt for license information.
5 # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 ##===----------------------------------------------------------------------===##
13 from threading
import Thread
16 class DebuggerDriver(Thread
):
17 """Drives the debugger and responds to events."""
19 def __init__(self
, debugger
, event_queue
):
21 self
.event_queue
= event_queue
22 # This is probably not great because it does not give liblldb a chance
25 self
.initialize(debugger
)
27 def initialize(self
, debugger
):
29 self
.debugger
= debugger
30 self
.listener
= debugger
.GetListener()
31 if not self
.listener
.IsValid():
32 raise "Invalid listener"
34 self
.listener
.StartListeningForEventClass(
36 lldb
.SBTarget
.GetBroadcasterClassName(),
37 lldb
.SBTarget
.eBroadcastBitBreakpointChanged
38 # | lldb.SBTarget.eBroadcastBitModuleLoaded
39 # | lldb.SBTarget.eBroadcastBitModuleUnloaded
40 | lldb
.SBTarget
.eBroadcastBitWatchpointChanged
41 # | lldb.SBTarget.eBroadcastBitSymbolLoaded
44 self
.listener
.StartListeningForEventClass(
46 lldb
.SBThread
.GetBroadcasterClassName(),
47 lldb
.SBThread
.eBroadcastBitStackChanged
48 # lldb.SBThread.eBroadcastBitBreakpointChanged
49 | lldb
.SBThread
.eBroadcastBitThreadSuspended
50 | lldb
.SBThread
.eBroadcastBitThreadResumed
51 | lldb
.SBThread
.eBroadcastBitSelectedFrameChanged
52 | lldb
.SBThread
.eBroadcastBitThreadSelected
,
55 self
.listener
.StartListeningForEventClass(
57 lldb
.SBProcess
.GetBroadcasterClassName(),
58 lldb
.SBProcess
.eBroadcastBitStateChanged
59 | lldb
.SBProcess
.eBroadcastBitInterrupt
60 | lldb
.SBProcess
.eBroadcastBitSTDOUT
61 | lldb
.SBProcess
.eBroadcastBitSTDERR
62 | lldb
.SBProcess
.eBroadcastBitProfileData
,
64 self
.listener
.StartListeningForEventClass(
66 lldb
.SBCommandInterpreter
.GetBroadcasterClass(),
67 lldb
.SBCommandInterpreter
.eBroadcastBitThreadShouldExit
68 | lldb
.SBCommandInterpreter
.eBroadcastBitResetPrompt
69 | lldb
.SBCommandInterpreter
.eBroadcastBitQuitCommandReceived
70 | lldb
.SBCommandInterpreter
.eBroadcastBitAsynchronousOutputData
71 | lldb
.SBCommandInterpreter
.eBroadcastBitAsynchronousErrorData
,
74 def createTarget(self
, target_image
, args
=None):
75 self
.handleCommand("target create %s" % target_image
)
77 self
.handleCommand("settings set target.run-args %s" % args
)
79 def attachProcess(self
, pid
):
80 self
.handleCommand("process attach -p %d" % pid
)
83 def loadCore(self
, corefile
):
84 self
.handleCommand("target create -c %s" % corefile
)
94 return self
.debugger
.GetPrompt()
96 def getCommandInterpreter(self
):
97 return self
.debugger
.GetCommandInterpreter()
99 def getSourceManager(self
):
100 return self
.debugger
.GetSourceManager()
102 def setSize(self
, width
, height
):
103 # FIXME: respect height
104 self
.debugger
.SetTerminalWidth(width
)
107 return self
.debugger
.GetTargetAtIndex(0)
109 def handleCommand(self
, cmd
):
110 ret
= lldb
.SBCommandReturnObject()
111 self
.getCommandInterpreter().HandleCommand(cmd
, ret
)
115 while not self
.isDone():
116 event
= lldb
.SBEvent()
117 got_event
= self
.listener
.WaitForEvent(lldb
.UINT32_MAX
, event
)
118 if got_event
and not event
.IsValid():
119 self
.winAddStr("Warning: Invalid or no event...")
121 elif not event
.GetBroadcaster().IsValid():
124 self
.event_queue
.put(event
)
130 lldb
.SBDebugger
.Terminate()
134 def createDriver(debugger
, event_queue
):
135 driver
= DebuggerDriver(debugger
, event_queue
)
139 # else if core file specified
140 # - create target from corefile
142 # - create target from file
143 # - settings append target.run-args <args-from-cmdline>
144 # source .lldbinit file