This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RFC: Fix unpaginated backtrace and various other corrupted output


I've noticed recently that backtraces aren't paginating.  The immediate
problem is this code in fputs_maybe_filtered:

  /* Don't do any filtering if it is disabled.  */
  if ((stream != gdb_stdout) || !pagination_enabled
      || (lines_per_page == UINT_MAX && chars_per_line == UINT_MAX))

It turns out that cli_text's saved stream is NOT equal to gdb_stdout.  Why
not?  Well, captured_main first initializes gdb_stdout:
  gdb_stdout = stdio_fileopen (stdout);

Then _initialize_cli_interp creates the CLI output object:
#1  0x0807ef6d in _initialize_cli_interp () at /opt/src/gdb/src/gdb/cli/cli-interp.c:136
136       cli_uiout = cli_out_new (gdb_stdout);

and then:
#0  gdb_setup_readline () at /opt/src/gdb/src/gdb/event-top.c:1123
#1  0x0807ee6b in cli_interpreter_resume (data=0x0) at /opt/src/gdb/src/gdb/cli/cli-interp.c:57
#2  0x080bbb78 in interp_set (interp=0x8271df8) at /opt/src/gdb/src/gdb/interps.c:203

1122          gdb_stdout = stdio_fileopen (stdout);

Oops!  We've changed gdb_stdout.  Now all CLI output using ui_out is
considered unfiltered.  This leads to broken pagination, bad interleaving,
et cetera.

Possible solutions: change the test, change stdio_fileopen to return the
same stream, update the CLI's stream value.  I chose door #3.  The
resulting patch isn't pretty, but door #1 was even worse and door #2 has
some surprising warts unless I introduce reference counting.

Does anyone have comments on this patch?

-- 
Daniel Jacobowitz
MontaVista Software                         Debian GNU/Linux Developer

2003-06-28  Daniel Jacobowitz  <drow@mvista.com>

	* cli/cli-interp.c (cli_interpreter_resume): Update the
	cli_uiout's stream to gdb_stdout.

Index: cli-interp.c
===================================================================
RCS file: /cvs/src/src/gdb/cli/cli-interp.c,v
retrieving revision 1.3
diff -u -p -r1.3 cli-interp.c
--- cli-interp.c	8 Jun 2003 18:27:14 -0000	1.3
+++ cli-interp.c	28 Jun 2003 17:57:08 -0000
@@ -53,8 +53,25 @@ cli_interpreter_init (void)
 static int
 cli_interpreter_resume (void *data)
 {
+  struct ui_file *stream;
+
   /*sync_execution = 1; */
+
+  /* gdb_setup_readline will change gdb_stdout.  If the CLI was previously
+     writing to gdb_stdout, then set it to the new gdb_stdout afterwards.  */
+
+  stream = cli_out_set_stream (cli_uiout, gdb_stdout);
+  if (stream != gdb_stdout)
+    {
+      cli_out_set_stream (cli_uiout, stream);
+      stream = NULL;
+    }
+
   gdb_setup_readline ();
+
+  if (stream != NULL)
+    cli_out_set_stream (cli_uiout, gdb_stdout);
+
   return 1;
 }
 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]