If gdb-debuginfod-enable-setting is set to 'ask, gdb-init-1 may be called recursively, causing gdb-token-number (and other variables) to be reset in the middle of startup.

This causes an "gdb-handle-reply: Wrong type argument: gdb-handler, nil" error message and other "strange" behavior.

It triggers every time for me when attaching gdb to a running process: "emacs -nw -q" and M-x gdb, "gdb -i=mi -p <some-pid>". I only tested it with emacs 30.1 but the code seems to be the same at origin/master.

If you insert (when (> gdb-token-number 0) (edebug)) in the begining of (gdb-init-1) you'll see what happens. Partial call trace:

  gdb-init-1()
   :
  gdb-update()
   :
  gdb-stopped(...)
   :
  gud-filter(...)
  read-from-minibuffer(...)
  y-or-n-p("Enable querying debuginfod servers for this session?")
   :
  gdb-init-1()
   :
  gdb-update()
  gdb("gdb -i=mi -p ...")

I don't know what the right fix is, but it doesn't seem right to wait for user input in the middle of gdb-init-1.