Skip to content

Commit d4159d9

Browse files
medismailbenbulbazord
authored andcommitted
[lldb] Improve breakpoint management for interactive scripted process
This patch improves breakpoint management when doing interactive scripted process debugging. In other to know which process set a breakpoint, we need to do some book keeping on the multiplexer scripted process. When initializing the multiplexer, we will first copy breakpoints that are already set on the driving target. Everytime we launch or resume, we should copy breakpoints from the multiplexer to the driving process. When creating a breakpoint from a child process, it needs to be set both on the multiplexer and on the driving process. We also tag the created breakpoint with the name and pid of the originator process. This patch also implements all the requirement to achieve proper breakpoint management. That involves: - Adding python interator for breakpoints and watchpoints in SBTarget - Add a new `ScriptedProcess.create_breakpoint` python method Differential Revision: https://reviews.llvm.org/D148548 Signed-off-by: Med Ismail Bennani <[email protected]> (cherry picked from commit e31d0c2)
1 parent 808ab31 commit d4159d9

File tree

1 file changed

+63
-1
lines changed

1 file changed

+63
-1
lines changed

lldb/bindings/interface/SBTargetExtensions.i

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ STRING_EXTENSION_LEVEL_OUTSIDE(SBTarget, lldb::eDescriptionLevelBrief)
8888

8989
def get_modules_access_object(self):
9090
'''An accessor function that returns a modules_access() object which allows lazy module access from a lldb.SBTarget object.'''
91-
return self.modules_access (self)
91+
return self.modules_access(self)
9292

9393
def get_modules_array(self):
9494
'''An accessor function that returns a list() that contains all modules in a lldb.SBTarget object.'''
@@ -107,18 +107,80 @@ STRING_EXTENSION_LEVEL_OUTSIDE(SBTarget, lldb::eDescriptionLevelBrief)
107107
object.'''
108108
return lldb_iter(self, 'GetNumBreakpoints', 'GetBreakpointAtIndex')
109109

110+
class bkpts_access(object):
111+
'''A helper object that will lazily hand out bkpts for a target when supplied an index.'''
112+
def __init__(self, sbtarget):
113+
self.sbtarget = sbtarget
114+
115+
def __len__(self):
116+
if self.sbtarget:
117+
return int(self.sbtarget.GetNumBreakpoints())
118+
return 0
119+
120+
def __getitem__(self, key):
121+
if isinstance(key, int):
122+
count = len(self)
123+
if -count <= key < count:
124+
key %= count
125+
return self.sbtarget.GetBreakpointAtIndex(key)
126+
return None
127+
128+
def get_bkpts_access_object(self):
129+
'''An accessor function that returns a bkpts_access() object which allows lazy bkpt access from a lldb.SBtarget object.'''
130+
return self.bkpts_access(self)
131+
132+
def get_target_bkpts(self):
133+
'''An accessor function that returns a list() that contains all bkpts in a lldb.SBtarget object.'''
134+
bkpts = []
135+
for idx in range(self.GetNumBreakpoints()):
136+
bkpts.append(self.GetBreakpointAtIndex(idx))
137+
return bkpts
138+
110139
def watchpoint_iter(self):
111140
'''Returns an iterator over all watchpoints in a lldb.SBTarget
112141
object.'''
113142
return lldb_iter(self, 'GetNumWatchpoints', 'GetWatchpointAtIndex')
114143

144+
class watchpoints_access(object):
145+
'''A helper object that will lazily hand out watchpoints for a target when supplied an index.'''
146+
def __init__(self, sbtarget):
147+
self.sbtarget = sbtarget
148+
149+
def __len__(self):
150+
if self.sbtarget:
151+
return int(self.sbtarget.GetNumWatchpoints())
152+
return 0
153+
154+
def __getitem__(self, key):
155+
if isinstance(key, int):
156+
count = len(self)
157+
if -count <= key < count:
158+
key %= count
159+
return self.sbtarget.GetWatchpointAtIndex(key)
160+
return None
161+
162+
def get_watchpoints_access_object(self):
163+
'''An accessor function that returns a watchpoints_access() object which allows lazy watchpoint access from a lldb.SBtarget object.'''
164+
return self.watchpoints_access(self)
165+
166+
def get_target_watchpoints(self):
167+
'''An accessor function that returns a list() that contains all watchpoints in a lldb.SBtarget object.'''
168+
watchpoints = []
169+
for idx in range(self.GetNumWatchpoints()):
170+
bkpts.append(self.GetWatchpointAtIndex(idx))
171+
return watchpoints
172+
115173
modules = property(get_modules_array, None, doc='''A read only property that returns a list() of lldb.SBModule objects contained in this target. This list is a list all modules that the target currently is tracking (the main executable and all dependent shared libraries).''')
116174
module = property(get_modules_access_object, None, doc=r'''A read only property that returns an object that implements python operator overloading with the square brackets().\n target.module[<int>] allows array access to any modules.\n target.module[<str>] allows access to modules by basename, full path, or uuid string value.\n target.module[uuid.UUID()] allows module access by UUID.\n target.module[re] allows module access using a regular expression that matches the module full path.''')
117175
process = property(GetProcess, None, doc='''A read only property that returns an lldb object that represents the process (lldb.SBProcess) that this target owns.''')
118176
executable = property(GetExecutable, None, doc='''A read only property that returns an lldb object that represents the main executable module (lldb.SBModule) for this target.''')
119177
debugger = property(GetDebugger, None, doc='''A read only property that returns an lldb object that represents the debugger (lldb.SBDebugger) that owns this target.''')
120178
num_breakpoints = property(GetNumBreakpoints, None, doc='''A read only property that returns the number of breakpoints that this target has as an integer.''')
179+
breakpoints = property(get_target_bkpts, None, doc='''A read only property that returns a list() of lldb.SBBreakpoint objects for all breakpoints in this target.''')
180+
breakpoint = property(get_bkpts_access_object, None, doc='''A read only property that returns an object that can be used to access breakpoints as an array ("bkpt_12 = lldb.target.bkpt[12]").''')
121181
num_watchpoints = property(GetNumWatchpoints, None, doc='''A read only property that returns the number of watchpoints that this target has as an integer.''')
182+
watchpoints = property(get_target_watchpoints, None, doc='''A read only property that returns a list() of lldb.SBwatchpoint objects for all watchpoints in this target.''')
183+
watchpoint = property(get_watchpoints_access_object, None, doc='''A read only property that returns an object that can be used to access watchpoints as an array ("watchpoint_12 = lldb.target.watchpoint[12]").''')
122184
broadcaster = property(GetBroadcaster, None, doc='''A read only property that an lldb object that represents the broadcaster (lldb.SBBroadcaster) for this target.''')
123185
byte_order = property(GetByteOrder, None, doc='''A read only property that returns an lldb enumeration value (lldb.eByteOrderLittle, lldb.eByteOrderBig, lldb.eByteOrderInvalid) that represents the byte order for this target.''')
124186
addr_size = property(GetAddressByteSize, None, doc='''A read only property that returns the size in bytes of an address for this target.''')

0 commit comments

Comments
 (0)