How can I set breakpoints by the sourcefile line number in Delve?

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

How can I set breakpoints by the sourcefile line number in Delve?

问题

标题基本上已经说明了一切。

我所知道的设置断点的唯一方法是在程序运行时或者在 breakpoint main.main 之前设置。

我能否通过行号来设置断点,例如 breakpoint ./otherfile.go:200

英文:

The title pretty much says it all.

The only way I know how to set one is either during the runtime of the program or just before with breakpoint main.main

Is there a way I can do this by line number like breakpoint ./otherfile.go:200?

答案1

得分: 40

在你的源代码中输入

  runtime.Breakpoint()

在命令行界面中输入

dlv test

然后输入

continue

程序将在设置断点的代码行停止。

英文:

In your Source code type

  runtime.Breakpoint()

type in the CLI

> dlv test

and then

> continue

The program will stop in the line of code where you set the breakpoint.

答案2

得分: 11

以下是在 delve 中有效的内容:

(dlv) break <断点名称> <文件名模式>:<行号>

如果你的文件名存在歧义,比如 main.go 分散在你的源代码和可能的供应商目录中,只需确保它在 delve 中看起来“唯一”(filename_pattern 不是你的确切文件位置)。例如:

(dlv) break myLoopingStuff project_name/loops.go:30
(dlv) condition myLoopingStuff thing == someOther.thing
英文:

The following is valid in delve:

(dlv) break &lt;breakpoint_name&gt; &lt;filename_pattern&gt;:&lt;line_number&gt;

If you have ambiguous filenames, say main.go spread all over your sources and possibly vendor directory, just make you make it look "unique" to delve (filename_pattern is not your exact file location). For example:

(dlv) break myLoopingStuff project_name/loops.go:30
(dlv) condition myLoopingStuff thing == someOther.thing

huangapple
  • 本文由 发表于 2016年3月8日 08:43:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/35856911.html
匿名

发表评论

匿名网友

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

确定