英文:
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 <breakpoint_name> <filename_pattern>:<line_number>
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论