首页 新闻 会员 周边 捐助

linux下vscode配置gdb调试问题

0
悬赏园豆:50 [待解决问题]

想在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
                }
            ]
        }
    ]
}
悟行丶的主页 悟行丶 | 初学一级 | 园豆:152
提问于:2022-09-26 20:43
< >
分享
所有回答(1)
0

你可以尝试添加以下几个配置项:

"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是否正确加载了调试符号信息。

Technologyforgood | 园豆:7688 (大侠五级) | 2023-04-09 09:09
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册