你可以使用gdb来调试Go测试。

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

how can I debug go tests with gdb

问题

我有一些Go的测试。我想用gdb进行调试。

但是由go test构建的二进制文件在运行后被丢弃了。

那么我该怎么做呢?

我的操作系统是Windows 64位,使用的是Go 1.6版本。

英文:

I have some go tests. I would like to debug with gdb.

But the binaries built by go test are thrown away after running.

So how do I do it?

go 1.6 on windows/64

答案1

得分: 4

你使用 go test -c 命令会生成可执行文件 xyz.test。然后你可以使用 gdb xyz.test 命令进行调试。

你可以查看 go test --help 来了解 -c 标志的说明:

编译测试二进制文件为 pkg.test,但不运行它
(其中 pkg 是包导入路径的最后一个元素)。
可以使用 -o 标志来更改文件名。

英文:

You use go test -c which will produce the executable file xyz.test. Afterwards you use gdb xyz.test to debug.

Just check go test --help for an explanation of the -c flag:

> Compile the test binary to pkg.test but do not run it
> (where pkg is the last element of the package's import path).
> The file name can be changed with the -o flag.

huangapple
  • 本文由 发表于 2016年3月26日 00:00:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/36223429.html
匿名

发表评论

匿名网友

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

确定