vscode下的gdb调试问题

在KDE Plasma 下使用aur中的visual-studio-code-bin包安装C++插件进行开发,为了进行测试就写了一个helloworld,但在VSCode的内置终端中先显示&"\342\232\240\357\270\217 warning: GDB: Failed to set controlling terminal: \344\270\215\345\205\201\350\256\270\347\232\204\346\223\215\344\275\234\n",我用AI翻译了一下,意思是“警告:GDB 无法设置控制终端:不允许的操作”

=thread-group-added,id="i1"
GNU gdb (GDB) 17.1
Copyright (C) 2025 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-pc-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
https://www.gnu.org/software/gdb/bugs/.
调试控制台显示了这些内容

AI给出了两个方法:

第一个:

把launch.json内容改为{

"version": "0.2.0",

"configurations": [

    {

"name": "(gdb) Launch",

"type": "cppdbg",

"request": "launch",

"program": "${fileDirname}/${fileBasenameNoExtension}",

"args": [],

"stopAtEntry": false,

"cwd": "${workspaceFolder}",

"environment": [],

"externalConsole": false,

"MIMode": "gdb",

// 核心修复:强制设置 tty 并忽略警告

"miDebuggerArgs": "-tty=/dev/pts/11",

"setupCommands": [

            {

"description": "Enable pretty-printing",

"text": "-enable-pretty-printing",

"ignoreFailures": true

            }

        \]

    }

\]

}(这里/dev/pts/11是因为在vscode的终端中输入tty返回的值是这样)

另一个方法是:
执行echo "set startup-with-shell off" >> ~/.gdbinit
echo "set inferior-tty /dev/null" >> ~/.gdbinit命令

但这些操作都没用,该怎么做才能正常在vscode的内置终端中输出正常的内容

tasks.json内容为{

"tasks": \[

    {

"type": "cppbuild",

"label": "C/C++: g++ 生成活动文件",

"command": "/usr/bin/g++",

"args": [

"-fdiagnostics-color=always",

"-g",

"${file}",

"-o",

"${fileDirname}/${fileBasenameNoExtension}"

        \],

"options": {

"cwd": "${fileDirname}"

        },

"problemMatcher": [

"$gcc"

        \],

"group": {

"kind": "build",

"isDefault": true

        },

"detail": "调试器生成的任务。"

    }

\],

"version": "2.0.0"

}

你的帖子未合理格式化,看着好乱。

我的建议是:尽量不要用调试器——我只在研究崩溃、内存数据异常、检查数据结构的时候会用到它。大部分时候打日志更方便快速好用。

我的另一个建议是:在独立的终端命令行上使用gdb,尤其是你的IDE不配合的时候。实际上我一直不明白为什么人们喜欢在IDE和文件管理器的一个逼仄的角落里用内置终端——一个功能完全的独立、按个人需求和喜欢挑选的终端不好用吗?