在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的内置终端中输出正常的内容