go-delve / delve

Delve is a debugger for the Go programming language.
MIT License
22.72k stars 2.13k forks source link

Delve debugger not working on VS Code - panic: assignment to entry in nil map #3120

Closed junhee071 closed 2 years ago

junhee071 commented 2 years ago

Please answer the following before submitting your issue:

Note: Please include any substantial examples (debug session output, stacktraces, etc) as linked gists.

If this is about source listing not showing up (or breakpoints not being accepted) while running in a container please read our FAQ first.

  1. What version of Delve are you using (dlv version)? Delve Debugger Version: 1.9.0 Build: $Id: 69310c2f438e492f892d6af22e8e62c8ea1e9d8d

  2. What version of Go are you using? (go version)?

go version go1.19 darwin/arm64

  1. What operating system and processor architecture are you using? macOS monterey V12.5.1

4 What did you do? using visual studio code, set a breakpoint in unit test file, hit "debug test".

  1. What did you expect to see? debugger to start and execute and stop at the breakpoint

  2. What did you see instead? test runs all the way through, debugger does not stop at breakpoint and shows this output instead: 2022-08-24T14:36:56-07:00 error layer=dap recovered panic: assignment to entry in nil map goroutine 18 [running]: runtime/debug.Stack() /usr/local/go/src/runtime/debug/stack.go:24 +0x64 github.com/go-delve/delve/service/dap.(Session).recoverPanic(0x1400023e000, {0x104ea2bb8, 0x14000c3c4b0}) /Users/go/pkg/mod/github.com/go-delve/delve@v1.9.0/service/dap/server.go:559 +0x48 panic({0x104e099e0, 0x104ea1808}) /usr/local/go/src/runtime/panic.go:890 +0x258 github.com/go-delve/delve/service/debugger.createLogicalBreakpoint(0x1400018a790, {0x1400277adb8, 0x1, 0x61?}, 0x14000afd4e8, 0x0) /Users/go/pkg/mod/github.com/go-delve/delve@v1.9.0/service/debugger/debugger.go:719 +0x118 github.com/go-delve/delve/service/debugger.(Debugger).CreateBreakpoint(0x1400018a790, 0x14000afd4e8) /Users/go/pkg/mod/github.com/go-delve/delve@v1.9.0/service/debugger/debugger.go:683 +0x1e4 github.com/go-delve/delve/service/dap.(Session).setBreakpoints(0x1400023e000, {0x14001f8e280?, 0x14000afd6a0?}, 0x1, 0x14000afd6d0, 0x14000afd6b0) /Users/go/pkg/mod/github.com/go-delve/delve@v1.9.0/service/dap/server.go:1386 +0x388 github.com/go-delve/delve/service/dap.(Session).onSetBreakpointsRequest(0x140020830e0?, 0x14000c3c4b0) /Users/go/pkg/mod/github.com/go-delve/delve@v1.9.0/service/dap/server.go:1275 +0xf8 github.com/go-delve/delve/service/dap.(Session).handleRequest(0x1400023e000, {0x104ea2bb8?, 0x14000c3c4b0?}) /Users/go/pkg/mod/github.com/go-delve/delve@v1.9.0/service/dap/server.go:727 +0x13f8 github.com/go-delve/delve/service/dap.(Session).ServeDAPCodec(0x1400023e000) /Users/go/pkg/mod/github.com/go-delve/delve@v1.9.0/service/dap/server.go:545 +0x2bc github.com/go-delve/delve/service/dap.(Server).runSession(0x140003140c0, {0x10ca64048?, 0x14000222010?}) /Users/go/pkg/mod/github.com/go-delve/delve@v1.9.0/service/dap/server.go:482 +0x148 github.com/go-delve/delve/service/dap.(Server).Run.func1() /Users/go/pkg/mod/github.com/go-delve/delve@v1.9.0/service/dap/server.go:474 +0xa8 created by github.com/go-delve/delve/service/dap.(*Server).Run /Users/go/pkg/mod/github.com/go-delve/delve@v1.9.0/service/dap/server.go:456 +0x68

I saw this issue with a similar error about the nil map - https://github.com/go-delve/delve/issues/3114 That issue has apparently been resolved, and I've reinstalled delve at the tree head with this command - go install github.com/go-delve/delve/cmd/dlv@master, with no luck

aarzilli commented 2 years ago

The stacktrace says you are still using v1.9.0 so you have to reinstall harder.

aarzilli commented 2 years ago

Also can you build a hello world program with go build -gcflags='-N -l' and send over the binary?

junhee071 commented 2 years ago

hey, i've installed version 1.9.1 and no longer see the nil map error. however, the debugger still does not work (does not stop at a breakpoint and simply runs the unit test fully).

here's the end of the debug console output when i run a unit test: Info 2022-08-29 11:57:49,996 v1(7) utils.go:205 192.168.1.163 - 20220829115749192168001163981D9CA default - 0 line no.: signal_handler.go:86 [func: server.syncSignal] ignoring event: event PASS Process 83715 has exited with status 0 Detaching dlv dap (83681) exited with code: 0

i've attached a hello world program binary here: main.zip

aarzilli commented 2 years ago

The hello world binary looks fine. Can you set a breakpoint on the main function and debug it?

junhee071 commented 2 years ago

I set a breakpoint in the main function, hit debug in vs code, and the function simply runs to full execution: heres the debug console output:

DAP server listening at: 127.0.0.1:56958 Type 'dlv help' for list of commands. hello world Process 86168 has exited with status 0 Detaching dlv dap (86147) exited with code: 0

aarzilli commented 2 years ago

I'd like to see dap logs, or maybe try doing it using dlv directly.

emanuelef commented 2 years ago

Hi, I'm experiencing the same issue with exactly the same environment. Go: go1.19 darwin/arm64 Delve: 1.9.0 macOS: Monterey V12.5.1 VSC: Version: 1.70.2 (Universal)

junhee071 commented 2 years ago

I'm trying to debug/set bps in unit test files using the delve command line. i've had success with "normal" unit test files. but some of my unit test files use the library gomonkey ("github.com/agiledragon/gomonkey") for function patching purposes.

To test a unit test, I do dlv test /absolutePathToPackageTestIsIn. This starts a dlv session, in which I enter 'b UnitTestName:60" to set a bp at line 60. I then get a undefinedBuildJmpDirective error (same error as here - https://github.com/agiledragon/gomonkey/issues/38)

To solve this error, I exit the dlv session, enter exportGOARCH=amd64 in my shell, then run: dlv test /absolutePathToPackageTestIsIn again. In the dlv session, I enter 'b UnitTestName:60", then get this error: cmnd failed: protocol error E09 during set bp for packet (same error as here - https://github.com/go-delve/delve/issues/1116). The recommended solution for this error is to `export GOARCH=arm64', but setting GOARCH to arm64 results in the FIRST error (the undefinedBuildJmpDirective error).

I've tried using v2 of the gomonkey package github.com/agiledragon/gomonkey/v2 with no luck.

wondering if you have any suggestions. thanks

aarzilli commented 2 years ago

I see. There's no way any of this could ever work with a debugger.

junhee071 commented 2 years ago

I see. There's no way any of this could ever work with a debugger.

So in the example I highlighted, delve debugger will not work? (no solution)

aarzilli commented 2 years ago

No, you can't debug amd64 executables on arm64 and you can't debug something that uses gomonkey unless you know very well what you are doing.