想在vscode下用gdb调试c++,vscode配置launch.json后,调试时断点功能好使,但step over和step into一点就会失灵(F5,F10,F11都失灵,调试还在继续),想问下大佬们有没有遇到过这种情况。
正常终端中gdb单步调试是可以的(应该不是gdb问题),vscode中调试会有个Warning: Debuggee TargetArchitecture not detected. assuming x86_64.
采用的是virtual box虚拟机,ubuntu 20.04.5LTS。
编译命令:g++ -g a.cpp -o a,只有一个a.cpp文件。
launch.json配置如下:
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/a",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
你可以尝试添加以下几个配置项:
"targetArchitecture":设置为"x86_64"
"miDebuggerPath":指定gdb可执行文件路径,如"/usr/bin/gdb"
"miDebuggerArgs":指定gdb命令行参数,如"-q"
修改后的launch.json示例如下:
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/a",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"targetArchitecture": "x86_64",
"miDebuggerPath": "/usr/bin/gdb",
"miDebuggerArgs": "-q"
}
]
}
另外,你也可以尝试在终端中输入 "file a" 命令,查看gdb是否能够正确识别可执行文件的调试信息,以及使用 "info files" 命令查看gdb是否正确加载了调试符号信息。