Skip to content

[lldb] Upstream bindings improvements #10416

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lldb/bindings/interface/SBTargetExtensions.i
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ STRING_EXTENSION_LEVEL_OUTSIDE(SBTarget, lldb::eDescriptionLevelBrief)
module = self.sbtarget.GetModuleAtIndex(idx)
if module.uuid == key:
return module
elif type(key) is re.SRE_Pattern:
elif isinstance(key, type(re.compile(''))):
matching_modules = []
for idx in range(num_modules):
module = self.sbtarget.GetModuleAtIndex(idx)
re_match = key.search(module.path.fullpath)
re_match = key.search(module.file.fullpath)
if re_match:
matching_modules.append(module)
return matching_modules
Expand Down
16 changes: 16 additions & 0 deletions lldb/bindings/interface/SBThreadExtensions.i
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,20 @@ STRING_EXTENSION_OUTSIDE(SBThread)
frames.append(frame)
return frames

def get_stop_reason_data(self):
return [
self.GetStopReasonDataAtIndex(idx)
for idx in range(self.GetStopReasonDataCount())
]

def set_selected_frame(self, frame):
if isinstance(frame, SBFrame):
if frame.thread != self:
raise ValueError("cannot select frame from different thread")
self.SetSelectedFrame(frame.idx)
else:
self.SetSelectedFrame(frame)

id = property(GetThreadID, None, doc='''A read only property that returns the thread ID as an integer.''')
idx = property(GetIndexID, None, doc='''A read only property that returns the thread index ID as an integer. Thread index ID values start at 1 and increment as threads come and go and can be used to uniquely identify threads.''')
return_value = property(GetStopReturnValue, None, doc='''A read only property that returns an lldb object that represents the return value from the last stop (lldb.SBValue) if we just stopped due to stepping out of a function.''')
Expand All @@ -56,8 +70,10 @@ STRING_EXTENSION_OUTSIDE(SBThread)
queue = property(GetQueueName, None, doc='''A read only property that returns the dispatch queue name of this thread as a string.''')
queue_id = property(GetQueueID, None, doc='''A read only property that returns the dispatch queue id of this thread as an integer.''')
stop_reason = property(GetStopReason, None, doc='''A read only property that returns an lldb enumeration value (see enumerations that start with "lldb.eStopReason") that represents the reason this thread stopped.''')
stop_reason_data = property(get_stop_reason_data, None, doc='''A read only property that returns the stop reason data as a list.''')
is_suspended = property(IsSuspended, None, doc='''A read only property that returns a boolean value that indicates if this thread is suspended.''')
is_stopped = property(IsStopped, None, doc='''A read only property that returns a boolean value that indicates if this thread is stopped but not exited.''')
selected_frame = property(GetSelectedFrame, set_selected_frame, doc='''A read/write property that gets and sets the selected frame of this SBThread.''')
%}
#endif
}
16 changes: 15 additions & 1 deletion lldb/bindings/interface/SBValueExtensions.i
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ STRING_EXTENSION_OUTSIDE(SBValue)
return self.GetDynamicValue (eDynamicCanRunTarget)

class children_access(object):
'''A helper object that will lazily hand out thread for a process when supplied an index.'''
'''A helper object that will lazily hand out child values when supplied an index.'''

def __init__(self, sbvalue):
self.sbvalue = sbvalue
Expand All @@ -29,6 +29,19 @@ STRING_EXTENSION_OUTSIDE(SBValue)
'''An accessor function that returns a children_access() object which allows lazy member variable access from a lldb.SBValue object.'''
return self.children_access (self)

def get_member_access_object(self):
'''An accessor function that returns an interface which provides subscript based lookup of child members.'''
class member_access:
def __init__(self, valobj):
self.valobj = valobj

def __getitem__(self, key):
if isinstance(key, str):
return self.valobj.GetChildMemberWithName(key)
raise TypeError("member key must be a string")

return member_access(self)

def get_value_child_list(self):
'''An accessor function that returns a list() that contains all children in a lldb.SBValue object.'''
children = []
Expand All @@ -50,6 +63,7 @@ STRING_EXTENSION_OUTSIDE(SBValue)

children = property(get_value_child_list, None, doc='''A read only property that returns a list() of lldb.SBValue objects for the children of the value.''')
child = property(get_child_access_object, None, doc='''A read only property that returns an object that can access children of a variable by index (child_value = value.children[12]).''')
member = property(get_member_access_object, None, doc='''A read only property that returns an object that can access child members by name.''')
name = property(GetName, None, doc='''A read only property that returns the name of this value as a string.''')
type = property(GetType, None, doc='''A read only property that returns a lldb.SBType object that represents the type for this value.''')
size = property(GetByteSize, None, doc='''A read only property that returns the size in bytes of this value.''')
Expand Down
Loading