Skip to content
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

[SR-10702] Request: lldb setting to render strings literally #4485

Open
NSExceptional opened this issue May 16, 2019 · 4 comments
Open

[SR-10702] Request: lldb setting to render strings literally #4485

NSExceptional opened this issue May 16, 2019 · 4 comments

Comments

@NSExceptional
Copy link

Previous ID SR-10702
Radar None
Original Reporter @NSExceptional
Type New Feature
Additional Detail from JIRA
Votes 0
Component/s LLDB for Swift
Labels New Feature
Assignee None
Priority Medium

md5: e8d7a61ff7c776cb8b0974b0e22366cd

Issue Description:

Strings currently render like this in LLDB for Swift:

(lldb) po someString
"{\n\t\"foo\": 5\n}"

I realize this is intentional—I remember reading that somewhere—but this is never what I want. I think I speak for a lot of people when I say that I'd rather see this:

(lldb) po someString
{
    "foo": 5
}

I would love either an lldb setting to change string printing behavior in Swift, or a special command to print them literally.

@belkadan
Copy link

I could see this being the difference between expr and po. jingham@apple.com (JIRA User), what do you think?

@swift-ci
Copy link

Comment by Jim Ingham (JIRA)

The result of "expr" for a string should show the \n , \t, etc. Since you need something to compare against what you typed into your code, and expr is the debugger view of the object, it seems right that expr should show the characters as typed.

The output of "po" for swift is the result of the debugDescription for String, which comes from the swift standard library. lldb just outputs the resultant text to the console, so real newlines would be newlines, etc. I don't have a strong opinion about how that behaves, but that's something to take that up with the standard library folks.

Note that if you want to render the string - as opposed to getting its debug description, you can do:

(lldb) expr print(someString)

That will show the rendered string and it's actually more efficient than po for printing strings - since `po` has to evaluate the expression, then pass it the expression's result to the mirror printing routine.

@NSExceptional
Copy link
Author

lldb just outputs the [ result of the debugDescription for String ] to the console, so real newlines would be newlines, etc.

So, String.debugDescription os escaping itself then? I guess we can't change how po works, can we just make String.debugDescription not escape itself? Seems redundant since expr is going to do the same thing for us (@ standard library folks). Maybe we could make a special case for String?

(lldb) expr print(someString)

That's a neat workaround![]( I'll definitely be using this in the meantime. Thank you)

@swift-ci
Copy link

Comment by Jim Ingham (JIRA)

Yes, probably the Standard Library folks thought the distinction between "description" - which doesn't escape - and which BTW is what print uses - and debugDescription which shows the string as typed in code was useful. I can actually see the sense behind that, especially given that you can get the rendered version from "print" in the debugger pretty easily...

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants