Subject: bug#69327: 29.2.50; Emacs crashes when running gdb with comint-prompt-read-only

From: Knut Anders Hatlen <[email-masked]>
Date: Fri, 23 Feb 2024 10:12:25 +0000

I'm seeing occasional crashes when debugging programs with M-x gdb. I'm
observing the crashes on head of both emacs-29 and master, and on
multiple platforms (Debian Bookworm, Debian Trixie, Oracle Linux 8,
Oracle Linux 9).

To reproduce, save this simple C program in a file main.c:

#include <stdio.h>
int main() {
  printf("Hello!\n");
}

Compile it and produce two binaries, a.out and b.out:

% gcc main.c
% cp a.out b.out

Make sure the contents of ~/.gdbinit are:

set debuginfod enabled off

Then run emacs -Q and evaluate:

(progn
  (setopt gdb-debuginfod-enable-setting nil
          comint-prompt-read-only t)
  (gdb "gdb -i=mi a.out")
  (insert "r")
  (comint-send-input)
  (sit-for 2)
  (gdb "gdb -i=mi b.out"))

This makes Emacs crash in my environment. The stack trace has 10700
frames, so I assume it's something like an infinite recursion bug.
The backtrace is available in the attached gdb.txt.

It also crashes if gdb-debuginfod-enable-setting is t, but not if it's
'ask. (However, if it's 'ask, the second invocation of gdb asks again
and again whether debuginfod should be enabled. After responding y or n,
a new prompt with the same question immediately reappears.)

When setting comint-prompt-read-only to nil, it seems to behave fine
regardless of which value gdb-debuginfod-enable-setting has.

According to git bisect, it has crashed since the
gdb-debuginfod-enable-setting option was introduced in:

commit ab417c8a6eeb7df7ccce3e5f8416f48544a5174e
Author: Eli Zaretskii <[email-masked]>
Date:   Tue Mar 7 14:39:27 2023 +0200

    Fix problem with debuginfod queries in "M-x gdb"
    
    * lisp/progmodes/gdb-mi.el (gdb-debuginfod-enable-setting): New
    defcustom.
    (gdb-debuginfod-message): New function.
    (gdb-init-1): Initialize gdb-debuginfod-enable.  Ask the user
    about debuginfod queries and display any error messages.
    (Bug#61973)
    
    * etc/NEWS: Announce the change.

In GNU Emacs 29.2.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version
 3.24.38, cairo version 1.16.0) of 2024-02-22 built on atum07
Repository revision: f28a557c7d4b39f302630ed2b19a73fc375e7ff4
Repository branch: emacs-29
System Description: Debian GNU/Linux 12 (bookworm)

Configured using:
 'configure --with-json --with-xml2 --with-modules
 --prefix=/usr/local/stow/emacs-29 --with-pgtk --without-x
 --with-native-compilation --with-tree-sitter'

Configured features:
CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GSETTINGS HARFBUZZ JPEG JSON
LIBSELINUX LIBXML2 MODULES NATIVE_COMP NOTIFY INOTIFY PDUMPER PGTK PNG
SECCOMP SOUND THREADS TIFF TOOLKIT_SCROLL_BARS TREE_SITTER WEBP XIM GTK3
ZLIB

Important settings:
  value of $LANG: nn_NO.UTF-8
  value of $XMODIFIERS: @im=ibus
  locale-coding-system: utf-8-unix

Major mode: Group

Minor modes in effect:
  xterm-mouse-mode: t
  global-git-commit-mode: t
  shell-dirtrack-mode: t
  gnus-undo-mode: t
  corfu-terminal-mode: t
  midnight-mode: t
  desktop-save-mode: t
  savehist-mode: t
  winner-mode: t
  windmove-mode: t
  server-mode: t
  save-place-mode: t
  repeat-mode: t
  recentf-mode: t
  minibuffer-depth-indicate-mode: t
  marginalia-mode: t
  global-so-long-mode: t
  global-auto-revert-mode: t
  dynamic-completion-mode: t
  breadcrumb-mode: t
  tooltip-mode: t
  global-eldoc-mode: t
  show-paren-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tab-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  buffer-read-only: t
  column-number-mode: t
  line-number-mode: t
  transient-mark-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t

Load-path shadows:
/home/khatlen/.emacs.d/elpa/29/transient-0.5.3/transient hides /usr/local/stow/emacs-29/share/emacs/29.2.50/lisp/transient
/home/khatlen/.emacs.d/elpa/29/jsonrpc-1.0.24/jsonrpc hides /usr/local/stow/emacs-29/share/emacs/29.2.50/lisp/jsonrpc
/home/khatlen/.emacs.d/elpa/29/flymake-1.3.7/flymake hides /usr/local/stow/emacs-29/share/emacs/29.2.50/lisp/progmodes/flymake
/home/khatlen/.emacs.d/elpa/29/project-0.10.0/project hides /usr/local/stow/emacs-29/share/emacs/29.2.50/lisp/progmodes/project
/home/khatlen/.emacs.d/elpa/29/eglot-1.17/eglot hides /usr/local/stow/emacs-29/share/emacs/29.2.50/lisp/progmodes/eglot
/home/khatlen/.emacs.d/elpa/29/eldoc-1.15.0/eldoc hides /usr/local/stow/emacs-29/share/emacs/29.2.50/lisp/emacs-lisp/eldoc

Features:
(shadow emacsbug mailalias smtpmail ecomplete flow-fill xt-mouse
term/xterm xterm shr-color sort gnus-cite smiley mm-archive mail-extr
textsec uni-scripts idna-mapping ucs-normalize uni-confusable
textsec-check gnus-bcklg mule-util gdb-mi bindat gud help-fns radix-tree
eglot external-completion jsonrpc ert ewoc debug backtrace find-func
etags fileloop generator xref whitespace vc c++-ts-mode c-ts-mode
c-ts-common qp grep orderless vc-git vc-dispatcher sql view misearch
multi-isearch files-x magit-extras face-remap magit-submodule
magit-obsolete magit-blame magit-stash magit-reflog magit-bisect
magit-push magit-pull magit-fetch magit-clone magit-remote magit-commit
magit-sequence magit-notes magit-worktree magit-tag magit-merge
magit-branch magit-reset magit-files magit-refs magit-status magit
magit-repos magit-apply magit-wip magit-log which-func magit-diff
smerge-mode diff diff-mode easy-mmode git-commit log-edit pcvs-util
add-log magit-core magit-margin magit-transient magit-process
with-editor shell pcomplete magit-mode transient edmacro kmacro
gnus-async gnus-dup gnus-ml gnus-topic nndraft nnmh utf-7 nnml
format-spec nnfolder nnnil gnus-agent gnus-srvr gnus-score score-mode
nnvirtual gnus-msg nntp gnus-cache cus-start gnus-art mm-uu mml2015
mm-view mml-smime smime gnutls dig gnus-sum shr pixel-fill kinsoku
url-file svg dom gnus-group gnus-undo gnus-start gnus-dbus dbus xml
gnus-cloud nnimap nnmail mail-source utf7 nnoo parse-time iso8601
gnus-spec gnus-int gnus-range message sendmail yank-media dired
dired-loaddefs rfc822 mml mml-sec epa derived epg rfc6068 epg-config
mm-decode mm-bodies mm-encode mailabbrev gmm-utils mailheader gnus-win
gnus nnheader gnus-util range mail-utils comp comp-cstr flyspell ispell
hl-line elec-pair display-line-numbers elide-head corfu-terminal popon
corfu time-date checkdoc lisp-mnt flymake compile text-property-search
comint ansi-osc ansi-color warnings bug-reference cus-edit pp midnight
desktop frameset savehist yaml-ts-mode dockerfile-ts-mode cmake-ts-mode
treesit pcase network-stream url-http mail-parse rfc2231 rfc2047 rfc2045
mm-util ietf-drums mail-prsvr url-gw nsm puny url-cache url-auth rx ffap
thingatpt winner ring windmove disp-table server icons cl-extra
help-mode saveplace repeat recentf tree-widget wid-edit mb-depth
marginalia compat magit-autorevert magit-git magit-section magit-utils
crm dash so-long autorevert filenotify completion breadcrumb pulse color
project imenu cus-load boxquote-autoloads breadcrumb-autoloads
clang-format-autoloads corfu-terminal-autoloads corfu-autoloads
eglot-autoloads flymake-autoloads eldoc-autoloads
google-c-style-autoloads jsonrpc-autoloads magit-autoloads
git-commit-autoloads magit-section-autoloads dash-autoloads
marginalia-autoloads orderless-autoloads popon-autoloads
project-autoloads slime-autoloads macrostep-autoloads
transient-autoloads with-editor-autoloads info compat-autoloads package
browse-url url url-proxy url-privacy url-expand url-methods url-history
url-cookie generate-lisp-file url-domsuf url-util mailcap url-handlers
url-parse auth-source cl-seq eieio eieio-core cl-macs password-cache
json subr-x map byte-opt gv bytecomp byte-compile url-vars cl-loaddefs
cl-lib rmc iso-transl tooltip cconv eldoc paren electric uniquify
ediff-hook vc-hooks lisp-float-type elisp-mode mwheel term/pgtk-win
pgtk-win term/common-win pgtk-dnd tool-bar dnd fontset image regexp-opt
fringe tabulated-list replace newcomment text-mode lisp-mode prog-mode
register page tab-bar menu-bar rfn-eshadow isearch easymenu timer select
scroll-bar mouse jit-lock font-lock syntax font-core term/tty-colors
frame minibuffer nadvice seq simple cl-generic indonesian philippine
cham georgian utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao
korean japanese eucjp-ms cp51932 hebrew greek romanian slovak czech
european ethiopic indian cyrillic chinese composite emoji-zwj charscript
charprop case-table epa-hook jka-cmpr-hook help abbrev obarray oclosure
cl-preloaded button loaddefs theme-loaddefs faces cus-face macroexp
files window text-properties overlay sha1 md5 base64 format env
code-pages mule custom widget keymap hashtable-print-readable backquote
threads dbusbind inotify dynamic-setting system-font-setting
font-render-setting cairo gtk pgtk multi-tty make-network-process
native-compile emacs)

Memory information:
((conses 16 784875 72679)
 (symbols 48 30984 0)
 (strings 32 143369 8872)
 (string-bytes 1 5136733)
 (vectors 16 102363)
 (vector-slots 8 2434741 119058)
 (floats 8 577 565)
 (intervals 56 15669 3720)
 (buffers 984 43))