Bug 29787 - Using "set debug infrun on" and "set logging enabled" breaks GDB prompt and makes GDB crash
Summary: Using "set debug infrun on" and "set logging enabled" breaks GDB prompt and m...
Status: RESOLVED FIXED
Alias: None
Product: gdb
Classification: Unclassified
Component: gdb (show other bugs)
Version: HEAD
: P2 normal
Target Milestone: 13.1
Assignee: Tom Tromey
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-11-16 03:53 UTC by vimacs.hacks@gmail.com
Modified: 2022-11-28 20:42 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed: 2022-11-16 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description vimacs.hacks@gmail.com 2022-11-16 03:53:14 UTC
The use of readline in GDB is broken in commit a715464cd2e25c8bf46190cc8bde9267c9ab6ac0 when using "set debug infrun on" and "set logging enabled".

GDB 12.1 doesn't have this bug, but GDB 12.1 doesn't have paging for the debug messages, so I don't know if this bug is only in the versions after GDB 12.1.

Steps to produce this bug:

1. build a simple program:

$ cat main.c 
int main()
{
}
$ gcc -g -O0 main.c

2. debug it and use the following commands:

$ ./gdb/gdb ./a.out
(gdb) b main
Breakpoint 1 at 0x1122: file main.c, line 3.
(gdb) set debug infrun on 
(gdb) set logging enabled 
Copying output to gdb.txt.
Copying debug output to gdb.txt.
(gdb) r

3. just type <RET> until the debug message finishes, and type <RET> once more, GDB will crash with "readline: readline_callback_read_char() called with no handler!"
Comment 1 Simon Marchi 2022-11-16 03:57:45 UTC
I was able to reproduce.  To be clear, you press <RET> to continue past the pagination prompts.  This was not clear to me at first.  Basically, after running, press <RET> until it crashes.
Comment 2 Tom Tromey 2022-11-16 18:11:34 UTC
Sounds like a regression.
Comment 3 Tom Tromey 2022-11-16 18:40:18 UTC
I don't think any output to gdb_stdlog should be paged,
so that seems like one problem here.
Comment 4 Tom Tromey 2022-11-17 16:27:22 UTC
Fixing the logging isn't super hard, but I think the real
problem is that some bit of code is enabling the stdin
input handler without also installing the readline callback
handler.
Comment 5 Tom Tromey 2022-11-17 16:34:22 UTC
One other weirdness for me here is that supposedly infrun
disables pagination.  Looking into this, I found a buglet
in fetch_inferior_event:

void
fetch_inferior_event ()
{
  INFRUN_SCOPED_DEBUG_ENTER_EXIT;
...
  /* Temporarily disable pagination.  Otherwise, the user would be
     given an option to press 'q' to quit, which would cause an early
     exit and could leave GDB in a half-baked state.  */
  scoped_restore save_pagination
    = make_scoped_restore (&pagination_enabled, false);


That is, it disables pagination -- but after the logging is done.
Comment 6 Tom Tromey 2022-11-17 16:48:11 UTC
Fixing fetch_inferior event is enough to fix this bug.
Should probably fix the logging in general, too, though.
Comment 7 Tom Tromey 2022-11-17 18:11:37 UTC
It occurs to me now that changing fetch_inferior_event shouldn't
be needed, because gdb_stdlog should never cause paging.
So, that patch isn't actually needed.
Comment 9 Sourceware Commits 2022-11-28 20:41:47 UTC
The master branch has been updated by Tom Tromey <tromey@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=1dd889362bb7027ebea754a161bf629270cc9042

commit 1dd889362bb7027ebea754a161bf629270cc9042
Author: Tom Tromey <tromey@adacore.com>
Date:   Thu Nov 17 10:24:38 2022 -0700

    Don't let gdb_stdlog use pager
    
    When using the "set logging" commands, cli_interp_base::set_logging
    will send gdb_stdlog output (among others) to the tee it makes for
    gdb_stdout.  However, this has the side effect of also causing logging
    to use the pager.  This is PR gdb/29787.
    
    This patch fixes the problem by keeping stderr and stdlog separate
    from stdout, preserving the rule that only gdb_stdout should page.
    
    Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29787
Comment 10 Tom Tromey 2022-11-28 20:42:18 UTC
Fixed.