A Few Quick Notes on Debugging With Delve

A Few Quick Notes on Debugging With Delve

My employment depends on me writing a lot of Go, seems like a good idea to become familiar with the tools that make writing Go easier. A few weeks back I spent an afternoon learning how to be more effective with the debugger. Being more comfortable with πšπš•πšŸ\texttt{dlv} has already been useful in tracking down a couple tricky bugs. Here are a few notes on using πšπš•πšŸ\texttt{dlv}.

go install github.com/go-delve/delve/cmd/dlv@latest && PATH=$PATH:$(go env GOPATH)/bin

You can stop reading here if you’d like. The next few bullets are just a TLDR from the video. The TLDR of the TLDR is that help will do you a lot of good.

Delve has a server that you can attach to by exposing additional ports in your container image. Not ideal IMO. One can pass the following arguments to 𝙲𝙼𝙳\texttt{CMD} to do this. I’m told the following integrates better with IDEs, etc.

  CMD ["/dlv", "--listen=:40000", 
      "--backend=default", "--headless=true", 
      "--api-version=2", "--accept-multiclient", 
      "exec", "/bin/main"
  ]

I’d need to read up a bit more on system capabilities. One can run docker with --sysctl ${cap}, but granting container code admin access to the host seems like a disaster in the making…