如何在Delve中使用init-command设置断点

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

How to set breakpoint in Delve with an init-command

问题

在GDB中,有一个--init-command标志,我可以定义一个命令,比如b dbConnection,它会在运行项目后自动应用。它在dbConnection函数上设置断点。

我在Delve中寻找类似的功能,但是我找不到。
整个想法是,不是先运行dlv命令,然后告诉它我的函数在哪里,并在那里设置断点,而是在运行dlv之前,将函数名作为初始化命令,比如break pkg/db/connection.go:dbConnection。我可以运行fzf命令轻松找到文件,然后将其传递给dlv的初始化命令,以在那里设置断点。

英文:

In GDB, there is a flag --init-command which I can define a command like b dbConnection and it will be applied automatically after running the project. It sets the breakpoint on the dbConnection function.

I was looking for the same in Delve but I couldn't find it.
The whole idea is instead of running dlv command and then telling where is my function and set the breakpoint there, I wanna give the function name before running dlv as init command like break pkg/db/connection.go:dbConnection. I can run fzf command to find the file easily and then I'll pass it to the dlv init command to set the breakpoint there.

答案1

得分: 1

这是答案的链接:https://github.com/go-delve/delve/discussions/3189

标志是 --init。例如:

dlv debug --init <(echo b main.main)
英文:

Here is the answer https://github.com/go-delve/delve/discussions/3189

The flag is --init. For example:

dlv debug --init <(echo b main.main)

huangapple
  • 本文由 发表于 2022年11月13日 05:53:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/74416875.html
匿名

发表评论

匿名网友

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

确定