Skip to content

[debug] Print strings using their description in the debugger #73550

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 3 commits into from
May 16, 2024
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
8 changes: 7 additions & 1 deletion stdlib/public/core/DebuggerSupport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,13 @@ public enum _DebuggerSupport {
print("\(name) : ", terminator: "", to: &target)
}

if let str = asStringRepresentation(value: value, mirror: mirror, count: count) {
if isRoot, let value = value as? String {
// We don't want to use string's debug desciprtion for 'po' because it
// escapes the string and prints it raw (e.g. prints "\n" instead of
// actually printing a newline), but only if its the root value. Otherwise,
// continue using the debug description.
print(value, terminator: "", to: &target)
} else if let str = asStringRepresentation(value: value, mirror: mirror, count: count) {
print(str, terminator: "", to: &target)
}

Expand Down
7 changes: 6 additions & 1 deletion test/stdlib/BridgedObjectDebuggerSupport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,12 @@ StringForPrintObjectTests.test("NSStringUTF8") {
let debug = debugVal(&newNSUTF16)
expectEqual("🏂☃❅❆❄︎⛄️❄️", String(reflecting: nsUTF16))
expectEqual("\"🏂☃❅❆❄︎⛄️❄️\"", String(reflecting: newNSUTF16))
expectEqual("\"🏂☃❅❆❄︎⛄️❄️\"\n", printed)

if #available(SwiftStdlib 6.0, *) {
expectEqual("🏂☃❅❆❄︎⛄️❄️\n", printed)
} else {
expectEqual("\"🏂☃❅❆❄︎⛄️❄️\"\n", printed)
}
expectEqual(printed, debug)
}

Expand Down
7 changes: 7 additions & 0 deletions test/stdlib/DebuggerSupport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,13 @@ StringForPrintObjectTests.test("DontBridgeThisStruct") {
}
#endif

if #available(SwiftStdlib 6.0, *) {
StringForPrintObjectTests.test("String") {
let printed = _stringForPrintObject("hello\nworld")
expectEqual(printed, "hello\nworld\n")
}
}

class RefCountedObj {
var patatino : Int
init(_ p : Int) {
Expand Down