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

debug: Newlines in strings in debugger displayed as actual new lines instead of "\n" #1321

Closed
mattwelke opened this issue Mar 12, 2021 · 8 comments
Labels
Debug Issues related to the debugging functionality of the extension. FrozenDueToAge upstream-vscode Issues that are by problems in VS Code itself.

Comments

@mattwelke
Copy link

Please answer these questions before submitting your issue. Thanks!

What version of Go, VS Code & VS Code Go extension are you using?

  • Run go version to get version of Go from the VS Code integrated terminal.
    • go version go1.16 linux/amd64
  • Run gopls -v version to get version of Gopls from the VS Code integrated terminal.
    • golang.org/x/tools/gopls v0.6.6
  • Run code -v or code-insiders -v to get version of VS Code or VS Code Insiders.
    • 1.54.1
  • Check your installed extensions to get the version of the VS Code Go extension
    • v0.23.2
  • Run Ctrl+Shift+P (Cmd+Shift+P on Mac OS) > Go: Locate Configured Go Tools command
Checking configured tools....
GOBIN: undefined
toolsGopath: 
gopath: /home/matt/go
GOROOT: /usr/local/go
PATH: /home/matt/.vscode-server/bin/f30a9b73e8ffc278e71575118b6bf568f04587c8/bin:/home/matt/.poetry/bin:/home/matt/google-cloud-sdk/bin:/home/matt/.poetry/bin:/home/matt/.pyenv/plugins/pyenv-virtualenv/shims:/home/matt/.pyenv/shims:/home/matt/.pyenv/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/mnt/c/Program Files/AdoptOpenJDK/jdk-11.0.10.9-hotspot/bin:/mnt/c/Windows/system32:/mnt/c/Windows:/mnt/c/Windows/System32/Wbem:/mnt/c/Windows/System32/WindowsPowerShell/v1.0/:/mnt/c/Windows/System32/OpenSSH/:/mnt/c/Program Files (x86)/NVIDIA Corporation/PhysX/Common:/mnt/c/Program Files/Git/cmd:/mnt/c/Program Files/dotnet/:/mnt/c/Program Files/Docker/Docker/resources/bin:/mnt/c/ProgramData/DockerDesktop/version-bin:/mnt/c/Users/mattw/AppData/Local/Microsoft/WindowsApps:/mnt/c/Users/mattw/AppData/Local/Programs/Microsoft VS Code/bin:/mnt/c/Users/mattw/.dotnet/tools:/snap/bin:/usr/local/go/bin:/home/matt/go/bin:/home/matt/n/bin:/opt/protoc/bin

   gopkgs: /home/matt/go/bin/gopkgs installed
   go-outline: /home/matt/go/bin/go-outline installed
   gotests: /home/matt/go/bin/gotests installed
   gomodifytags: /home/matt/go/bin/gomodifytags installed
   impl: /home/matt/go/bin/impl installed
   goplay: /home/matt/go/bin/goplay installed
   dlv: /home/matt/go/bin/dlv installed
   staticcheck: staticcheck not installed
   gopls: /home/matt/go/bin/gopls installed

go env
Workspace Folder (go-string-with-newline-debugger-bug): /home/matt/go-string-with-newline-debugger-bug
	GO111MODULE=""
	GOARCH="amd64"
	GOBIN=""
	GOCACHE="/home/matt/.cache/go-build"
	GOENV="/home/matt/.config/go/env"
	GOEXE=""
	GOFLAGS=""
	GOHOSTARCH="amd64"
	GOHOSTOS="linux"
	GOINSECURE=""
	GOMODCACHE="/home/matt/go/pkg/mod"
	GONOPROXY="github.com/groupby"
	GONOSUMDB="github.com/groupby"
	GOOS="linux"
	GOPATH="/home/matt/go"
	GOPRIVATE="github.com/groupby"
	GOPROXY="https://proxy.golang.org,direct"
	GOROOT="/usr/local/go"
	GOSUMDB="sum.golang.org"
	GOTMPDIR=""
	GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
	GOVCS=""
	GOVERSION="go1.16"
	GCCGO="gccgo"
	AR="ar"
	CC="gcc"
	CXX="g++"
	CGO_ENABLED="1"
	GOMOD="/home/matt/go-string-with-newline-debugger-bug/go.mod"
	CGO_CFLAGS="-g -O2"
	CGO_CPPFLAGS=""
	CGO_CXXFLAGS="-g -O2"
	CGO_FFLAGS="-g -O2"
	CGO_LDFLAGS="-g -O2"
	PKG_CONFIG="pkg-config"
	GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build995798943=/tmp/go-build -gno-record-gcc-switches"

Share the Go related settings you have added/edited

Run Preferences: Open Settings (JSON) command to open your settings.json file.
Share all the settings with the go. or ["go"] or gopls prefixes.

(none)

Describe the bug

When using the debugger, string values are rendered with newlines becoming actual newlines (preventing the characters after the newline from appearing). Example:

package main

import "fmt"

func main() {
	longString := `
	{
		"propName": "value"
	}
	`
	fmt.Printf("string is %s", longString)
}

If I add a break point to the line with fmt.Printf, and observe the value of longString in the debugger, it appears like this:

image

This isn't a useful way to see this information. For use cases like a JSON string, there will never be any useful information available to me for objects and arrays. In my opinion, it would be more useful to have the newlines converted to \n in this display, so that I can at least see more data from the string.

I can se the rest of the string by moving my mouse over it, but this isn't as useful as just being able to see it at a glance, and makes it impossible to see the values for more than one string variable at a time that is like this:

image

Repo with full reproduction: https://github.com/mattwelke/go-string-with-newline-debugger-bug

Steps to reproduce the behavior:

  1. Create a string variable and give it a value that has newlines.
  2. Run debugger.
  3. Observe the value of the string in the debugger.
@hyangah
Copy link
Contributor

hyangah commented Mar 12, 2021

Thanks for the report @mattwelke

We are currently working on a new debug adapter (that's embedded in dlv) and that seems to be escaping the new lines.
You can try it by compiling the dlv at master (go install github.com/go-delve/delve/cmd/delve) and specifying "debugAdapter": "dlv-dap", in the launch.json now. (warning: the new adapter is still in experimental mode and this workflow will change soon)

Screen Shot 2021-03-12 at 10 12 37 AM.

@polinasok @suzmue

@hyangah hyangah added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Mar 12, 2021
@hyangah hyangah changed the title Newlines in strings in debugger displayed as actual new lines instead of "\n" debug: Newlines in strings in debugger displayed as actual new lines instead of "\n" Mar 12, 2021
@mattwelke
Copy link
Author

@hyangah Sure I'll test that out. I'm not familiar with building things like that from scratch though so it might take me a bit to get it running. I'll post back when I do.

Another thought I just had though is that maybe some folks would prefer the new lines not be escaped. Like my example where I mouse over the variable get a nice visual representation of it, with new lines rendered. Perhaps long term, the best option would be a toggle people could click on in the UI (maybe on the left, in the debugging section) where they could toggle escaping whitespace characters like new lines?

@hyangah hyangah added Debug Issues related to the debugging functionality of the extension. DlvDAP labels Mar 15, 2021
@polinasok
Copy link
Contributor

polinasok commented Mar 22, 2021

According to DAP spec, variable's value <...> can be a multi-line text, e.g. for a function the body of a function, so the fact that such multi-line values are not displayed accordingly seems like a bug in the vscode UI (filed as microsoft/vscode#119555). Note that if you enter longString into the DEBUG CONSOLE, it will be displayed as expected:
image

What the new dlv-dap mode does is consistent with what dlv cli does:

polina$ dlv debug foo.go 
Type 'help' for list of commands.
(dlv) c
...
(dlv) locals
longString = "\n\t{\n\t\t\"propName\": \"value\"\n\t}\n\t"
(dlv) p longString
"\n\t{\n\t\t\"propName\": \"value\"\n\t}\n\t"

A toggling option would have to be supported by both vscode UI (to get user input) and Debug Adapter Protocol (to communicate user setting to the adapter/debugger) for us to reconfigure this on the fly. I guess we could add a flag to launch.json configuration to configure this once for the duration of the session.

@polinasok
Copy link
Contributor

Btw, there are many related vscode issues, which link to more related issues and discussions. See especially microsoft/vscode#73845, which "changed that VS Code debugger to no longer escape whitespaces."

@polinasok polinasok added the upstream-vscode Issues that are by problems in VS Code itself. label Apr 5, 2021
@hyangah hyangah added FixedInDlvDapOnly and removed NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Apr 5, 2021
@hyangah
Copy link
Contributor

hyangah commented Apr 5, 2021

Since the new dlv dap mode escapes \n already, I propose to close this issue.
Toggling display options would be nice but I think we can address that separately when dlv dap is wildly used and there is a real demand.

@hyangah hyangah closed this as completed Apr 5, 2021
@mattwelke
Copy link
Author

Sorry I've been busy lately and never got around to trying the suggestions here to see if the new debugging stuff would work better. Is the conclusion here that the new debugging stuff will solve the DX problem I encountered by showing newline characters (literally \n) instead of omitting the portion of the string after the newline characters?

@polinasok
Copy link
Contributor

polinasok commented Apr 5, 2021

This is what things look like with experimental dlv-dap adapter:

image

@mattwelke
Copy link
Author

That's brilliant. Thanks. :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Debug Issues related to the debugging functionality of the extension. FrozenDueToAge upstream-vscode Issues that are by problems in VS Code itself.
Projects
None yet
Development

No branches or pull requests

4 participants