Blame SOURCES/gdb-rhbz1844458-use-fputX_unfiltered.patch

b2f73e
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
b2f73e
From: Keith Seitz <keiths@redhat.com>
b2f73e
Date: Mon, 8 Jun 2020 11:33:47 -0700
b2f73e
Subject: gdb-rhbz1844458-use-fputX_unfiltered.patch
b2f73e
b2f73e
;; Fix fput?_unfiltered functions
b2f73e
;; RH BZ 1844458 (Sergio Durigan Junior and Tom Tromey)
b2f73e
b2f73e
From 9effb44ccbf50c16da66aaab5fd535fe17e38e32 Mon Sep 17 00:00:00 2001
b2f73e
From: Sergio Durigan Junior <sergiodj@redhat.com>
b2f73e
Date: Wed, 19 Feb 2020 16:40:48 -0500
b2f73e
Subject: [PATCH] Make '{putchar,fputc}_unfiltered' use 'fputs_unfiltered'
b2f73e
b2f73e
There is currently a regression when using
b2f73e
'{putchar,fputc}_unfiltered' with 'puts_unfiltered' which was
b2f73e
introduced by one of the commits that reworked the unfiltered print
b2f73e
code.
b2f73e
b2f73e
The regression makes it impossible to use '{putchar,fputc}_unfiltered'
b2f73e
with 'puts_unfiltered', because the former writes directly to the
b2f73e
ui_file stream using 'stream->write', while the latter uses a buffered
b2f73e
mechanism (see 'wrap_buffer') and delays the printing.
b2f73e
b2f73e
If you do a quick & dirty hack on e.g. top.c:show_gdb_datadir:
b2f73e
b2f73e
  @@ -2088,6 +2088,13 @@ static void
b2f73e
   show_gdb_datadir (struct ui_file *file, int from_tty,
b2f73e
                    struct cmd_list_element *c, const char *value)
b2f73e
   {
b2f73e
  +  putchar_unfiltered ('\n');
b2f73e
  +  puts_unfiltered ("TEST");
b2f73e
  +  putchar_unfiltered ('>');
b2f73e
  +  puts_unfiltered ("PUTS");
b2f73e
  +  puts_unfiltered ("PUTS");
b2f73e
  +  putchar_unfiltered ('\n');
b2f73e
b2f73e
rebuild GDB and invoke the "show data-directory" command, you will
b2f73e
see:
b2f73e
b2f73e
  (gdb) show data-directory
b2f73e
b2f73e
  >
b2f73e
  TESTPUTSGDB's data directory is "/usr/local/share/gdb".
b2f73e
b2f73e
Note how the '>' was printed before the output, and "TEST" and "PUTS"
b2f73e
were printed together.
b2f73e
b2f73e
My first attempt to fix this was to always call 'flush_wrap_buffer' at
b2f73e
the end of 'fputs_maybe_filtered', since it seemed to me that the
b2f73e
function should always print what was requested.  But I wasn't sure
b2f73e
this was the right thing to do, so I talked to Tom on IRC and he gave
b2f73e
me another, simpler idea: make '{putchar,fputc}_unfiltered' call into
b2f73e
the already existing 'fputs_unfiltered' function.
b2f73e
b2f73e
This patch implements the idea.  I regtested it on the Buildbot, and
b2f73e
no regressions were detected.
b2f73e
b2f73e
gdb/ChangeLog:
b2f73e
2020-02-20  Sergio Durigan Junior  <sergiodj@redhat.com>
b2f73e
            Tom Tromey  <tom@tromey.com>
b2f73e
b2f73e
        * utils.c (fputs_maybe_filtered): Call 'stream->puts' instead
b2f73e
        of 'fputc_unfiltered'.
b2f73e
        (putchar_unfiltered): Call 'fputc_unfiltered'.
b2f73e
        (fputc_unfiltered): Call 'fputs_unfiltered'.
b2f73e
b2f73e
diff --git a/gdb/utils.c b/gdb/utils.c
b2f73e
--- a/gdb/utils.c
b2f73e
+++ b/gdb/utils.c
b2f73e
@@ -1783,7 +1783,12 @@ fputs_maybe_filtered (const char *linebuffer, struct ui_file *stream,
b2f73e
 		     newline -- if chars_per_line is right, we
b2f73e
 		     probably just overflowed anyway; if it's wrong,
b2f73e
 		     let us keep going.  */
b2f73e
-		  fputc_unfiltered ('\n', stream);
b2f73e
+		  /* XXX: The ideal thing would be to call
b2f73e
+		     'stream->putc' here, but we can't because it
b2f73e
+		     currently calls 'fputc_unfiltered', which ends up
b2f73e
+		     calling us, which generates an infinite
b2f73e
+		     recursion.  */
b2f73e
+		  stream->puts ("\n");
b2f73e
 		}
b2f73e
 	      else
b2f73e
 		{
b2f73e
@@ -1828,7 +1833,12 @@ fputs_maybe_filtered (const char *linebuffer, struct ui_file *stream,
b2f73e
 	  wrap_here ((char *) 0);	/* Spit out chars, cancel
b2f73e
 					   further wraps.  */
b2f73e
 	  lines_printed++;
b2f73e
-	  fputc_unfiltered ('\n', stream);
b2f73e
+	  /* XXX: The ideal thing would be to call
b2f73e
+	     'stream->putc' here, but we can't because it
b2f73e
+	     currently calls 'fputc_unfiltered', which ends up
b2f73e
+	     calling us, which generates an infinite
b2f73e
+	     recursion.  */
b2f73e
+	  stream->puts ("\n");
b2f73e
 	  lineptr++;
b2f73e
 	}
b2f73e
     }
b2f73e
@@ -1923,10 +1933,7 @@ fputs_highlighted (const char *str, const compiled_regex &highlight,
b2f73e
 int
b2f73e
 putchar_unfiltered (int c)
b2f73e
 {
b2f73e
-  char buf = c;
b2f73e
-
b2f73e
-  ui_file_write (gdb_stdout, &buf, 1);
b2f73e
-  return c;
b2f73e
+  return fputc_unfiltered (c, gdb_stdout);
b2f73e
 }
b2f73e
 
b2f73e
 /* Write character C to gdb_stdout using GDB's paging mechanism and return C.
b2f73e
@@ -1941,9 +1948,11 @@ putchar_filtered (int c)
b2f73e
 int
b2f73e
 fputc_unfiltered (int c, struct ui_file *stream)
b2f73e
 {
b2f73e
-  char buf = c;
b2f73e
+  char buf[2];
b2f73e
 
b2f73e
-  ui_file_write (stream, &buf, 1);
b2f73e
+  buf[0] = c;
b2f73e
+  buf[1] = 0;
b2f73e
+  fputs_unfiltered (buf, stream);
b2f73e
   return c;
b2f73e
 }
b2f73e