gdb总是在按任意键后退出

gdb always quit after press any key

我检查了 gdb 源代码并使用 MinGW 编译成功。当我 运行 输出文件 gdb.exe 时,我无法输入任何内容,任何按键都会导致它退出:

aj@TERRAN E:\
$ gdb --data-directory=E:\gdb_build\gdb\gdb-7.11\gdb\data-directory
GNU gdb (GDB) 7.11
Copyright (C) 2016 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 "--host=i686-pc-mingw32 --target=arm-linux-androideabi".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word".
(gdb) quit

aj@TERRAN E:\
$

我没有输入最后一个 quit,我只是按了 space 就退出了。 我下载了另一个运行良好的预构建 gdb,但它不支持 python,所以我需要自己构建它。

但我用 gdb -tui 尝试了 tui 模式,它工作正常,我可以输入命令。 为什么非tui模式会退出?

这是 gdb 7.12 的一个错误,7.11.1 工作正常。

旧版本的 GDB 在从 Windows 上的源构建它们时存在此错误。我在使用 MSYS2 构建的自定义 GDB 7.6.1 时遇到了这个问题。 当 GDB 与 ncurses 库链接时出现问题。在这种情况下,函数 getch() 取自 ncurses 和 returns EOF,因为没有 curses window。它是从 readline/input.c:rl_getc() 调用的。
最新的资源已修复此问题并从标准库调用 _getch()。这个简单的修复以 backspace 键结束,不删除字符。因此,readline 中也有更多修复程序来修复该问题。 更多信息:https://www.mail-archive.com/bug-readline@gnu.org/msg01203.html
https://gdb-patches.sourceware.narkive.com/A7CT0KH0/enabled-tui-mode-on-msys2

构建旧版本的一个简单解决方法是使用 --disable-tui 配置选项禁用 TUI 模式。这将在不依赖 ncurses 的情况下构建 GDB,并且不会暴露此错误。