调试Go应用程序时断点无法停止的问题

huangapple go评论92阅读模式
英文:

debugging go application doesn't stop at breakpoints

问题

我有最新的IntelliJ Ultimate EAP和最新的Gogland,这个问题在MacOS Sierra上的两个版本都出现了。

我正在尝试通过为Go Application创建一个调试配置来调试一个Go应用程序,Run Kind被配置为Package,其中包含当前项目的包名。

Go tool arguments下,我配置了-ldflags="-linkmode internal"

当我在有一些断点的情况下启动调试会话时,它会运行,但不会在这些断点处停止。

我漏掉了什么?

谢谢

更新

好的,我能够使用以下项目重现这个问题:

test1.go包含:

package main

const Numb uint64 = 5

test2.go包含:

package main

import "fmt"

func main() {
    fmt.Println(Numb);
}

我创建了一个名为Go Application的运行/调试配置,具有以下参数:

运行类型:package
包:github.com/kfirufk/test
工作目录:/usr/local/Cellar/go/1.8.1/src/github.com/kfirufk/test/

当我在test2.go的第6行(main函数的第一行代码)选择一个断点并启动调试会话时,我看到以下输出:

"/Users/ufk/Library/Application Support/IntelliJIdea2017.1/Go/lib/dlv/mac/dlv" --listen=localhost:53111 --headless=true exec /private/var/folders/cn/n7rwdd_95_l54s3zdnbxvw040000gn/T/Unnamedgo --
GOROOT=/usr/local/Cellar/go/1.8.1/libexec
GOPATH=/usr/local/opt/go
/usr/local/Cellar/go/1.8.1/libexec/bin/go build -o /private/var/folders/cn/n7rwdd_95_l54s3zdnbxvw040000gn/T/Unnamedgo -gcflags "-N -l" github.com/kfirufk/test
API server listening at: 127.0.0.1:53111
5

我正确地得到了程序的输出,但Intellij没有在所需的断点处停止。

这个问题在Intellij 2017.1.3和Go Lang插件0.171.1928上的MacOS Sierra 10.12.4上重现。

更新

尝试使用Intellij的delve来更好地理解发生了什么:

/Users/ufk/Library/Application\ Support/IntelliJIdea2017.1/intellij-go/lib/dlv/mac/dlv exec ./test

然后我执行了:

(dlv) step

并收到了:

Command failed: could not find FDE for PC 0x78bc000

我是没有理解如何使用delve还是有什么地方出了问题?

更新

是的,使用continue,调试器可以正常工作,无论是从homebrew安装的版本还是Intellij的版本。但是Intellij仍然没有在断点处停止。我在test2.go的打印变量的那一行创建了一个断点。

有什么想法吗?

英文:

I have latest IntelliJ Ultimate EAP and latest Gogland and the problem occurs on both under MacOS Sierra.

I'm trying to debug a go application by creating a debug profile for Go Application and the Run Kind is configured to Package, which contains the package name of the current project.

under Go tool arguments I have -ldflags="-linkmode internal" configured.

When I start a debug session while having some breakpoints, it would run but not stop at these breakpoints.

what am I missing?

thanks

update

ok I was able to reproduce the issue with the following project:

test1.go contains:

package main

const Numb uint64 = 5

test2.go contains:

package main

import "fmt"

func main() {
    fmt.Println(Numb);
}

I Created a Go Application run/debug configuration with the following parameters:

Run kind: package
Package: github.com/kfirufk/test
Working Directory: /usr/local/Cellar/go/1.8.1/src/github.com/kfirufk/test/

when I choose a breakpoint on test2.go line 6 (the first and only line of code in the main function) and I start a debug session, I see the following output:

"/Users/ufk/Library/Application Support/IntelliJIdea2017.1/Go/lib/dlv/mac/dlv" --listen=localhost:53111 --headless=true exec /private/var/folders/cn/n7rwdd_95_l54s3zdnbxvw040000gn/T/Unnamedgo --
GOROOT=/usr/local/Cellar/go/1.8.1/libexec
GOPATH=/usr/local/opt/go
/usr/local/Cellar/go/1.8.1/libexec/bin/go build -o /private/var/folders/cn/n7rwdd_95_l54s3zdnbxvw040000gn/T/Unnamedgo -gcflags "-N -l" github.com/kfirufk/test
API server listening at: 127.0.0.1:53111
5

I get the program's output properly but Intellij did not stop in the required breakpoint.

the problem is reproduced on Intellij 2017.1.3 with Go Lang Plugin 0.171.1928 on MacOS Sierra 10.12.4.

update

trying to play with intellij's delve to try to understand better what's going on:

/Users/ufk/Library/Application\ Support/IntelliJIdea2017.1/intellij-go/lib/dlv/mac/dlv exec ./test

then I executed:

(dlv) step

and received:

Command failed: could not find FDE for PC 0x78bc000

did I fail to understand how to use delve or is something doesn't work properly here ?

update

yeap.. with continue the debugger works properly with both versions of delve (installed from homebrew and the intellij's version). but still intellij works the same, doesn't stop at breakpoints. i create a breakpoint at test2.go at the line when I print the variable.

any ideas ?

答案1

得分: 5

好的,以下是翻译好的内容:

好的,我终于明白了。我把GOROOT结构和GOPATH结构搞混了,我把我的项目放在了GOROOT而不是GOPATH中。

这是我解决问题的步骤

我使用以下环境变量完全删除了go:brew uninstall --force go,然后重新安装go,并设置了以下环境变量:

export GOPATH=$HOME/golang
export GOROOT=/usr/local/opt/go/libexec
export PATH=$PATH:$GOPATH/bin
export PATH=$PATH:$GOROOT/bin

然后我把我的项目放在了~/golang/src/github.com/kfirufk/windy-server路径下。

最终,我终于能够正确地调试go应用程序了。

感谢大家的帮助! 调试Go应用程序时断点无法停止的问题

英文:

Ok.. I finally got it. I got mixed up with the GOROOT structure and GOPATH structure and I placed my project in GOROOT instead of GOPATH.

this is what I did to resolve the issue

I completely deleted go with brew uninstall --force go, then reinstalled go with the following environment variables:

export GOPATH=$HOME/golang
export GOROOT=/usr/local/opt/go/libexec
export PATH=$PATH:$GOPATH/bin
export PATH=$PATH:$GOROOT/bin

then I placed my project at ~/golang/src/github.com/kfirufk/windy-server

and I was finally able to properly debug go applications.

thank you all for assisting me! 调试Go应用程序时断点无法停止的问题

答案2

得分: 2

我明白了,以下是翻译好的内容:

同样的问题。

GoLand 2022.3.2 版本 #GO-223.8617.58,构建于2023年1月27日

降级 Go 版本到 1.19.7 以修复。

英文:

Same issue here.

GoLand 2022.3.2 Build #GO-223.8617.58, built on January 27, 2023

Downgrade Go to 1.19.7 version to fix.

答案3

得分: 1

对于我的情况(在Ubuntu 20.04上使用VSCode),如果项目位于符号链接目录内(或符号目录的子目录),VSCode将显示“未验证”的断点,并且会出现“在创建断点时出错:找不到文件...”的错误,导致断点无法停止。

使用以下命令可以解决该问题:

cd readlink -f <项目目录> && code .

这样就可以正常运行了。

英文:

For my case (VSCode on Ubuntu 20.04), if the project is inside a symbolic link directory (or sub-dir of a symbolic dir), vscode will shows "unverified" breakpoints and

> "Error on CreateBreakpoint: could not find file ..."

which leads to not stop on breakpoints.

cd \`readlink -f &lt;project dir&gt;\` &amp;&amp; code . 

will be ok.

答案4

得分: 0

对于我来说,问题已经解决,添加以下内容:

export GOROOT="/usr/local/go"

到 $HOME/.profile。

编辑:
我正在使用 LiteIde X35.2,带有 Delve 调试器
版本:1.1.0
构建:$Id: 1990ba12450cab9425a2ae62e6ab988725023d5c $

在以下环境下:
> DISTRIB=LinuxMint VERSION=18.3 CODENAME=sylvia
>
> RELEASE=#41~16.04.1-Ubuntu SMP Wed Oct 10 20:16:04 UTC 2018
> UBUNTU_CODENAME=xenial KERNEL=4.15.0-38-generic HDWPLATFORM=x86_64
>
> DESKTOP_SESSION=XFCE WINDOWS_MANAGER=XFWM4
> DESKTOP_COMPONENTS=kdevtmpfs gnome-keyring-d xfce4-session xfce4-panel
> xfce4-volumed polkit-gnome-au xfce4-power-man xfce4-terminal
> gnome-pty-helpe
>
> GTK=libgtk-3-0:amd64 3.18.9-1ubuntu3.3 GStreamer=gst-launch-1.0
> version 1.8.3 GStreamer 1.8.3
> https://launchpad.net/distros/ubuntu/+source/gstreamer1.0

英文:

For me, issue resolved adding:

export GOROOT=&quot;/usr/local/go&quot;

to $HOME/.profile.

EDIT:
I'm using LiteIde X35.2, with Delve Debugger
Version: 1.1.0
Build: $Id: 1990ba12450cab9425a2ae62e6ab988725023d5c $

under:
> DISTRIB=LinuxMint VERSION=18.3 CODENAME=sylvia
>
> RELEASE=#41~16.04.1-Ubuntu SMP Wed Oct 10 20:16:04 UTC 2018
> UBUNTU_CODENAME=xenial KERNEL=4.15.0-38-generic HDWPLATFORM=x86_64
>
> DESKTOP_SESSION=XFCE WINDOWS_MANAGER=XFWM4
> DESKTOP_COMPONENTS=kdevtmpfs gnome-keyring-d xfce4-session xfce4-panel
> xfce4-volumed polkit-gnome-au xfce4-power-man xfce4-terminal
> gnome-pty-helpe
>
> GTK=libgtk-3-0:amd64 3.18.9-1ubuntu3.3 GStreamer=gst-launch-1.0
> version 1.8.3 GStreamer 1.8.3
> https://launchpad.net/distros/ubuntu/+source/gstreamer1.0

答案5

得分: 0

在我的情况下,该进程已经在该端口上运行,并且没有关闭。因此,我不得不手动停止该进程,并从IntelliJ重新运行。

英文:

In my case, the process was already running at that port and didn't close. So I had to manually stop the process and run again from IntelliJ.

答案6

得分: 0

在我的情况下(GoLand),问题出在我的调试配置中未设置-trimpath标志:

  1. "运行","调试...","编辑配置"。
  2. 在模板项中,转到"Go Test"选项,并在"Go工具参数"中添加参数-trimpath

你也可以在环境中设置:

go env -w GOFLAGS="-trimpath"

这对于"附加到进程"的调试选项也适用。

你可以在菜单"帮助","显示日志文件"中查看GoLand IDE的日志。这将使你的生活更轻松。

参考:https://youtrack.jetbrains.com/issue/GO-8277

英文:

In my case (GoLand), the problem was with the flag -trimpath not being set in my debug configurations:

  1. "Run", "Debug...", "Edit Configurations."
  2. In the templates item, go to "Go Test" option and add the argument -trimpath in "Go tool arguments"

You can also set in your environment with:

go env -w GOFLAGS=&quot;-trimpath&quot;

That also works for the "attach to process" debugging option.

You can see GoLand IDE Logs in the menu "Help", "Show Log Files". It will make your life easier.

Reference: https://youtrack.jetbrains.com/issue/GO-8277

huangapple
  • 本文由 发表于 2017年5月18日 13:01:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/44038930.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定