gpt4 book ai didi

go - 在 Delve 中通过源文件设置断点

转载 作者:数据小太阳 更新时间:2023-10-29 03:34:12 29 4
gpt4 key购买 nike

如何通过源文件设置断点?我在 tmp.go 文件中有以下代码。

package main

func main() {
a, b := 1, 2
c := a + b
println(c)

这行得通

$ dlv debug ./tmp.go
(dlv) b main.main:1
Breakpoint 1 set at 0x105395d for main.main() ./tmp.go:4

但这失败了

$ dlv debug ./tmp.go
(dlv) b ./tmp.go:4
Command failed: Location "./tmp.go:4" not found

编辑:这行得通

$ dlv debug ./tmp.go
(dlv) b tmp.go:4
Breakpoint 1 set at 0x105395d for main.main() ./tmp.go:4

知道我的环境可能出了什么问题吗?

最佳答案

Any ideas what might be wrong with my environment?


Why should this question be closed?

off-topic because...

Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example.

您没有提供 MCVE,所以我们只能猜测。

我们不知道您的 main.go 中有什么,所以您希望我们如何知道您的问题是什么?


例如,只是猜测,使用 MCVE,

main.go:

package main

func main() {
a, b := 1, 2
c := a + b
println(c)
}

Playground :https://play.golang.org/p/i2D9uZnFlXn

输出:

$ go run main.go
3
$ dlv debug ./main.go
Type 'help' for list of commands.
(dlv) break main.main:4
Breakpoint 1 set at 0x454bda for main.main() ./main.go:7
(dlv) quit
$ dlv debug ./main.go
Type 'help' for list of commands.
(dlv) break main.go:4
Breakpoint 1 set at 0x454b9d for main.main() ./main.go:4
(dlv) quit
$

break main.main:4break main.go:4 不是一回事,在 ./main.go:7./main.go:4 分别。行号与文件、函数等相关。


关于go - 在 Delve 中通过源文件设置断点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53453860/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com