Skip to content

Commit bddce88

Browse files
authored
Merge pull request #10416 from swiftlang/lldb-bindings-cherry-picks
[lldb] Upstream bindings improvements
2 parents 1a6cc02 + 1499abb commit bddce88

File tree

12 files changed

+1318
-1308
lines changed

12 files changed

+1318
-1308
lines changed

lldb/bindings/interface/SBTargetExtensions.i

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,11 @@ STRING_EXTENSION_LEVEL_OUTSIDE(SBTarget, lldb::eDescriptionLevelBrief)
7979
module = self.sbtarget.GetModuleAtIndex(idx)
8080
if module.uuid == key:
8181
return module
82-
elif type(key) is re.SRE_Pattern:
82+
elif isinstance(key, type(re.compile(''))):
8383
matching_modules = []
8484
for idx in range(num_modules):
8585
module = self.sbtarget.GetModuleAtIndex(idx)
86-
re_match = key.search(module.path.fullpath)
86+
re_match = key.search(module.file.fullpath)
8787
if re_match:
8888
matching_modules.append(module)
8989
return matching_modules

lldb/bindings/interface/SBThreadExtensions.i

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,20 @@ STRING_EXTENSION_OUTSIDE(SBThread)
4545
frames.append(frame)
4646
return frames
4747

48+
def get_stop_reason_data(self):
49+
return [
50+
self.GetStopReasonDataAtIndex(idx)
51+
for idx in range(self.GetStopReasonDataCount())
52+
]
53+
54+
def set_selected_frame(self, frame):
55+
if isinstance(frame, SBFrame):
56+
if frame.thread != self:
57+
raise ValueError("cannot select frame from different thread")
58+
self.SetSelectedFrame(frame.idx)
59+
else:
60+
self.SetSelectedFrame(frame)
61+
4862
id = property(GetThreadID, None, doc='''A read only property that returns the thread ID as an integer.''')
4963
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.''')
5064
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.''')
@@ -56,8 +70,10 @@ STRING_EXTENSION_OUTSIDE(SBThread)
5670
queue = property(GetQueueName, None, doc='''A read only property that returns the dispatch queue name of this thread as a string.''')
5771
queue_id = property(GetQueueID, None, doc='''A read only property that returns the dispatch queue id of this thread as an integer.''')
5872
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.''')
73+
stop_reason_data = property(get_stop_reason_data, None, doc='''A read only property that returns the stop reason data as a list.''')
5974
is_suspended = property(IsSuspended, None, doc='''A read only property that returns a boolean value that indicates if this thread is suspended.''')
6075
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.''')
76+
selected_frame = property(GetSelectedFrame, set_selected_frame, doc='''A read/write property that gets and sets the selected frame of this SBThread.''')
6177
%}
6278
#endif
6379
}

lldb/bindings/interface/SBValueExtensions.i

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ STRING_EXTENSION_OUTSIDE(SBValue)
77
return self.GetDynamicValue (eDynamicCanRunTarget)
88

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

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

32+
def get_member_access_object(self):
33+
'''An accessor function that returns an interface which provides subscript based lookup of child members.'''
34+
class member_access:
35+
def __init__(self, valobj):
36+
self.valobj = valobj
37+
38+
def __getitem__(self, key):
39+
if isinstance(key, str):
40+
return self.valobj.GetChildMemberWithName(key)
41+
raise TypeError("member key must be a string")
42+
43+
return member_access(self)
44+
3245
def get_value_child_list(self):
3346
'''An accessor function that returns a list() that contains all children in a lldb.SBValue object.'''
3447
children = []
@@ -50,6 +63,7 @@ STRING_EXTENSION_OUTSIDE(SBValue)
5063

5164
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.''')
5265
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]).''')
66+
member = property(get_member_access_object, None, doc='''A read only property that returns an object that can access child members by name.''')
5367
name = property(GetName, None, doc='''A read only property that returns the name of this value as a string.''')
5468
type = property(GetType, None, doc='''A read only property that returns a lldb.SBType object that represents the type for this value.''')
5569
size = property(GetByteSize, None, doc='''A read only property that returns the size in bytes of this value.''')

0 commit comments

Comments
 (0)