Skip to content

Commit 4ab2b5b

Browse files
committed
Don't stop on breakpoints when running the swift Object Description function (#10693)
* The Swift `object description` expression was being run without setting "IgnoreBreakpointsInExpressions", so it was stopping on breakpoints. That's not how the ObjC object description is run, and is not what people expect here. I added the setting to the options in the Swift case, and added a test that we don't stop on breakpoints in the Object Description expression. * Mark the tests as @swifttest and fix the test name. (cherry picked from commit d8693d3)
1 parent f698e08 commit 4ab2b5b

File tree

3 files changed

+49
-16
lines changed

3 files changed

+49
-16
lines changed

lldb/source/Plugins/LanguageRuntime/Swift/SwiftLanguageRuntime.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -926,9 +926,10 @@ llvm::Error SwiftLanguageRuntime::RunObjectDescriptionExpr(
926926
Log *log(GetLog(LLDBLog::DataFormatters | LLDBLog::Expressions));
927927
ValueObjectSP result_sp;
928928
EvaluateExpressionOptions eval_options;
929+
eval_options.SetUnwindOnError(true);
929930
eval_options.SetLanguage(lldb::eLanguageTypeSwift);
930931
eval_options.SetSuppressPersistentResult(true);
931-
eval_options.SetGenerateDebugInfo(true);
932+
eval_options.SetIgnoreBreakpoints(true);
932933
eval_options.SetTimeout(GetProcess().GetUtilityExpressionTimeout());
933934

934935
StackFrameSP frame_sp = object.GetFrameSP();

lldb/test/API/lang/swift/po/val_types/TestSwiftPOValTypes.py

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,43 @@
99
# See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
1010
#
1111
# ------------------------------------------------------------------------------
12-
import lldbsuite.test.lldbinline as lldbinline
12+
import lldb
13+
import lldbsuite.test
14+
import lldbsuite.test.lldbutil as lldbutil
15+
from lldbsuite.test.lldbtest import *
1316
from lldbsuite.test.decorators import *
1417

15-
lldbinline.MakeInlineTest(__file__, globals(), decorators=[swiftTest])
18+
class TestSwiftPOValueTypes(TestBase):
19+
20+
@swiftTest
21+
def test_value_types(self):
22+
"""Test 'po' on a variety of value types with and without custom descriptions."""
23+
self.build()
24+
(_,_,_,_) = lldbutil.run_to_source_breakpoint(self, "Break here to run tests", lldb.SBFileSpec("main.swift"))
25+
26+
self.expect("po dm", substrs=['a', '12', 'b', '24'])
27+
self.expect("po cm", substrs=['c', '36'])
28+
self.expect("po cm", substrs=['12', '24'], matching=False)
29+
self.expect("po cs", substrs=['CustomDebugStringConvertible'])
30+
self.expect("po cs", substrs=['CustomStringConvertible'], matching=False)
31+
self.expect("po cs", substrs=['a', '12', 'b', '24'])
32+
self.expect("script lldb.frame.FindVariable('cs').GetObjectDescription()", substrs=['a', '12', 'b', '24'])
33+
self.expect("po (12,24,36,48)", substrs=['12', '24', '36', '48'])
34+
self.expect("po (dm as Any, cm as Any,48 as Any)", substrs=['12', '24', '36', '48'])
35+
self.expect("po patatino", substrs=['foo'])
36+
37+
@swiftTest
38+
def test_ignore_bkpts_in_po(self):
39+
"""Run a po expression with a breakpoint in the debugDescription, make sure we don't hit it."""
40+
41+
self.build()
42+
main_spec = lldb.SBFileSpec("main.swift")
43+
(target, process, thread, _) = lldbutil.run_to_source_breakpoint(self, "Break here to run tests", main_spec)
44+
po_bkpt = target.BreakpointCreateBySourceRegex("Breakpoint in debugDescription", main_spec)
45+
46+
# As part of the po expression we should auto-continue past the breakpoint so this succeeds:
47+
self.expect("po cs", substrs=['CustomDebugStringConvertible'])
48+
self.assertEqual(po_bkpt.GetHitCount(), 1, "Did hit the breakpoint")
49+
50+
51+

lldb/test/API/lang/swift/po/val_types/main.swift

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,21 @@ struct CustomSummary : CustomStringConvertible, CustomDebugStringConvertible {
1616
var a = 12
1717
var b = 24
1818

19-
var description: String { return "CustomStringConvertible" }
20-
var debugDescription: String { return "CustomDebugStringConvertible" }
19+
var description: String {
20+
return "CustomStringConvertible"
21+
}
22+
var debugDescription: String {
23+
return "CustomDebugStringConvertible" // Breakpoint in debugDescription
24+
}
2125
}
2226

2327
func main() {
2428
var dm = DefaultMirror()
2529
var cm = CustomMirror()
2630
var cs = CustomSummary()
27-
var patatino = "foo" //% self.expect("image list")
28-
print("yay I am done!") //% self.expect("po dm", substrs=['a', '12', 'b', '24'])
29-
//% self.expect("po cm", substrs=['c', '36'])
30-
//% self.expect("po cm", substrs=['12', '24'], matching=False)
31-
//% self.expect("po cs", substrs=['CustomDebugStringConvertible'])
32-
//% self.expect("po cs", substrs=['CustomStringConvertible'], matching=False)
33-
//% self.expect("po cs", substrs=['a', '12', 'b', '24'])
34-
//% self.expect("script lldb.frame.FindVariable('cs').GetObjectDescription()", substrs=['a', '12', 'b', '24'])
35-
//% self.expect("po (12,24,36,48)", substrs=['12', '24', '36', '48'])
36-
//% self.expect("po (dm as Any, cm as Any,48 as Any)", substrs=['12', '24', '36', '48'])
37-
//% self.expect("po patatino", substrs=['foo'])
31+
var patatino = "foo"
32+
33+
print("yay I am done!") // Break here to run tests.
3834
}
3935

4036
main()

0 commit comments

Comments
 (0)