Running distrobuilder with delve

I’m trying to get distrobuilder up and running in Visual Studio Code and debug it with delve, but crashes when trying stop at a breakpoint. I’m not sure if I’m missing a build argument I should be passing to delve when it builds the binary for debugging or if this isn’t expected to work for one reason or another.

  1. go get ./distrobuilder
  2. sudo -E ~/go/bin/dlv debug --headless --api-version 2 --listen 127.0.0.1:2345 --only-same-user=false ./distrobuilder -- --help
  3. In VSCode, create a launch configuration as follows: { "name": "Connect to server", "type": "go", "request": "attach", "mode": "remote", "port": 2345, "host": "127.0.0.1" }
  4. Set a breakpoint in VSCode
  5. Connect to the remote debugging session.

It crashes with a stacktrace:

API server listening at: 127.0.0.1:2345
SIGTRAP: trace trap
PC=0xd44453 m=0 sigcode=128

goroutine 1 [running]:
main.main()
	/home/link/go/src/github.com/lxc/distrobuilder/distrobuilder/main.go:91 +0x33 fp=0xc00021ff88 sp=0xc00021fc70 pc=0xd44453
runtime.main()
	/usr/lib/go-1.14/src/runtime/proc.go:203 +0x1c8 fp=0xc00021ffe0 sp=0xc00021ff88 pc=0x43df38
runtime.goexit()
	/usr/lib/go-1.14/src/runtime/asm_amd64.s:1373 +0x1 fp=0xc00021ffe8 sp=0xc00021ffe0 pc=0x46e681

rax    0xc00021fcf0
rbx    0x14
rcx    0xc000000180
rdx    0xeed9a8
rdi    0xc000355678
rsi    0xd0
rbp    0xc00021ff78
rsp    0xc00021fc70
r8     0x1a
r9     0x1a
r10    0x7fa5f598bab6
r11    0x0
r12    0x203000
r13    0x0
r14    0xd0
r15    0x2a
rip    0xd44453
rflags 0x202
cs     0x33
fs     0x0
gs     0x0

Is this to be expected?

It appears that running dlv and setting a breakpoint in the console does the same thing.

sudo -E ~/go/bin/dlv debug ./distrobuilder -- --help                              
Type 'help' for list of commands.
(dlv) break main.main
Breakpoint 1 set at 0xd4443b for main.main() ./distrobuilder/main.go:89
(dlv) c
SIGTRAP: trace trap
PC=0xd4443c m=0 sigcode=128

goroutine 1 [running]:
main.main()
	/home/link/go/src/github.com/lxc/distrobuilder/distrobuilder/main.go:89 +0x1c fp=0xc00029ff88 sp=0xc00029ff80 pc=0xd4443c
runtime.main()
	/usr/lib/go-1.14/src/runtime/proc.go:203 +0x1c8 fp=0xc00029ffe0 sp=0xc00029ff88 pc=0x43df38
runtime.goexit()
	/usr/lib/go-1.14/src/runtime/asm_amd64.s:1373 +0x1 fp=0xc00029ffe8 sp=0xc00029ffe0 pc=0x46e681

rax    0xc00029fcf0
rbx    0xb5
rcx    0xc000000180
rdx    0xeed9a8
rdi    0xc000176258
rsi    0x0
rbp    0xc00029ffd0
rsp    0xc00029ff80
r8     0xfc
r9     0x0
r10    0x0
r11    0x202
r12    0x203000
r13    0x0
r14    0xc8
r15    0x2c
rip    0xd4443c
rflags 0x202
cs     0x33
fs     0x0
gs     0x0
Process 58216 has exited with status 2