Ubuntu系统下配置VS Code与Clang编译器及miDebugger调试报错解决
解决VS Code中Clang调试"miDebugger is invalid"错误
这个错误核心是VS Code调试配置里的调试器路径无效,或调试器本身未正确安装。按以下步骤排查修复:
确认调试器安装状态
Clang默认适配的调试器是lldb,先在终端检查是否安装:lldb --version如果提示未找到,执行以下命令安装:
sudo apt update && sudo apt install lldb若你想使用GDB作为调试器(也兼容Clang编译的程序),则安装GDB:
sudo apt install gdb修正launch.json配置
打开项目下的.vscode/launch.json文件,重点检查调试器相关配置:- 若使用LLDB:
先安装VS Code的「CodeLLDB」插件,然后将launch.json配置改为LLDB类型:{ "version": "0.2.0", "configurations": [ { "type": "lldb", "request": "launch", "name": "Debug", "program": "${workspaceFolder}/${fileBasenameNoExtension}", "args": [], "cwd": "${workspaceFolder}" } ] } - 若使用GDB或lldb-mi:
确保miDebuggerPath指向正确的可执行文件路径,比如:{ "version": "0.2.0", "configurations": [ { "name": "Debug with GDB", "type": "cppdbg", "request": "launch", "program": "${workspaceFolder}/${fileBasenameNoExtension}", "args": [], "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [], "externalConsole": false, "MIMode": "gdb", "miDebuggerPath": "/usr/bin/gdb", "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true } ], "preLaunchTask": "clang build" } ] }
可以用
which gdb或which lldb-mi命令获取准确的调试器路径,替换到miDebuggerPath中。- 若使用LLDB:
确保编译时生成调试符号
打开.vscode/tasks.json,确认编译命令包含-g参数(生成调试符号的必要选项):{ "version": "2.0.0", "tasks": [ { "label": "clang build", "type": "shell", "command": "clang -g ${file} -o ${fileBasenameNoExtension}", "group": { "kind": "build", "isDefault": true }, "problemMatcher": "$gcc" } ] }验证调试器可执行性
在终端手动运行调试器命令(比如/usr/bin/gdb或/usr/bin/lldb),确认能正常启动,排除调试器本身损坏的问题。
内容的提问来源于stack exchange,提问作者Marko Minic
相关产品推荐
相关产品推荐

