无法在GDB中设置断点,因为出现错误“没有名为model/page.go的源文件”。

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

Can't set breakpoint in GDB with Golang due to error "no source file named model/page.go"

问题

我正在尝试使用gdb调试一个Go程序,除了一个包之外,设置断点在所有包中都正常工作。在我的src文件夹中,有3个子文件夹,每个文件夹都包含一个包:

  • crawler/
    • crawler.go
  • model/
    • page.go
  • urlutils/
    • urlutils.go

我无法在page.go的任何行上设置断点,因为它给我返回以下错误信息:

(gdb) break model/page.go:14
No source file named model/page.go.
Make breakpoint pending on future shared library load? (y or [n])

我不明白为什么只有这个包会出现这种情况。"model/page"也是包含主函数的文件中的一个导入项,并且在程序运行时被使用,所以它必须在可执行文件中。有人有什么想法吗?

英文:

I am trying to debug a Go-program using gdb and setting breakpoints works normally in all packages, except for one. In my src-folder I have 3 subfolders that each contain packages:

  • crawler/
    • crawler.go
  • model/
    • page.go
  • urlutils/
    • urlutils.go

I cannot set a breakpoint in page.go on any line as it gives me the following error:

(gdb) break model/page.go:14
No source file named model/page.go.
Make breakpoint pending on future shared library load? (y or [n])

I do not understand why this is happening with only this one package. "model/page" is also an import in the file that contains the main function and is used when the program runs, so it must be in the executable. Does anyone have an idea?

答案1

得分: 3

我找到了一个解决方案:

我需要在我的go build命令中添加一个标志:

go build -gcflags "-N -l" launch.go

这将禁用go编译器执行的代码优化,从而使我的断点起作用。路径是正确的,绝对路径也不起作用。

不过,还是要感谢tomwilde指引我朝一个方向。

英文:

I found a solution:

I needed to add a flag to my go build command:

go build -gcflags "-N -l" launch.go

This disables the code optimization performed by the go compiler which lead to my breakpoint working. The paths were correct and also the absolute path didn't work.

Nevertheless, thank you tomwilde for pointing me into a direction.

huangapple
  • 本文由 发表于 2013年10月15日 17:46:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/19378021.html
匿名

发表评论

匿名网友

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

确定