Delve: Unable to print local variables

Created on 30 Apr 2017  路  4Comments  路  Source: go-delve/delve

Please answer the following before submitting your issue:

  1. What version of Delve are you using (dlv version)?
Delve Debugger
Version: 0.12.2
Build: v0.12.2

  1. What version of Go are you using? (go version)?
    go version devel +0716fef Mon Dec 12 01:31:50 2016 +0000 darwin/amd64

  2. What operating system and processor architecture are you using?
    OSX, darwin/amd64

  3. What did you do?

  4. Created an executable using go install.
  5. dlv exex [binary name]
  6. Set breakpoint using b file.go:22
  7. Did n a few lines after a local variable x was initialized
  8. Tried printing x using p x

  9. What did you expect to see?
    The value of the local variable

  10. What did you see instead?
    Command failed: could not find symbol value for x

Most helpful comment

For Go 1.10+ you need to run -gcflags="all=-N -l" to have a better debug experience.

All 4 comments

You are not seeing the value of some local variables because the compiler is optimizing them away.
You should use dlv debug or dlv test to compile your code. If you build the executable yourself you should pass the option -gcflags='-N -l' to the compiler.

If you used delve to compile or remembered to use -gcflags='-N -l' and the missing local variables are in a package other than main you may be victim of this go bug. If this is the case your only option is to manually purge the offending packages from $GOPATH/pkg/.

Having run into this just now on Windows 10 with version go1.10.1, I had to use -gcflags '-N -l'
i.e. without the '=' .

Using VSCode, adding this to my launch.json causes all my local variables to appear:
"args": ["-gcflags '-N -l'"], , whereas
"args": ["-gcflags='-N -l'"], does not.

For Go 1.10+ you need to run -gcflags="all=-N -l" to have a better debug experience.

@dlsniper For Go 1.10+ -gcflags="-N -l" doesn't work well锛孻our answer is right锛宼hank you

Was this page helpful?
0 / 5 - 0 ratings