调试C++;在MacOS上使用Bazel构建代码时不起作用 我在VisualStudio代码中用BaZelBug系统启动了一个C++项目。但是,当二进制文件是使用Bazel构建时,调试在IDE中不起作用

调试C++;在MacOS上使用Bazel构建代码时不起作用 我在VisualStudio代码中用BaZelBug系统启动了一个C++项目。但是,当二进制文件是使用Bazel构建时,调试在IDE中不起作用,c++,macos,visual-studio-code,bazel,C++,Macos,Visual Studio Code,Bazel,使用clang++-g main.cpp-o sample构建应用程序时,我可以调试该应用程序 我的设置: 操作系统:MacOS,Bazel:release 0.17.2-homebrew,VS代码:1.27.2 这是由Bazel的编译方式造成的。是否有任何解决方法使调试工作正常 这里是一个最小的例子。只需在编辑器中放置一个断点,运行调试,并观察未命中的断点: ├── .vscode │   ├── launch.json │   └── tasks.json ├── BUILD ├── WOR

使用
clang++-g main.cpp-o sample构建应用程序时,我可以调试该应用程序

我的设置: 操作系统:MacOS,Bazel:release 0.17.2-homebrew,VS代码:1.27.2

这是由Bazel的编译方式造成的。是否有任何解决方法使调试工作正常

这里是一个最小的例子。只需在编辑器中放置一个断点,运行调试,并观察未命中的断点:

├── .vscode
│   ├── launch.json
│   └── tasks.json
├── BUILD
├── WORKSPACE
├── main.cpp
└── sample.code-workspace
.vscode/launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(lldb) Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceRoot}/bazel-bin/sample",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "externalConsole": false,
            "MIMode": "lldb",
            "preLaunchTask": "bazel build",
        }
    ]
}
{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "bazel build",
            "type": "shell",
            "command": "bazel",
            "args": [
                "build",
                "--compilation_mode=dbg",
                "sample"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}
cc_binary(
    name = "sample",
    srcs = ["main.cpp"],
    visibility = ["//main:__pkg__"],
)
#include <iostream>

int main() {
    std::cout << "tests" << std::endl;
    return 0;
}
{
    "folders": [ {"path": "."} ],
    "settings": {}
}
.vscode/tasks.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(lldb) Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceRoot}/bazel-bin/sample",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "externalConsole": false,
            "MIMode": "lldb",
            "preLaunchTask": "bazel build",
        }
    ]
}
{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "bazel build",
            "type": "shell",
            "command": "bazel",
            "args": [
                "build",
                "--compilation_mode=dbg",
                "sample"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}
cc_binary(
    name = "sample",
    srcs = ["main.cpp"],
    visibility = ["//main:__pkg__"],
)
#include <iostream>

int main() {
    std::cout << "tests" << std::endl;
    return 0;
}
{
    "folders": [ {"path": "."} ],
    "settings": {}
}
构建

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(lldb) Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceRoot}/bazel-bin/sample",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "externalConsole": false,
            "MIMode": "lldb",
            "preLaunchTask": "bazel build",
        }
    ]
}
{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "bazel build",
            "type": "shell",
            "command": "bazel",
            "args": [
                "build",
                "--compilation_mode=dbg",
                "sample"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}
cc_binary(
    name = "sample",
    srcs = ["main.cpp"],
    visibility = ["//main:__pkg__"],
)
#include <iostream>

int main() {
    std::cout << "tests" << std::endl;
    return 0;
}
{
    "folders": [ {"path": "."} ],
    "settings": {}
}
main.cpp

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(lldb) Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceRoot}/bazel-bin/sample",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "externalConsole": false,
            "MIMode": "lldb",
            "preLaunchTask": "bazel build",
        }
    ]
}
{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "bazel build",
            "type": "shell",
            "command": "bazel",
            "args": [
                "build",
                "--compilation_mode=dbg",
                "sample"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}
cc_binary(
    name = "sample",
    srcs = ["main.cpp"],
    visibility = ["//main:__pkg__"],
)
#include <iostream>

int main() {
    std::cout << "tests" << std::endl;
    return 0;
}
{
    "folders": [ {"path": "."} ],
    "settings": {}
}

Upd。一,

已尝试调试bazel生成的可执行文件并直接使用lldb手动生成:

Bazel构建的二进制文件
Bazel构建--编译模式=dbg示例

lldb bazel-bin/sample
(lldb) breakpoint set -n main
Breakpoint 1: 13 locations.
(lldb) r
Process 24391 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
    frame #0: 0x00000001000021b0 sample`main
sample`main:
->  0x1000021b0 <+0>: pushq  %rbp
    0x1000021b1 <+1>: movq   %rsp, %rbp
    0x1000021b4 <+4>: subq   $0x20, %rsp
    0x1000021b8 <+8>: movq   0xe51(%rip), %rdi         ; (void *)0x00007fff9c93a660: std::__1::cout
Target 0: (sample) stopped.
lldb sample
(lldb) breakpoint set -n main
Breakpoint 1: where = sample`main + 29 at main.cpp:4, address = 0x0000000100000f9d
(lldb) r
Process 24410 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
    frame #0: 0x0000000100000f9d sample`main at main.cpp:4
   1    #include <iostream>
   2    
   3    int main() {
-> 4        std::cout << "tests" << std::endl;
   5        return 0;
   6    }
Target 0: (sample) stopped.
在可执行文件中查找“调试注释”后(感谢)

我发现这些路径指向Bazel用来构建的沙箱环境。而且这条路已经无法通行了

这可能是由Bazel的已知问题引起的


Upd。二,

将Bazel更新到版本0.17.2(问题已经解决)后,此问题仍然存在


Upd。三,


最后,它变成了巴泽尔问题。我在这里创建了一个问题(升级更新以获得答案):看起来像是一个已知的问题:

如果您扔掉visual studio代码,您肯定会有更好的运气构建和/或获得答案。从命令行运行bazel,并向我们展示该命令,这样我们就知道它实际上是如何执行的。另外,请告诉我们您在让bazel使用对调试有用的编译选项方面做了什么。@Mark我已将pure bazel命令添加到更新的部件中,所以实际问题是您没有调试符号?你说它“不起作用”,但在我看来,你可以很好地附加,尽管没有符号。@BradAllred我可以附加调试器,尽管问题是IDE中的调试不起作用。在你的帖子中,我完全不清楚“不起作用”。您根本没有提供错误。