我有使用这样的命令构建的 Visual Studio Code、C++ bazel 测试
bazel test //tensorflow/lite/kernels:xxx_test --test_arg=gtest_filter=XXXTest -c dbg
然后我可以像这样使用 gdb 调试它
gdb ./bazel-bin/tensorflow/lite/kernels/xxx_test.runfiles/org_tensorflow/tensorflow/lite/kernels/xxx_test
但是这是在 VS Code 中正确调试它的另一种方法吗? 我安装了 Google Tests 插件,但它看不到它们,也没有 gtest.exe。
谢谢!
最佳答案
使用 Google Test Adapter 插件时,以下步骤对我有用。前往Debug -> Add Configuration...
将新的启动目标添加到您的 launch.json
文件并填写"program"
下的程序路径(请注意,相对路径在这里对我不起作用,所以也许您需要填写完整路径,编辑:正如评论中指出的,在路径帮助之前添加 $(workspaceFolder)
):
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "gtest",
"type": "cppdbg",
"request": "launch",
"program": "(maybe insert complete path)/bazel-bin/tensorflow/lite/kernels/xxx_test.runfiles/org_tensorflow/tensorflow/lite/kernels/xxx_test",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "",
"miDebuggerPath": "/usr/bin/gdb"
}
]
}
通过在代码中设置断点然后按 F5
检查是否可以正确调试应用程序.
如果有效,请转到 Google 测试适配器插件,并将鼠标悬停在左侧(通常显示可用测试的位置)以及显示“GOOGLE TESTS”的栏中(带有所有运行和停止按钮)按双箭头<->
并在上面的调试配置上设置 Hook 。现在按Run All
应该可以正常工作。
请告诉我它是否有效,如果无效,哪些步骤不起作用。
关于c++ - 如何在 Visual Studio 代码中调试 bazel c++ google test,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57825915/