Konubinix' opinionated web of thoughts

Debug Golang Dap Dlv Delve Emacs

Fleeting

debug golang dap emacs

START by adding a breakpoint

then,

dlv debug –listen 127.0.0.1:2345 –headless ./cmd/something – options

(–accept-multiclient to allow several connections)

thrn dap-debuf “Go Dlv Remote Debug”

I can provide my own template to ease attaching to the debugger

Using

(dap-register-debug-template "test"
                             (list :type "go"
                                   :request "attach"
                                   :debugPort 2346
                                   :host "127.0.0.1"
                                   :name "My own template"
                                   :mode "remote"))

beware the symlinks

go dlv does not work well with symlinks

For instance, to debug kubernetes, where …/vendor/k8s.io is full of symlinks to …/staging/src/k8s.io

You could do something like

(dap-register-debug-template "test"
                             (list :type "go"
                                   :request "attach"
                                   :debugPort 2346
                                   :host "127.0.0.1"
                                   :name "My own template"
                                   :substitutePath: [(list :from
                                                           "${workspaceFolder}/staging/src/k8s.io"
                                                           :to
                                                           "${workspaceFolder}/vendor/k8s.io")]
                                   :mode "remote"))

So far, it does not work, so I just replaced the symlinks with “rsync -L”. This is not ideal, but I did not have time to dig deeper.

running in docker

(progn
  (load-library "dap-mode")
  (load-library "go-mode")
  (konix/dap-debug-with-mapping
   (list
    (list (string-trim (shell-command-to-string "go env GOROOT")) "/usr/lib/go")
    (list (string-trim (shell-command-to-string "go env GOPATH")) "/root/go")
    (list "<mysrc>" "/src")
    )
   (list :type "go" :request "attach" :mode "remote" :host "127.0.0.1" :debugPort 2345)
   )
  )