c++ 启动调试会话时macOS上的Visual Studio Code LLDB错误

siotufzp  于 2023-06-25  发布在  Mac
关注(0)|答案(4)|浏览(292)

我正在尝试配置Visual Studio Code,以便在macOS上编译/调试C++程序。我使用以下launch.json文件:

当我尝试并启动调试会话时,我得到以下错误:

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

值得一提的是,我使用的是MacBook(M1),所以x86_64不是正确的架构。我假设这就是错误的原因。
我似乎找不到任何关于这个错误的参考。我该如何解决这个问题?
添加“targetArchitecture”:“ARM 64”删除了警告,但它没有修复错误。

1tu0hz3e

1tu0hz3e1#

我也遇到了同样的问题,我发现Visual Studio Code还不支持ARM 64二进制文件的调试器。问题是link
但是,如果您使用另一个扩展,它就可以工作。安装CodeLLDB,并在 * launch.json * 中设置"type": "lldb",如下所示。

  1. {
  2. // Use IntelliSense to learn about possible attributes.
  3. // Hover to view descriptions of existing attributes.
  4. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
  5. "version": "0.2.0",
  6. "configurations": [
  7. {
  8. "name": "clang++ - Build and debug active file",
  9. "type": "lldb",
  10. "request": "launch",
  11. "program": "${fileDirname}/${fileBasenameNoExtension}",
  12. "args": [],
  13. "cwd": "${workspaceFolder}",
  14. "preLaunchTask": "clang++ build active file"
  15. }
  16. ]
  17. }

您可以查看vscode-lldb存储库的快速入门指南。
请注意,preLaunchTask的值应该与 * task.json * 文件中标签的值相同。

展开查看全部
zf2sa74q

zf2sa74q2#

使用cargo的config而不是“program”为我解决了这个问题(使用Rust和LLDB)。

  1. {
  2. "name": "(OSX) Launch",
  3. "type": "lldb",
  4. "request": "launch",
  5. "cargo": {
  6. "args": ["build", "--manifest-path", "${fileDirname}/../Cargo.toml"]
  7. }
  8. }
woobm2wo

woobm2wo3#

在2023年,LLDB调试器可以在macOS Monterey 12.5.1上使用M1芯片运行Rust:

我安装了CodeLLDB扩展。在vscode菜单栏中,我点击了View > Extensions,然后在搜索文本框中输入CodeLLDB,然后点击“安装”。
我配置了launch.json。我用cargo new创建了我的程序,在vscode中,我确保资源管理器(View > Explorer)中的顶部目录是我的程序的目录,例如。guessing_game3.我通过点击File > Open Folder,然后导航到我的程序的顶级目录来完成。

然后我点击了vscode左侧的Run and Debug图标:

产生了这样的观点:

如果你看到这个:

这意味着你已经有一个.vscode目录在你的程序的目录你的程序的父目录之一。我不小心这样做了,所以我进入一个父目录并删除了.vscode目录:

  1. one_of_my_programs_parent_dirs% rm -rf ./.vscode

好了,回到上一张图片....我点击了“创建一个launch.json文件”,弹出了一个对话框:

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

就是这样调试器成功了您可以在此处阅读有关如何使用调试器的信息:
https://code.visualstudio.com/docs/editor/debugging

展开查看全部
vmpqdwk3

vmpqdwk34#

使用以下命令生成可执行文件:

  1. gcc file_name.c -g

文件 launch.json

“targetArchitecture”:x86_64

相关问题