Go Delve (1.0.0-rc2) freezes on Windows after breakpoint hit

时间:2019-04-17 00:34:35

标签: go delve

I have recently been having a problem which essentially makes debugging Go using delve next to impossible. Basically I can't use breakpoints otherwise there is a good chance the debugged code freezes and all I can do is stop the debugger an restart.

To start at the beginning... I have had an intermittent problem debugging Go using GoLand IDE (2019.1) and delve (1.0.0-rc2) for some time. The whole session would freeze - I know that nothing is happening because the debugged process CPU usage is zero, and the fact that there are no messages being written to the log (I have many go-routines most of which are writing occasional log messages). It's as if a breakpoint was hit but the debugger commands (STEP, etc) are not enabled which indicates that the debugger is not at a breakpoint. When this happens I have to hit the GoLand STOP button twice to get the debugger to terminate and then start all over again.

Recently this problem has become far more common. From perhaps a few times a day to almost every debug session. This is annoying but at least it has allowed me to track down what I believe is the underlying problem. It seems that sometimes when a breakpoint is encountered the debugger stops but delve or the IDE does not realise that - so there is no way to continue.

How do I know this? I proved this to myself by setting a breakpoint on a log line (ie, log.Printf). When the breakpoint is on that line (and I know it will be hit) then the debug session freezes. If I ensure there are no breakpoints that will be hit then the program runs absolutely fine including printing the log line. If I set the (one and only) breakpoint on the line after log line the log line is printed and the session freezes.

I think this is a problem with delve. Note that I have loaded the same project into VSCode and the exactly the same thing happens (GoLand and VSCode use the same version of delve), so I don't think GoLand is doing anything wrong. But if someone has another explanation I welcome it.

I have tried a lot of things to track down the cause. I have created a small project in order to demonstrate the problem but it does not occur in a simple project. It appears that I am doing something wrong (in my large project) that causes delve to misbehave but I have no idea what that is.

1 个答案:

答案 0 :(得分:0)

首先,1.0.0-rc2似乎是德尔文(Delve)的重生:current version is 1.2.0

1.0.0-rc2太古老了,以至于2018年8月(issue 1318)报道了类似的错误,该错误无头地执行了delve:

dlv debug --headless ...

添加--log --log-output=rpc可以为您提供其他线索。

dlv debug --headless --listen=:2345 --api-version=2 --log --log-output=rpc ./test.go
  

以无头模式运行时,自己会忽略SIGINT。
  要停止无头实例,您必须连接到它,然后终止连接。
  要将SIGINT发送到目标程序,您必须启动目标程序,而不必启动目标程序,因为要启动目标程序,必须先连接到delve。