Skip to content

debugger: Reverse Python repr escaping#50554

Merged
ConradIrwin merged 1 commit intomainfrom
debugger-improve-variable-copying
Mar 4, 2026
Merged

debugger: Reverse Python repr escaping#50554
ConradIrwin merged 1 commit intomainfrom
debugger-improve-variable-copying

Conversation

@ConradIrwin
Copy link
Copy Markdown
Member

Closes #37168

Authored-By: @ngauder

Release Notes:

  • debugger: Unescape Python strings

@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Mar 3, 2026
@zed-community-bot zed-community-bot bot added the staff Pull requests authored by a current member of Zed staff label Mar 3, 2026
@ConradIrwin
Copy link
Copy Markdown
Member Author

@Anthony-Eid @ngauder and I went back and forth on this a little bit. I think the fix is useful, and I'm not sure a better way to factor it, but would love a second opinion from you.

@Anthony-Eid
Copy link
Copy Markdown
Contributor

The fix makes sense, the only thing I'm not a fan of is that it's adapter specific. There doesn't seem to be a clean way around that though.

I wonder if there's an arg we can pass into Debugpy to fix this, or if we should submit a PR.

@ConradIrwin
Copy link
Copy Markdown
Member Author

A PR to Debugpy seems sensible @ngauder if you want to take a pass.

Going to merge this in the meantime.

@ConradIrwin ConradIrwin merged commit 0fc5bc2 into main Mar 4, 2026
38 checks passed
@ConradIrwin ConradIrwin deleted the debugger-improve-variable-copying branch March 4, 2026 19:55
@ngauder
Copy link
Copy Markdown
Contributor

ngauder commented Mar 8, 2026

I dug a bit into this and found the code in debugpy that's responsible for generating the str representation: https://github.com/microsoft/debugpy/blob/2801e484ceee299390a037c6a71a6d305c42ba35/src/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_safe_repr.py#L264

From what I can tell, there doesn't seem to be a clean way to fix this on our side since it's inherent to how debugpy (via pydevd) generates safe string representations.

While looking into it, I also noticed another related issue: very long strings are truncated by debugpy. That means when debugging from Zed they won't be copied correctly to the clipboard because the value we receive is already truncated.

Quick demo:

ok = "a" * 2**16
too_long = "a" * 2**16 + "!"

print("breakpoint here")
print(ok)
print(too_long)

In this case, too_long gets truncated in the debugger representation, so copying it won't yield the real value (see also microsoft/debugpy#1204 and microsoft/vscode#73845).

Maybe the proper way to solve this would be to obtain the variable value via a ReadMemory DAP request (or some other mechanism that bypasses the repr) specifically when copying a value to the clipboard rather than relying on the string representation we get for display in the debugger UI. But I'm not very familiar with the best approach here/no expert in this area.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement staff Pull requests authored by a current member of Zed staff

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Debugger: string value escaped and truncated

3 participants