如何在Windows 10操作系统上使用Bazel调试C ++代码 [英] How to debug c++ code using Bazel on Windows 10 OS
问题描述
最近我开始玩Bazel,并且在调试应用程序时遇到问题,我可以使用 g ++ 进行调试,但不能调试生成的 Bazel . exe文件.
Recently I start to play with the Bazel and I face a problem with debugging the app, I can debug with g++ but I can't debug the Bazel generated .exe file.
谢谢您的关注.
此外,我使用Bazel和VsCode任务构建源代码.
Also, I build the source code with the Bazel and VsCode tasks.
- 我应该针对哪个.exe文件调试我的应用程序?
- 我的设置可以吗?
- 可以在Windows上使用Bazel调试c ++源代码.?
- 我应该使用minGW调试bazel生成的可执行文件还是一些 othertools或debuggers ??
- What .exe file should I target to debug my application?
- Is my setup Ok.?
- It is possible to debug a c++ source code using Bazel on Windows.?
- Should I use minGW for debugin a bazel generated executable or some othertools or debuggers.?
版本
- 操作系统:Windows 10
- Bazel版本:构建标签:0.20.0
|-- CPP_TESTS
|-- .gitignore
|-- a.exe <-- I generated this with g++ minGW
|-- readme.md
|-- WORKSPACE
|-- .vscode
| |-- c_cpp_properties.json
| |-- launch.json
| |-- settings.json
| |-- tasks.json
|-- project
|-- WORKSPACE
|-- main
|-- app.cc
|-- BUILD
|-- readme.md
#include <iostream>
int main(int argc, char const *argv[])
{
int a = 3;
int b = 5;
int c = a + b;
/* code */
std::cout << "Hello world" << std::endl;
std::cout << c << std::endl;
return 0;
}
内置文件
cc_binary(
name = "app",
srcs = ["app.cc"]
)
然后在./CPP_TESTS的根目录上运行此命令
And then I run this command on the root of the ./CPP_TESTS
bazel build //project/main:app
此命令将生成一些文件和文件夹
this command will generate some files and folders
某些文件夹包含app.exe文件,例如在 bazel-bin 目录我有此文件和文件夹
Some of the folders contain the app.exe file for example inside the bazel-bin dir I have this files and folder
|-- bazel-bin
|-- project
| |-- main
| |-- app.exe
| |-- app.exe-2.params
| |-- app.exe.runfiles_manifest
| |-- app.pdb
| |-- app.exe.runfiles
| | |-- MANIFEST
| |-- _objs
| |-- app
| |-- app.obj
|-- project-name
|-- main
|-- app.exe
|-- app.exe-2.params
|-- app.exe.runfiles_manifest
|-- app.pdb
|-- app.exe.runfiles
| |-- MANIFEST
|-- _objs
|-- app
|-- app.obj
所以如果我在
so If I run the app.exe inside the
|-- bazel-bin
|-- project
| |-- main
| |-- app.exe <=========
我得到这个输出
I get this output
INFO: Elapsed time: 0,145s, Critical Path: 0,01s
INFO: 0 processes.
INFO: Build completed successfully, 1 total action
INFO: Build completed successfully, 1 total action
Hello world
8
PS C:\dev\tests\cpp_tests>
如果我调试应用程序,则会出现此错误.
if I debug the app I get this error.
开始之前,这是我的 tasks/json
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "bazel_run",
"type": "shell",
"command": "bazel run //project/main:app",
"args": [],
"group": {
"kind": "build",
"isDefault": true
}
},
{
"label": "bazel_build",
"type": "shell",
"command": "bazel build //project/main:app",
"args": [],
"group": {
"kind": "build",
"isDefault": true
}
},
{
"label": "bazel_debug_build",
"type": "shell",
"command": "bazel",
"args": [
"build",
"//project/main:app",
"--compilation_mode=dbg"
],
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": [
"$gcc"
]
}
]
}
launch.json
{
// 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": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
// "program": "${workspaceFolder}/a.exe",
"program": "${workspaceFolder}\\bazel-bin\\project\\main\\app.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "C:/MinGW/bin/gdb.exe",
"preLaunchTask": "bazel_debug_build",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
所以我运行
bazel build //project/main:app
命令
错误消息.
但是app.exe在吗?
But the app.exe is there?
推荐答案
您应使用构建文件夹bazel-out/x64_windows-dbg/project/main/app.exe
中的可执行文件.
You should use the executable located in the build folder bazel-out/x64_windows-dbg/project/main/app.exe
.
如果要设置断点,则可能还需要--strip=never
参数.
If you are setting breakpoints, you may need the --strip=never
argument as well.
如果它不起作用,请尝试使用"cppvsdbg".而不是"cppdbg"作为 launch.json 中的配置类型.
If it does not work, try "cppvsdbg" rather than "cppdbg" as configuration type in your launch.json.
这篇关于如何在Windows 10操作系统上使用Bazel调试C ++代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!