Docker容器内QEMU环境下VSCode调试Launch.json配置求助
解决VSCode附加QEMU远程调试时“未指定可执行文件”的问题
我是Docker、QEMU、GDB新手,通过CLI执行make debug和make gdb能正常调试,但用VSCode调试器附加运行中的QEMU目标时,弹出“未指定可执行文件”错误。当前在x86/64机器的Ubuntu开发容器里工作,问题出在VSCode误把ARM目标ELF当成本地x86 ELF文件识别。
目标ELF文件信息
root@6d0880bb1ed3:/work/RapidPatch/VulDevices/qemu-stm32-p103/build# file ./arm-start.elf ./arm-start.elf: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), statically linked, with debug_info, not stripped
当前Launch.json配置
{ "version": "0.2.0", "configurations": [ { "useExtendedRemote": true, "name": "Attach to QEMU (GDB Remote)", "type": "cppdbg", "request": "attach", "MIMode": "gdb", "miDebuggerServerAddress": "localhost:1234", "miDebuggerPath": "${workspaceFolder}/gcc-arm-none-eabi-9-2020-q2-update/bin/arm-none-eabi-gdb", "program": "${workspaceFolder}/RapidPatch/VulDevices/qemu-stm32-p103/build/arm-start.elf" } ] }
修复步骤
问题根源是VSCode的cppdbg调试器默认会检查program指定的ELF是否与本地系统架构匹配,而ARM ELF和x86/64容器架构不兼容,导致误判。需要添加两个配置项解决:
- 添加
targetArchitecture字段,明确指定目标架构为ARM - 添加
skipExecutableCheck字段,禁用本地可执行文件兼容性检查
修改后的完整Launch.json:
{ "version": "0.2.0", "configurations": [ { "useExtendedRemote": true, "name": "Attach to QEMU (GDB Remote)", "type": "cppdbg", "request": "attach", "MIMode": "gdb", "miDebuggerServerAddress": "localhost:1234", "miDebuggerPath": "${workspaceFolder}/gcc-arm-none-eabi-9-2020-q2-update/bin/arm-none-eabi-gdb", "program": "${workspaceFolder}/RapidPatch/VulDevices/qemu-stm32-p103/build/arm-start.elf", "targetArchitecture": "arm", "skipExecutableCheck": true } ] }
内容的提问来源于stack exchange,提问作者Chang Jia Jun
相关产品推荐
相关产品推荐

