VScode 报错:ERROR: Unable to start debugging. Unexpected LLDB output from command “-exec-run”.
1. 背景介绍
- 新手 VScode 使用者,使用系统是:MacOS Big Sur 11.4,使用的是Apple M1 芯片。
- 利用 Vscode 编译 c++ 代码,按照标准流程, 进行了配置。标准配置链接为:https://code.visualstudio.com/docs/cpp/config-clang-mac。
debug 之后出现的问题是:
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 ‘/Users/Desktop/test/test’ has exited with code 42 (0x0000002a).
2. 问题分析以及解决方法
tasks.json 中代码为:
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: clang++ 生成活动文件",
"command": "/usr/bin/clang++",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": "build",
"detail": "编译器: /usr/bin/clang++"
},
]
}
其中 args 中的参数代表编译器会执行:
clang++ -g test.cpp -o test
在此之后,生成的结果为:
然后,下一步是需要执行 ./test 操作,这一步需要用扩展来完成:CodeLLDB,具体是在 launch.json 中写入 launch 的操作,具体是操作 ./test 的步骤,使结果输出:
{
"name": "Launch",
"type": "lldb",
"request": "launch",
"program": "${workspaceFolder}/${fileBasenameNoExtension}",
"args": ["-arg1", "-arg2"],
}
其中 ${fileBasenameNoExtension} 代表 test 的文件。之后,在cpp文件中执行 F5 操作,无报错。
3. 重点
CodeLLDB 扩展的引入以及 launch 中写入了
"program": "${workspaceFolder}/${fileBasenameNoExtension}",
命令。
参考:
- lldb 使用: https://blog.csdn.net/Vinsuan1993/article/details/103983520
- 思路指向:https://github.com/microsoft/vscode-cpptools/issues/6779
2022.2.4 更新
新添加配置成功之后的json参数:
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": "(lldb) 启动",
"type": "lldb",
"request": "launch",
"program": "${workspaceFolder}/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "lldb"
}
]
}
task.json
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: clang 生成活动文件",
"command": "/usr/bin/clang",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": "build",
"detail": "编译器: /usr/bin/clang"
}
]
}
此外,安装了插件:
CodeLLDB
和
C/C++