如何在VS Code的launch.json中启用Linux核心转储文件选择对话框?
在VS Code中用文件选择对话框配置Linux核心转储调试
要实现通过文件选择对话框选择可执行程序和核心转储文件,无需依赖额外扩展,直接利用VS Code的launch.json内置的command类型输入即可替代promptString。
实现步骤
在launch.json中定义输入项和调试配置,通过调用VS Code内置的文件选择命令触发对话框:
完整示例配置
{ "version": "0.2.0", "configurations": [ { "name": "调试Linux核心转储", "type": "cppdbg", "request": "launch", "program": "${input:selectExecutable}", "coreDumpPath": "${input:selectCoreDump}", "MIMode": "gdb", "setupCommands": [ { "description": "启用GDB美观打印", "text": "-enable-pretty-printing", "ignoreFailures": true } ] } ], "inputs": [ { "id": "selectExecutable", "type": "command", "command": "workbench.action.files.openFile", "args": { "title": "选择可执行程序", "filters": { "可执行文件": ["*"], "所有文件": ["*"] } } }, { "id": "selectCoreDump", "type": "command", "command": "workbench.action.files.openFile", "args": { "title": "选择核心转储文件", "filters": { "核心转储文件": ["core*"], "所有文件": ["*"] } } } ] }
配置说明
inputs区块:定义两个文件选择输入项,通过command调用VS Code内置的workbench.action.files.openFile命令触发文件选择对话框:id:唯一标识,供调试配置引用args.title:自定义对话框标题,方便区分选择目标args.filters:设置文件筛选规则,比如"core*"可以快速定位以core开头的核心转储文件
- 调试配置区块:用
${input:id}的形式引用对应的文件选择输入,启动调试时会依次弹出两个对话框,选择完成后自动填充路径
注意事项
- 确保已安装官方的C/C++扩展(ms-vscode.cpptools),
cppdbg调试类型依赖该扩展 - 如果需要选择特定格式的可执行文件,可以修改
filters中的匹配规则,比如针对ELF文件设置"ELF Executables": [".elf"] - 若需选择文件夹(而非单个文件),可将
command替换为workbench.action.files.openFolder
内容的提问来源于stack exchange,提问作者H.Arslan
相关产品推荐
相关产品推荐

