启动调试会话时 MacOS 上的 VSCode LLDB 错误

问题描述 投票:0回答:4

我正在尝试配置 VSCode 以在 MacOS 上编译/调试 C++ 程序。我正在使用以下 launch.json 文件:

当我尝试启动调试会话时,出现以下错误:

Warning: Debuggee TargetArchitecture not detected, assuming x86_64.
ERROR: Unable to start debugging. Unexpected LLDB output from command "-exec-run". process 
exited with status -1 (attach failed ((os/kern) invalid argument))
The program '/path/to/Development/C++/helloworld/main' has exited with code 42 
(0x0000002a).

值得一提的是,我使用的是 M1 Macbook,所以 x86_64 不是正确的架构。我假设这是错误的原因。

我似乎无法在网上的任何地方找到任何关于此错误的参考,有谁知道我该如何解决这个问题?

编辑:添加“targetArchitecture”:“ARM64”删除了警告,但没有修复错误。

c++ visual-studio-code lldb vscode-debugger
4个回答
52
投票

我遇到了同样的问题,我发现 VScode 还不支持 ARM64 二进制文件的调试器。这是问题link.

但是,如果您使用其他扩展程序,它会起作用。安装 CodeLLDB 并在 launch.json 上设置

"type": "lldb"
,如下所示。

{
    // 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": "clang++ - Build and debug active file",
        "type": "lldb",
        "request": "launch",
        "program": "${fileDirname}/${fileBasenameNoExtension}",
        "args": [],
        "cwd": "${workspaceFolder}",
        "preLaunchTask": "clang++ build active file"
      }
    ]
  }

您可以查看 vscode-lldb 存储库的快速入门指南。

请注意,preLaunchTask 的值应与 task.json 中标签的值相同。


0
投票

使用命令使可执行:

gcc file_name.c -g

启动.json

“目标架构”:“x86_64”,


0
投票

使用 cargo 的配置而不是“程序”为我解决了它(使用 Rust 和 LLDB)。

{
  "name": "(OSX) Launch",
  "type": "lldb",
  "request": "launch",
  "cargo": {
    "args": ["build", "--manifest-path", "${fileDirname}/../Cargo.toml"]
  }
}

0
投票

2023 年,LLDB 调试器适用于带有 M1 芯片的 macOS Monterey 12.5.1 上的 Rust:

我安装了 CodeLLDB 扩展。在 vscode 菜单栏中,我单击

View > Extensions
,然后在搜索文本框中输入
CodeLLDB
,然后单击“安装”。

我配置了launch.json。我用

cargo new
创建了我的程序,在 vscode 中,我确保资源管理器中的顶级目录(视图 > 资源管理器)是我的程序目录,例如guessing_game3.我通过单击
File > Open Folder
,然后导航到我的程序的顶级目录来做到这一点。

然后我点击了vscode左侧的

Run and Debug
图标:

产生这个观点:

我点击“Create a launch.json file”,弹出对话框:

我点击了“是”。这在我的程序目录中创建了一个 .vscode 目录,其中包含

launch.json
文件:

就是这样。调试器工作了。您可以在此处阅读有关如何使用调试器的信息:

https://code.visualstudio.com/docs/editor/debugging

如果你点击 vscode 左侧的

Run and Debug
cion,你会看到这个:

这意味着您的程序目录或程序的父目录之一中已经有一个 .vscode 目录。我无意中这样做了,所以我进入了一个父目录并删除了该目录:

% rm -rf ./.vscode
© www.soinside.com 2019 - 2024. All rights reserved.