[PATCH] Remove some ui_file_* functions

Luis Machado luis.machado@linaro.org
Tue Feb 11 08:38:00 GMT 2020


On 2/7/20 6:19 PM, Tom Tromey wrote:
> This removes ui_file_isatty, ui_file_read, ui_file_write,
> ui_file_write_async_safe, ui_file_flush, and ui_file_puts, replacing
> them with calls to the appropriate method instead.
> 
> gdb/ChangeLog
> 2020-02-07  Tom Tromey  <tromey@adacore.com>
> 
> 	* remote.c (remote_console_output): Update.
> 	* printcmd.c (printf_command): Update.
> 	* event-loop.c (gdb_wait_for_event): Update.
> 	* linux-nat.c (sigchld_handler): Update.
> 	* remote-sim.c (gdb_os_write_stdout): Update.
> 	(gdb_os_flush_stdout): Update.
> 	(gdb_os_flush_stderr): Update.
> 	(gdb_os_write_stderr): Update.
> 	* exceptions.c (print_exception): Update.
> 	* remote-fileio.c (remote_fileio_func_read): Update.
> 	(remote_fileio_func_write): Update.
> 	* tui/tui.c (tui_enable): Update.
> 	* tui/tui-interp.c (tui_interp::init): Update.
> 	* utils.c (init_page_info): Update.
> 	(putchar_unfiltered, fputc_unfiltered): Update.
> 	(gdb_flush): Update.
> 	(emit_style_escape): Update.
> 	(flush_wrap_buffer, fputs_maybe_filtered): Update.
> 	* ui-file.c (ui_file_isatty, ui_file_read, ui_file_write)
> 	(ui_file_write_async_safe, ui_file_flush, ui_file_puts): Remove.
> 	(stderr_file::write): Update.
> 	(stderr_file::puts): Update.
> 	* ui-file.h (ui_file_isatty, ui_file_write)
> 	(ui_file_write_async_safe, ui_file_read, ui_file_flush)
> 	(ui_file_puts): Don't declare.
> 
> Change-Id: I3ca9b36e9107f6adbc41e014f5078b41d6bcec4d
> ---
>   gdb/ChangeLog         | 28 +++++++++++++++++++++++++++
>   gdb/event-loop.c      |  4 ++--
>   gdb/exceptions.c      |  2 +-
>   gdb/guile/scm-ports.c |  2 +-
>   gdb/linux-nat.c       |  3 +--
>   gdb/printcmd.c        |  2 +-
>   gdb/remote-fileio.c   | 12 +++++++-----
>   gdb/remote-sim.c      |  8 ++++----
>   gdb/remote.c          |  4 ++--
>   gdb/tui/tui-interp.c  |  2 +-
>   gdb/tui/tui.c         |  2 +-
>   gdb/ui-file.c         | 45 ++-----------------------------------------
>   gdb/ui-file.h         | 14 --------------
>   gdb/utils.c           | 16 +++++++--------
>   14 files changed, 59 insertions(+), 85 deletions(-)
> 
> diff --git a/gdb/event-loop.c b/gdb/event-loop.c
> index fbe6aa43249..62f8c2052bf 100644
> --- a/gdb/event-loop.c
> +++ b/gdb/event-loop.c
> @@ -750,8 +750,8 @@ gdb_wait_for_event (int block)
>     int num_found = 0;
>   
>     /* Make sure all output is done before getting another event.  */
> -  ui_file_flush (gdb_stdout);
> -  ui_file_flush (gdb_stderr);
> +  gdb_stdout->flush ();
> +  gdb_stderr->flush ();
>   
>     if (gdb_notifier.num_fds == 0)
>       return -1;
> diff --git a/gdb/exceptions.c b/gdb/exceptions.c
> index 52cee4e2f6d..7e15551e015 100644
> --- a/gdb/exceptions.c
> +++ b/gdb/exceptions.c
> @@ -85,7 +85,7 @@ print_exception (struct ui_file *file, const struct gdb_exception &e)
>         else
>   	{
>   	  end++;
> -	  ui_file_write (file, start, end - start);
> +	  file->write (start, end - start);
>   	}
>       }					
>     fprintf_filtered (file, "\n");
> diff --git a/gdb/guile/scm-ports.c b/gdb/guile/scm-ports.c
> index 3df186412e0..3f832dc753a 100644
> --- a/gdb/guile/scm-ports.c
> +++ b/gdb/guile/scm-ports.c
> @@ -234,7 +234,7 @@ ioscm_fill_input (SCM port)
>     gdb_flush (gdb_stdout);
>     gdb_flush (gdb_stderr);
>   
> -  count = ui_file_read (gdb_stdin, (char *) pt->read_buf, pt->read_buf_size);
> +  count = gdb_stdin->read ((char *) pt->read_buf, pt->read_buf_size);
>     if (count == -1)
>       scm_syserror (FUNC_NAME);
>     if (count == 0)
> diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c
> index 230ae366b64..81af83c4ac5 100644
> --- a/gdb/linux-nat.c
> +++ b/gdb/linux-nat.c
> @@ -4213,8 +4213,7 @@ sigchld_handler (int signo)
>     int old_errno = errno;
>   
>     if (debug_linux_nat)
> -    ui_file_write_async_safe (gdb_stdlog,
> -			      "sigchld\n", sizeof ("sigchld\n") - 1);
> +    gdb_stdlog->write_async_safe ("sigchld\n", sizeof ("sigchld\n") - 1);
>   
>     if (signo == SIGCHLD
>         && linux_nat_event_pipe[0] != -1)
> diff --git a/gdb/printcmd.c b/gdb/printcmd.c
> index cee0c880355..797041484eb 100644
> --- a/gdb/printcmd.c
> +++ b/gdb/printcmd.c
> @@ -2720,7 +2720,7 @@ printf_command (const char *arg, int from_tty)
>     ui_printf (arg, gdb_stdout);
>     reset_terminal_style (gdb_stdout);
>     wrap_here ("");
> -  ui_file_flush (gdb_stdout);
> +  gdb_stdout->flush ();
>   }
>   
>   /* Implement the "eval" command.  */
> diff --git a/gdb/remote-fileio.c b/gdb/remote-fileio.c
> index 40add06509e..f2dc9a66ead 100644
> --- a/gdb/remote-fileio.c
> +++ b/gdb/remote-fileio.c
> @@ -541,7 +541,7 @@ remote_fileio_func_read (remote_target *remote, char *buf)
>   		 limit this read to something smaller than that - by a
>   		 safe margin, in case the limit depends on system
>   		 resources or version.  */
> -	      ret = ui_file_read (gdb_stdtargin, (char *) buffer, 16383);
> +	      ret = gdb_stdtargin->read ((char *) buffer, 16383);
>   	      if (ret > 0 && (size_t)ret > length)
>   		{
>   		  remaining_buf = (char *) xmalloc (ret - length);
> @@ -639,10 +639,12 @@ remote_fileio_func_write (remote_target *remote, char *buf)
>   	xfree (buffer);
>   	return;
>         case FIO_FD_CONSOLE_OUT:
> -	ui_file_write (target_fd == 1 ? gdb_stdtarg : gdb_stdtargerr,
> -		       (char *) buffer, length);
> -	ui_file_flush (target_fd == 1 ? gdb_stdtarg : gdb_stdtargerr);
> -	ret = length;
> +	{
> +	  ui_file *file = target_fd == 1 ? gdb_stdtarg : gdb_stdtargerr;
> +	  file->write ((char *) buffer, length);
> +	  file->flush ();
> +	  ret = length;
> +	}
>   	break;
>         default:
>   	ret = write (fd, buffer, length);
> diff --git a/gdb/remote-sim.c b/gdb/remote-sim.c
> index b4fa69c84fc..347dfd70131 100644
> --- a/gdb/remote-sim.c
> +++ b/gdb/remote-sim.c
> @@ -351,7 +351,7 @@ end_callbacks (void)
>   static int
>   gdb_os_write_stdout (host_callback *p, const char *buf, int len)
>   {
> -  ui_file_write (gdb_stdtarg, buf, len);
> +  gdb_stdtarg->write (buf, len);
>     return len;
>   }
>   
> @@ -360,7 +360,7 @@ gdb_os_write_stdout (host_callback *p, const char *buf, int len)
>   static void
>   gdb_os_flush_stdout (host_callback *p)
>   {
> -  ui_file_flush (gdb_stdtarg);
> +  gdb_stdtarg->flush ();
>   }
>   
>   /* GDB version of os_write_stderr callback.  */
> @@ -375,7 +375,7 @@ gdb_os_write_stderr (host_callback *p, const char *buf, int len)
>       {
>         b[0] = buf[i];
>         b[1] = 0;
> -      ui_file_puts (gdb_stdtargerr, b);
> +      gdb_stdtargerr->puts (b);
>       }
>     return len;
>   }
> @@ -385,7 +385,7 @@ gdb_os_write_stderr (host_callback *p, const char *buf, int len)
>   static void
>   gdb_os_flush_stderr (host_callback *p)
>   {
> -  ui_file_flush (gdb_stdtargerr);
> +  gdb_stdtargerr->flush ();
>   }
>   
>   /* GDB version of printf_filtered callback.  */
> diff --git a/gdb/remote.c b/gdb/remote.c
> index 34a8a08f562..4a70ab3fb0d 100644
> --- a/gdb/remote.c
> +++ b/gdb/remote.c
> @@ -6845,9 +6845,9 @@ remote_console_output (const char *msg)
>   
>         tb[0] = c;
>         tb[1] = 0;
> -      ui_file_puts (gdb_stdtarg, tb);
> +      gdb_stdtarg->puts (tb);
>       }
> -  ui_file_flush (gdb_stdtarg);
> +  gdb_stdtarg->flush ();
>   }
>   
>   struct stop_reply : public notif_event
> diff --git a/gdb/tui/tui-interp.c b/gdb/tui/tui-interp.c
> index 978b5022152..090cf0e0d0c 100644
> --- a/gdb/tui/tui-interp.c
> +++ b/gdb/tui/tui-interp.c
> @@ -243,7 +243,7 @@ tui_interp::init (bool top_level)
>   
>     tui_initialize_io ();
>     tui_initialize_win ();
> -  if (ui_file_isatty (gdb_stdout))
> +  if (gdb_stdout->isatty ())
>       tui_initialize_readline ();
>   }
>   
> diff --git a/gdb/tui/tui.c b/gdb/tui/tui.c
> index ae3b9f6072d..0a598373ce6 100644
> --- a/gdb/tui/tui.c
> +++ b/gdb/tui/tui.c
> @@ -425,7 +425,7 @@ tui_enable (void)
>   
>         /* Don't try to setup curses (and print funny control
>   	 characters) if we're not outputting to a terminal.  */
> -      if (!ui_file_isatty (gdb_stdout))
> +      if (!gdb_stderr->isatty ())
>   	error (_("Cannot enable the TUI when output is not a terminal"));
>   
>         s = newterm (NULL, stdout, stdin);
> diff --git a/gdb/ui-file.c b/gdb/ui-file.c
> index e42d203f1f0..f3adbd014aa 100644
> --- a/gdb/ui-file.c
> +++ b/gdb/ui-file.c
> @@ -90,18 +90,6 @@ null_file::write_async_safe (const char *buf, long sizeof_buf)
>   
>   

>   
> -void
> -ui_file_flush (struct ui_file *file)
> -{
> -  file->flush ();
> -}
> -
> -int
> -ui_file_isatty (struct ui_file *file)
> -{
> -  return file->isatty ();
> -}
> -
>   /* true if the gdb terminal supports styling, and styling is enabled.  */
>   
>   static bool
> @@ -126,35 +114,6 @@ term_cli_styling ()
>     return true;
>   }
>   
> -
> -void
> -ui_file_write (struct ui_file *file,
> -		const char *buf,
> -		long length_buf)
> -{
> -  file->write (buf, length_buf);
> -}
> -
> -void
> -ui_file_write_async_safe (struct ui_file *file,
> -			  const char *buf,
> -			  long length_buf)
> -{
> -  file->write_async_safe (buf, length_buf);
> -}
> -
> -long
> -ui_file_read (struct ui_file *file, char *buf, long length_buf)
> -{
> -  return file->read (buf, length_buf);
> -}
> -
> -void
> -ui_file_puts (struct ui_file *file, const char *buf)
> -{
> -  file->puts (buf);
> -}
> -
>   

>   
>   string_file::~string_file ()
> @@ -315,7 +274,7 @@ stdio_file::can_emit_style_escape ()
>   void
>   stderr_file::write (const char *buf, long length_buf)
>   {
> -  ui_file_flush (gdb_stdout);
> +  gdb_stdout->flush ();
>     stdio_file::write (buf, length_buf);
>   }
>   
> @@ -325,7 +284,7 @@ stderr_file::write (const char *buf, long length_buf)
>   void
>   stderr_file::puts (const char *linebuffer)
>   {
> -  ui_file_flush (gdb_stdout);
> +  gdb_stdout->flush ();
>     stdio_file::puts (linebuffer);
>   }
>   
> diff --git a/gdb/ui-file.h b/gdb/ui-file.h
> index 67685bdfa15..10c7e18344e 100644
> --- a/gdb/ui-file.h
> +++ b/gdb/ui-file.h
> @@ -100,20 +100,6 @@ public:
>   /* A preallocated null_file stream.  */
>   extern null_file null_stream;
>   
> -extern void ui_file_flush (ui_file *);
> -
> -extern int ui_file_isatty (struct ui_file *);
> -
> -extern void ui_file_write (struct ui_file *file, const char *buf,
> -			   long length_buf);
> -
> -extern void ui_file_write_async_safe (struct ui_file *file, const char *buf,
> -				      long length_buf);
> -
> -extern long ui_file_read (struct ui_file *file, char *buf, long length_buf);
> -
> -extern void ui_file_puts (struct ui_file *file, const char *buf);
> -
>   extern int gdb_console_fputs (const char *, FILE *);
>   
>   /* A std::string-based ui_file.  Can be used as a scratch buffer for
> diff --git a/gdb/utils.c b/gdb/utils.c
> index d51008aa694..0200a8621f6 100644
> --- a/gdb/utils.c
> +++ b/gdb/utils.c
> @@ -1277,7 +1277,7 @@ init_page_info (void)
>   	}
>   
>         /* If the output is not a terminal, don't paginate it.  */
> -      if (!ui_file_isatty (gdb_stdout))
> +      if (!gdb_stdout->isatty ())
>   	lines_per_page = UINT_MAX;
>   #endif
>       }
> @@ -1405,7 +1405,7 @@ emit_style_escape (const ui_file_style &style,
>     if (stream == nullptr)
>       wrap_buffer.append (style.to_ansi ());
>     else
> -    ui_file_puts (stream, style.to_ansi ().c_str ());
> +    stream->puts (style.to_ansi ().c_str ());
>   }
>   
>   /* Set the current output style.  This will affect future uses of the
> @@ -1539,7 +1539,7 @@ flush_wrap_buffer (struct ui_file *stream)
>   {
>     if (stream == gdb_stdout && !wrap_buffer.empty ())
>       {
> -      ui_file_puts (stream, wrap_buffer.c_str ());
> +      stream->puts (wrap_buffer.c_str ());
>         wrap_buffer.clear ();
>       }
>   }
> @@ -1550,7 +1550,7 @@ void
>   gdb_flush (struct ui_file *stream)
>   {
>     flush_wrap_buffer (stream);
> -  ui_file_flush (stream);
> +  stream->flush ();
>   }
>   
>   /* Indicate that if the next sequence of characters overflows the line,
> @@ -1697,7 +1697,7 @@ fputs_maybe_filtered (const char *linebuffer, struct ui_file *stream,
>         || top_level_interpreter ()->interp_ui_out ()->is_mi_like_p ())
>       {
>         flush_wrap_buffer (stream);
> -      ui_file_puts (stream, linebuffer);
> +      stream->puts (linebuffer);
>         return;
>       }
>   
> @@ -1797,7 +1797,7 @@ fputs_maybe_filtered (const char *linebuffer, struct ui_file *stream,
>   	      /* Now output indentation and wrapped string.  */
>   	      if (wrap_column)
>   		{
> -		  ui_file_puts (stream, wrap_indent);
> +		  stream->puts (wrap_indent);
>   		  if (stream->can_emit_style_escape ())
>   		    emit_style_escape (save_style, stream);
>   		  /* FIXME, this strlen is what prevents wrap_indent from
> @@ -1918,7 +1918,7 @@ putchar_unfiltered (int c)
>   {
>     char buf = c;
>   
> -  ui_file_write (gdb_stdout, &buf, 1);
> +  gdb_stdout->write (&buf, 1);
>     return c;
>   }
>   
> @@ -1936,7 +1936,7 @@ fputc_unfiltered (int c, struct ui_file *stream)
>   {
>     char buf = c;
>   
> -  ui_file_write (stream, &buf, 1);
> +  stream->write (&buf, 1);
>     return c;
>   }
>   
> 

LGTM.



More information about the Gdb-patches mailing list