如何通过Delve中的源文件行号设置断点?

ben*_*bot 7 debugging go delve

标题基本概括了所有内容.

我知道如何设置一个的唯一方法是在程序运行期间或之前 breakpoint main.main

有没有办法可以通过行号来做到这一点breakpoint ./otherfile.go:200

Ale*_*ret 19

在您的源代码类型中

  runtime.Breakpoint()
Run Code Online (Sandbox Code Playgroud)

在CLI中输入

dlv测试

然后

继续

程序将在您设置断点的代码行中停止.


小智 5

以下内容在 delve 中有效:

(dlv) break <breakpoint_name> <filename_pattern>:<line_number>
Run Code Online (Sandbox Code Playgroud)

如果你有不明确的文件名,比如main.go遍布你的源代码和可能的供应商目录,只要让它看起来“独一无二”就可以深入研究(filename_pattern 不是你的确切文件位置)。例如:

(dlv) break myLoopingStuff project_name/loops.go:30
(dlv) condition myLoopingStuff thing == someOther.thing
Run Code Online (Sandbox Code Playgroud)