WSL Ubuntu22.04下VSCode调试C代码启动失败求助
WSL Ubuntu 22.04下VSCode调试C代码的断点错误问题
在WSL(Ubuntu 22.04)环境中使用VSCode调试C代码时,尝试多种方案均触发相同错误:
已尝试的操作包括:
- 按指南配置基于make构建的
launch.json和tasks.json - 参考视频教程配置不依赖make的调试环境
- 以管理员模式启动VSCode
- 执行
chmod -x修改二进制文件权限 - 使用C/C++ Runner扩展
所有操作后,调试控制台均输出以下错误:
ERROR: Unable to start debugging. Unexpected GDB output from command "-exec-run". Warning: Cannot insert breakpoint 1. Cannot access memory at address 0x8001245 Cannot insert breakpoint 2. Cannot access memory at address 0x8001260
终端同时出现警告:
&"warning: GDB: Failed to set controlling terminal: Operation not permitted\n" [1] + Done "/usr/bin/gdb" --interpreter=mi --tty=${DbgTerm} 0<"/tmp/Microsoft-MIEngine-In-ri4karkl.dco" 1>"/tmp/Microsoft-MIEngine-Out-3varx35x.tnm"
尝试过的配置文件
方法一:基于make构建的配置
launch.json
{ "version": "0.2.0", "configurations": [ { "name": "(gdb) Launch", "type": "cppdbg", "request": "launch", "program": "${workspaceFolder}/bin/main", "args": [], "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [], "externalConsole": false, "MIMode": "gdb", "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true } ], "preLaunchTask": "build" }, { "name": "C/C++ Runner: Debug Session", "type": "cppdbg", "request": "launch", "args": [], "stopAtEntry": false, "externalConsole": false, "cwd": "${workspaceFolder}", "program": "${workspaceFolder}/bin/main", "MIMode": "gdb", "miDebuggerPath": "gdb", "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true } ], "preLaunchTask": "build" } ] }
tasks.json
{ "version": "2.0.0", "tasks": [ { "label": "build", "type": "shell", "command": "make", "group": { "kind": "build", "isDefault": true }, "problemMatcher": "$gcc" } ] }
方法二:不使用make的配置
launch.json
{ "version": "0.2.0", "configurations": [ { "name": "(gdb) Launch", "type": "cppdbg", "request": "launch", "program": "${workspaceFolder}/bin/main", "args": [], "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [], "externalConsole": false, "MIMode": "gdb", "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true } ], "preLaunchTask": "C/C++: g++ build active file" }, { "name": "C/C++ Runner: Debug Session", "type": "cppdbg", "request": "launch", "args": [], "stopAtEntry": false, "externalConsole": false, "cwd": "${workspaceFolder}", "program": "${workspaceFolder}/bin/main", "MIMode": "gdb", "miDebuggerPath": "gdb", "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true } ], "preLaunchTask": "C/C++: g++ build active file" } ] }
tasks.json
{ "tasks": [ { "type": "cppbuild", "label": "C/C++: g++ build active file", "command": "/usr/bin/g++", "args": [ "-fdiagnostics-color=always", "-g", "*.cpp", "-o", "${fileDirname}/${fileBasenameNoExtension}" ], "options": { "cwd": "${fileDirname}" }, "problemMatcher": [ "$gcc" ], "group": { "kind": "build", "isDefault": true } } ], "version": "2.0.0" }
内容的提问来源于stack exchange,提问作者JG03dev
相关产品推荐
相关产品推荐

