如何在 visual studio 代码中调试 bazel c++ google 测试
how to debug bazel c++ google test in visual studio code
我有 Visual Studio 代码,我使用这样的命令构建的 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 测试安装了插件,但它没有看到它们并且没有 gtest.exe.
谢谢!
使用 Google 测试适配器插件时,以下步骤对我有用。去Debug -> Add Configuration...
给你的launch.json
文件添加一个新的launch target,在"program"
下填入程序路径(注意我这里不能用相对路径,所以也许你需要填写完整路径):
{
// 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" 的栏中(带有所有 运行 和停止按钮)按下双箭头 <->
并在上面的调试配置上设置挂钩。现在按 Run All
应该可以正常工作了。
让我知道它是否有效,如果无效,哪些步骤无效。
我有 Visual Studio 代码,我使用这样的命令构建的 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 测试安装了插件,但它没有看到它们并且没有 gtest.exe.
谢谢!
使用 Google 测试适配器插件时,以下步骤对我有用。去Debug -> Add Configuration...
给你的launch.json
文件添加一个新的launch target,在"program"
下填入程序路径(注意我这里不能用相对路径,所以也许你需要填写完整路径):
{
// 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" 的栏中(带有所有 运行 和停止按钮)按下双箭头 <->
并在上面的调试配置上设置挂钩。现在按 Run All
应该可以正常工作了。
让我知道它是否有效,如果无效,哪些步骤无效。