air icon indicating copy to clipboard operation
air copied to clipboard

Best Practice to work with delve

Open sharefantasy opened this issue 4 years ago • 13 comments

Hi, I'm looking for a better way to make air work with delve remote debugging. I setup up this param in full_bin

dlv exec --head --accept-multiclient --listen=127.0.0.1:6342 --continue

But during reloading delve reports an error of "address already in use".

Is there a best practice for delve debug config? Thanks! :)

sharefantasy avatar Jun 22 '20 03:06 sharefantasy

Sorry, I'm not familiar with dlv. Maybe others could help you. 😄

cosmtrek avatar Jun 22 '20 16:06 cosmtrek

We've been using the following:

full_bin = "dlv exec --continue --accept-multiclient --listen=:2345 --headless=true --api-version=2 --log ./tmp/app"

This is run within a docker container with port 2345 mapped to a host port. Host port is usually the same but depends on how many projects a dev runs simultaneously.

sokratisg avatar Jul 02 '20 08:07 sokratisg

I wrote a plugin of goland. it will auto reconnect debugger. https://github.com/xiantang/air-plugin and finally I will make a pull request to air. then we can use air smoothly.

xiantang avatar Aug 30 '20 16:08 xiantang

Hi @xiantang Im using Goland. Your plugin is ready for use ? I'm currently looking for use Air integrated to Goland

Metrakit avatar Sep 11 '20 10:09 Metrakit

EDIT:

Wrote a small tutorial to use Delve with Air and VSCode that worked for me: https://dev.to/andreidascalu/setup-go-with-vscode-in-docker-for-debugging-24ch

andrei-dascalu avatar Apr 28 '21 20:04 andrei-dascalu

嗯,看你标记的位置是广州,那,我就直接敲汉字吧。

提示的是端口被占用了

  • 使用netstat -antp | grep 6342看下是哪个进程占用了这个端口

实践

我是在找dlv的最佳实践,然后找到了这里,确切的说是dlv debug,写一下自己平时遇到的一些细节吧:

1. 传入参数

  • 使用--,后面接需要传给程序的参数;例如,服务启动时需要指定配置文件,形如:server -conf foo.yaml,就可以这样弄: dlv debug -- -conf ./foo.yaml 详见文档描述

2. 设置断点(存疑)

  • b ./main.go:15,在当前目录的main.go文件15行设置断点。我遇到的问题是:Command failed: could not find statement at,因为,设置断点的语法貌似是要指定文件路径,“错误的”写法是这样的b main.go:15

3. 重复上一个命令

  • 当我们想继续执行上一个执行的命令时(例如:n: Step over to next source line),可以在输入完命令、按回车后,直接按回车,就是执行上一个命令了。

4. 重启调试

  • restart (alias: r) ---------- Restart process,重启,很实用。

maliyan avatar Mar 08 '22 05:03 maliyan

full_bin = "dlv exec --continue --accept-multiclient --listen=:2345 --headless=true --api-version=2 --log ./tmp/app"

Hot reload not working with this command right now with @latest verison of cosmtrek/air package. With previous version of both (.air.toml and delve for debugging) works perfect (It was versions from 4 months ago, since I have pause with this project). When I remove it, hot reload works perfect. Does anyone have same issue ?

dusan91judo avatar Aug 31 '22 22:08 dusan91judo

I found solution. Do not use @latest tag for delve package. It can cause an issue. Use specific release version and it is working. Ex Docker. RUN go install github.com/cosmtrek/[email protected] && go install github.com/go-delve/delve/cmd/[email protected] Instead RUN go install github.com/cosmtrek/air@latest && go install github.com/go-delve/delve/cmd/dlv@latest

dusan91judo avatar Sep 01 '22 09:09 dusan91judo

Can't figure out a way of running this!

Can any one give me a hand?

I have a docker compose which uses the air image. I am trying to enable debugging on goland intellij IDE. But I cant get the remote to connect to the container

ShuttleSantalex avatar Jul 17 '23 04:07 ShuttleSantalex

@dusan91judo does your solution still work? Just started using a docker go setup and am getting the "port already in use" issues. Any particular versions you'd recommend?

Anyone else have a fix here?

casey-speer avatar Dec 13 '23 21:12 casey-speer

first kill that port in os. Then, try with specific version setup. It should work for [email protected] and [email protected]. My answer have more than a year, so for latest versions it might have some changes.

dusan91judo avatar Dec 14 '23 10:12 dusan91judo

@dusan91judo thank you. Yeah those versions are a bit old at this point, so I don't think they'll work with the go version I'm using. I'll play around though and see if I can find working versions or configuration.

casey-speer avatar Dec 14 '23 17:12 casey-speer