Skip to content

Commit f5368ed

Browse files
committed
[lldb] Add SBThread.selected_frame property (llvm#123981)
Adds a `selected_frame` property to `SBThread`. The setter accepts either a frame index (like `SetSelectedFrame`), or a frame object. Updates a few tests to make use of the new `selected_frame`. While doing so I noticed some of the usage could be cleaned up, so I did that too. (cherry picked from commit 7293455)
1 parent d1723d2 commit f5368ed

File tree

5 files changed

+21
-20
lines changed

5 files changed

+21
-20
lines changed

lldb/bindings/interface/SBThreadExtensions.i

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,14 @@ STRING_EXTENSION_OUTSIDE(SBThread)
5151
for idx in range(self.GetStopReasonDataCount())
5252
]
5353

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+
5462
id = property(GetThreadID, None, doc='''A read only property that returns the thread ID as an integer.''')
5563
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.''')
5664
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.''')
@@ -65,6 +73,7 @@ STRING_EXTENSION_OUTSIDE(SBThread)
6573
stop_reason_data = property(get_stop_reason_data, None, doc='''A read only property that returns the stop reason data as a list.''')
6674
is_suspended = property(IsSuspended, None, doc='''A read only property that returns a boolean value that indicates if this thread is suspended.''')
6775
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.''')
6877
%}
6978
#endif
7079
}

lldb/test/API/commands/frame/recognizer/TestFrameRecognizer.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def test_frame_recognizer_1(self):
9999
target, process, thread, _ = lldbutil.run_to_name_breakpoint(
100100
self, "foo", exe_name=exe
101101
)
102-
frame = thread.GetSelectedFrame()
102+
frame = thread.selected_frame
103103

104104
self.expect("frame variable", substrs=["(int) a = 42", "(int) b = 56"])
105105

@@ -169,7 +169,7 @@ def test_frame_recognizer_hiding(self):
169169
self.build()
170170

171171
target, process, thread, _ = lldbutil.run_to_name_breakpoint(self, "nested")
172-
frame = thread.GetSelectedFrame()
172+
frame = thread.selected_frame
173173

174174
# Sanity check.
175175
self.expect(
@@ -233,7 +233,6 @@ def test_frame_recognizer_multi_symbol(self):
233233
target, process, thread, _ = lldbutil.run_to_name_breakpoint(
234234
self, "foo", exe_name=exe
235235
)
236-
frame = thread.GetSelectedFrame()
237236

238237
self.expect(
239238
"frame recognizer info 0",
@@ -243,7 +242,6 @@ def test_frame_recognizer_multi_symbol(self):
243242
target, process, thread, _ = lldbutil.run_to_name_breakpoint(
244243
self, "bar", exe_name=exe
245244
)
246-
frame = thread.GetSelectedFrame()
247245

248246
self.expect(
249247
"frame recognizer info 0",
@@ -380,7 +378,7 @@ def test_frame_recognizer_not_only_first_instruction(self):
380378

381379
opts = lldb.SBVariablesOptions()
382380
opts.SetIncludeRecognizedArguments(True)
383-
frame = thread.GetSelectedFrame()
381+
frame = thread.selected_frame
384382
variables = frame.GetVariables(opts)
385383

386384
self.assertEqual(variables.GetSize(), 2)

lldb/test/API/functionalities/location-list-lookup/TestLocationListLookup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def check_local_vars(self, process: lldb.SBProcess, check_expr: bool):
2525
# Find `bar` on the stack, then
2626
# make sure we can read out the local
2727
# variables (with both `frame var` and `expr`)
28-
for f in process.GetSelectedThread().frames:
28+
for f in process.selected_thread.frames:
2929
frame_name = f.GetDisplayFunctionName()
3030
if frame_name is not None and frame_name.startswith("Foo::bar"):
3131
argv = f.GetValueForVariablePath("argv").GetChildAtIndex(0)
@@ -34,7 +34,7 @@ def check_local_vars(self, process: lldb.SBProcess, check_expr: bool):
3434
self.assertNotEqual(strm.GetData().find("a.out"), -1)
3535

3636
if check_expr:
37-
process.GetSelectedThread().SetSelectedFrame(f.idx)
37+
process.selected_thread.selected_frame = f
3838
self.expect_expr("this", result_type="Foo *")
3939

4040
@skipIf(bugnumber = "rdar://135577167")

lldb/test/API/lang/cpp/std-function-recognizer/TestStdFunctionRecognizer.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,14 @@ def test_up_down(self):
6464
(target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(
6565
self, "// break here", lldb.SBFileSpec("main.cpp")
6666
)
67-
frame = thread.GetSelectedFrame()
67+
frame = thread.selected_frame
6868
# up
6969
self.assertIn("foo", frame.GetFunctionName())
7070
start_idx = frame.GetFrameID()
7171
i = 0
7272
while i < thread.GetNumFrames():
7373
self.expect("up")
74-
frame = thread.GetSelectedFrame()
74+
frame = thread.selected_frame
7575
if frame.GetFunctionName() == "main":
7676
break
7777
end_idx = frame.GetFrameID()
@@ -81,7 +81,7 @@ def test_up_down(self):
8181
start_idx = frame.GetFrameID()
8282
for i in range(1, thread.GetNumFrames()):
8383
self.expect("down")
84-
frame = thread.GetSelectedFrame()
84+
frame = thread.selected_frame
8585
if "foo" in frame.GetFunctionName():
8686
break
8787
end_idx = frame.GetFrameID()
@@ -94,11 +94,8 @@ def test_api(self):
9494
(target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(
9595
self, "// break here", lldb.SBFileSpec("main.cpp")
9696
)
97-
frame = thread.GetSelectedFrame()
9897
num_hidden = 0
99-
for i in range(1, thread.GetNumFrames()):
100-
thread.SetSelectedFrame(i)
101-
frame = thread.GetSelectedFrame()
98+
for frame in thread.frames:
10299
if frame.IsHidden():
103100
num_hidden += 1
104101

lldb/test/API/lang/objc/print-obj/TestPrintObj.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,9 @@ def test_print_obj(self):
6969
# We want to traverse the frame to the one corresponding to blocked.m to
7070
# issue our 'po lock_me' command.
7171

72-
depth = other_thread.GetNumFrames()
73-
for i in range(depth):
74-
frame = other_thread.GetFrameAtIndex(i)
75-
name = frame.GetFunctionName()
76-
if name == "main":
77-
other_thread.SetSelectedFrame(i)
72+
for frame in other_thread.frames:
73+
if frame.name == "main":
74+
other_thread.selected_frame = frame
7875
if self.TraceOn():
7976
print("selected frame:" + lldbutil.get_description(frame))
8077
break

0 commit comments

Comments
 (0)