public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [PATCH 09/19] Unify vprintf functions
Date: Fri, 21 Jan 2022 18:37:51 -0700	[thread overview]
Message-ID: <20220122013801.666659-10-tom@tromey.com> (raw)
In-Reply-To: <20220122013801.666659-1-tom@tromey.com>

Now that filtered and unfiltered output can be treated identically, we
can unify the vprintf family of functions: vprintf_filtered,
vprintf_unfiltered, vfprintf_filtered and vfprintf_unfiltered.  (For
the gdb_stdout variants, recall that only printf_unfiltered gets truly
unfiltered output at this point.)  This removes one such function and
renames the remaining two to "gdb_vprintf".  All callers are updated.
Much of this patch was written by script.
---
 gdb/cli/cli-cmds.c        |  2 +-
 gdb/cli/cli-script.c      |  2 +-
 gdb/complaints.c          |  2 +-
 gdb/debug.c               |  2 +-
 gdb/disasm.c              |  2 +-
 gdb/exceptions.c          |  2 +-
 gdb/language.c            |  2 +-
 gdb/mi/mi-out.c           |  2 +-
 gdb/parse.c               |  4 +--
 gdb/remote-sim.c          |  8 +++---
 gdb/sol-thread.c          |  2 +-
 gdb/target-descriptions.c |  2 +-
 gdb/ui-file.c             |  2 +-
 gdb/utils.c               | 59 ++++++++-------------------------------
 gdb/utils.h               |  9 ++----
 15 files changed, 30 insertions(+), 72 deletions(-)

diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c
index 3cdc7cde9a5..aaa07b7dc50 100644
--- a/gdb/cli/cli-cmds.c
+++ b/gdb/cli/cli-cmds.c
@@ -2020,7 +2020,7 @@ ambiguous_line_spec (gdb::array_view<const symtab_and_line> sals,
 {
   va_list ap;
   va_start (ap, format);
-  vprintf_filtered (format, ap);
+  gdb_vprintf (format, ap);
   va_end (ap);
 
   for (const auto &sal : sals)
diff --git a/gdb/cli/cli-script.c b/gdb/cli/cli-script.c
index 55248de649b..67613aa0bc0 100644
--- a/gdb/cli/cli-script.c
+++ b/gdb/cli/cli-script.c
@@ -501,7 +501,7 @@ print_command_trace (const char *fmt, ...)
   va_list args;
 
   va_start (args, fmt);
-  vprintf_filtered (fmt, args);
+  gdb_vprintf (fmt, args);
   va_end (args);
   puts_filtered ("\n");
 }
diff --git a/gdb/complaints.c b/gdb/complaints.c
index 2c2d90a39d2..b582bf38f11 100644
--- a/gdb/complaints.c
+++ b/gdb/complaints.c
@@ -51,7 +51,7 @@ complaint_internal (const char *fmt, ...)
   else
     {
       fputs_filtered (_("During symbol reading: "), gdb_stderr);
-      vfprintf_filtered (gdb_stderr, fmt, args);
+      gdb_vprintf (gdb_stderr, fmt, args);
       fputs_filtered ("\n", gdb_stderr);
     }
 
diff --git a/gdb/debug.c b/gdb/debug.c
index 6f9cad0ddd0..b29a6620afe 100644
--- a/gdb/debug.c
+++ b/gdb/debug.c
@@ -30,5 +30,5 @@ int debug_print_depth = 0;
 void
 debug_vprintf (const char *fmt, va_list ap)
 {
-  vfprintf_unfiltered (gdb_stdlog, fmt, ap);
+  gdb_vprintf (gdb_stdlog, fmt, ap);
 }
diff --git a/gdb/disasm.c b/gdb/disasm.c
index 3000e5dddad..9564f1ca8ec 100644
--- a/gdb/disasm.c
+++ b/gdb/disasm.c
@@ -171,7 +171,7 @@ gdb_disassembler::dis_asm_fprintf (void *stream, const char *format, ...)
   va_list args;
 
   va_start (args, format);
-  vfprintf_filtered ((struct ui_file *) stream, format, args);
+  gdb_vprintf ((struct ui_file *) stream, format, args);
   va_end (args);
   /* Something non -ve.  */
   return 0;
diff --git a/gdb/exceptions.c b/gdb/exceptions.c
index 16e26d5e4b1..b23ab0e4f33 100644
--- a/gdb/exceptions.c
+++ b/gdb/exceptions.c
@@ -127,7 +127,7 @@ exception_fprintf (struct ui_file *file, const struct gdb_exception &e,
 
       /* Print the prefix.  */
       va_start (args, prefix);
-      vfprintf_filtered (file, prefix, args);
+      gdb_vprintf (file, prefix, args);
       va_end (args);
 
       print_exception (file, e);
diff --git a/gdb/language.c b/gdb/language.c
index 0846b3e5eeb..c4d11758d10 100644
--- a/gdb/language.c
+++ b/gdb/language.c
@@ -414,7 +414,7 @@ range_error (const char *string,...)
     case range_check_off:
       /* FIXME: cagney/2002-01-30: Should this function print anything
 	 when range error is off?  */
-      vfprintf_filtered (gdb_stderr, string, args);
+      gdb_vprintf (gdb_stderr, string, args);
       fprintf_filtered (gdb_stderr, "\n");
       break;
     default:
diff --git a/gdb/mi/mi-out.c b/gdb/mi/mi-out.c
index 53f7206addd..5145bea4b75 100644
--- a/gdb/mi/mi-out.c
+++ b/gdb/mi/mi-out.c
@@ -151,7 +151,7 @@ mi_ui_out::do_field_fmt (int fldno, int width, ui_align align,
     fprintf_unfiltered (stream, "%s=\"", fldname);
   else
     fputs_unfiltered ("\"", stream);
-  vfprintf_unfiltered (stream, format, args);
+  gdb_vprintf (stream, format, args);
   fputs_unfiltered ("\"", stream);
 }
 
diff --git a/gdb/parse.c b/gdb/parse.c
index a6595e3da06..abd6beac2d0 100644
--- a/gdb/parse.c
+++ b/gdb/parse.c
@@ -632,11 +632,11 @@ parser_fprintf (FILE *x, const char *y, ...)
 
   va_start (args, y);
   if (x == stderr)
-    vfprintf_unfiltered (gdb_stderr, y, args); 
+    gdb_vprintf (gdb_stderr, y, args); 
   else
     {
       fprintf_unfiltered (gdb_stderr, " Unknown FILE used.\n");
-      vfprintf_unfiltered (gdb_stderr, y, args);
+      gdb_vprintf (gdb_stderr, y, args);
     }
   va_end (args);
 }
diff --git a/gdb/remote-sim.c b/gdb/remote-sim.c
index 39bddec77b3..a87e86aaeaf 100644
--- a/gdb/remote-sim.c
+++ b/gdb/remote-sim.c
@@ -401,16 +401,16 @@ gdb_os_printf_filtered (host_callback * p, const char *format, ...)
   va_list args;
 
   va_start (args, format);
-  vfprintf_filtered (gdb_stdout, format, args);
+  gdb_vprintf (gdb_stdout, format, args);
   va_end (args);
 }
 
-/* GDB version of error vprintf_filtered.  */
+/* GDB version of error gdb_vprintf.  */
 
 static void ATTRIBUTE_PRINTF (2, 0)
 gdb_os_vprintf_filtered (host_callback * p, const char *format, va_list ap)
 {
-  vfprintf_filtered (gdb_stdout, format, ap);
+  gdb_vprintf (gdb_stdout, format, ap);
 }
 
 /* GDB version of error evprintf_filtered.  */
@@ -418,7 +418,7 @@ gdb_os_vprintf_filtered (host_callback * p, const char *format, va_list ap)
 static void ATTRIBUTE_PRINTF (2, 0)
 gdb_os_evprintf_filtered (host_callback * p, const char *format, va_list ap)
 {
-  vfprintf_filtered (gdb_stderr, format, ap);
+  gdb_vprintf (gdb_stderr, format, ap);
 }
 
 /* GDB version of error callback.  */
diff --git a/gdb/sol-thread.c b/gdb/sol-thread.c
index 0bfdbdf5037..f1991bec342 100644
--- a/gdb/sol-thread.c
+++ b/gdb/sol-thread.c
@@ -882,7 +882,7 @@ ps_plog (const char *fmt, ...)
 
   va_start (args, fmt);
 
-  vfprintf_filtered (gdb_stderr, fmt, args);
+  gdb_vprintf (gdb_stderr, fmt, args);
 }
 
 /* Get size of extra register set.  Currently a noop.  */
diff --git a/gdb/target-descriptions.c b/gdb/target-descriptions.c
index 7c380cdb60f..4c187754c65 100644
--- a/gdb/target-descriptions.c
+++ b/gdb/target-descriptions.c
@@ -1581,7 +1581,7 @@ class print_c_tdesc : public tdesc_element_visitor
 
     va_list args;
     va_start (args, fmt);
-    vprintf_filtered (fmt, args);
+    gdb_vprintf (fmt, args);
     va_end (args);
   }
 
diff --git a/gdb/ui-file.c b/gdb/ui-file.c
index f6878f76cf1..ec441a73a8c 100644
--- a/gdb/ui-file.c
+++ b/gdb/ui-file.c
@@ -42,7 +42,7 @@ ui_file::printf (const char *format, ...)
   va_list args;
 
   va_start (args, format);
-  vfprintf_unfiltered (this, format, args);
+  vprintf (format, args);
   va_end (args);
 }
 
diff --git a/gdb/utils.c b/gdb/utils.c
index 0254286e8ac..4a3d5397bc7 100644
--- a/gdb/utils.c
+++ b/gdb/utils.c
@@ -83,10 +83,6 @@ void (*deprecated_error_begin_hook) (void);
 
 /* Prototypes for local functions */
 
-static void vfprintf_maybe_filtered (struct ui_file *, const char *,
-				     va_list, bool)
-  ATTRIBUTE_PRINTF (2, 0);
-
 static void set_screen_size (void);
 static void set_width (void);
 
@@ -155,7 +151,7 @@ vwarning (const char *string, va_list args)
       gdb_flush (gdb_stdout);
       if (warning_pre_print)
 	fputs_unfiltered (warning_pre_print, gdb_stderr);
-      vfprintf_unfiltered (gdb_stderr, string, args);
+      gdb_vprintf (gdb_stderr, string, args);
       fprintf_unfiltered (gdb_stderr, "\n");
     }
 }
@@ -879,7 +875,7 @@ defaulted_query (const char *ctlstr, const char defchar, va_list args)
       target_terminal::scoped_restore_terminal_state term_state;
       target_terminal::ours_for_output ();
       gdb_stdout->wrap_here (0);
-      vfprintf_filtered (gdb_stdout, ctlstr, args);
+      gdb_vprintf (gdb_stdout, ctlstr, args);
 
       printf_filtered (_("(%s or %s) [answered %c; "
 			 "input not from terminal]\n"),
@@ -1841,49 +1837,16 @@ fputc_filtered (int c, struct ui_file *stream)
   return c;
 }
 
-/* Print a variable number of ARGS using format FORMAT.  If this
-   information is going to put the amount written (since the last call
-   to REINITIALIZE_MORE_FILTER or the last page break) over the page size,
-   call prompt_for_continue to get the users permission to continue.
-
-   Unlike fprintf, this function does not return a value.
-
-   We implement three variants, vfprintf (takes a vararg list and stream),
-   fprintf (takes a stream to write on), and printf (the usual).
-
-   Note also that this may throw a quit (since prompt_for_continue may
-   do so).  */
-
-static void
-vfprintf_maybe_filtered (struct ui_file *stream, const char *format,
-			 va_list args, bool filter)
-{
-  stream->vprintf (format, args);
-}
-
-
-void
-vfprintf_filtered (struct ui_file *stream, const char *format, va_list args)
-{
-  vfprintf_maybe_filtered (stream, format, args, true);
-}
-
 void
-vfprintf_unfiltered (struct ui_file *stream, const char *format, va_list args)
+gdb_vprintf (struct ui_file *stream, const char *format, va_list args)
 {
-  vfprintf_maybe_filtered (stream, format, args, false);
-}
-
-void
-vprintf_filtered (const char *format, va_list args)
-{
-  vfprintf_filtered (gdb_stdout, format, args);
+  stream->vprintf (format, args);
 }
 
 void
-vprintf_unfiltered (const char *format, va_list args)
+gdb_vprintf (const char *format, va_list args)
 {
-  vfprintf_unfiltered (gdb_stdout, format, args);
+  gdb_stdout->vprintf (format, args);
 }
 
 void
@@ -1892,7 +1855,7 @@ fprintf_filtered (struct ui_file *stream, const char *format, ...)
   va_list args;
 
   va_start (args, format);
-  vfprintf_filtered (stream, format, args);
+  gdb_vprintf (stream, format, args);
   va_end (args);
 }
 
@@ -1902,7 +1865,7 @@ fprintf_unfiltered (struct ui_file *stream, const char *format, ...)
   va_list args;
 
   va_start (args, format);
-  vfprintf_unfiltered (stream, format, args);
+  gdb_vprintf (stream, format, args);
   va_end (args);
 }
 
@@ -1916,7 +1879,7 @@ fprintf_styled (struct ui_file *stream, const ui_file_style &style,
 
   stream->emit_style_escape (style);
   va_start (args, format);
-  vfprintf_filtered (stream, format, args);
+  gdb_vprintf (stream, format, args);
   va_end (args);
   stream->emit_style_escape (ui_file_style ());
 }
@@ -1928,7 +1891,7 @@ vfprintf_styled (struct ui_file *stream, const ui_file_style &style,
 		 const char *format, va_list args)
 {
   stream->emit_style_escape (style);
-  vfprintf_filtered (stream, format, args);
+  gdb_vprintf (stream, format, args);
   stream->emit_style_escape (ui_file_style ());
 }
 
@@ -1938,7 +1901,7 @@ printf_filtered (const char *format, ...)
   va_list args;
 
   va_start (args, format);
-  vfprintf_filtered (gdb_stdout, format, args);
+  gdb_vprintf (gdb_stdout, format, args);
   va_end (args);
 }
 
diff --git a/gdb/utils.h b/gdb/utils.h
index cb322c34396..268886d716a 100644
--- a/gdb/utils.h
+++ b/gdb/utils.h
@@ -244,9 +244,9 @@ extern void puts_filtered (const char *);
 
 extern void puts_filtered_tabular (char *string, int width, int right);
 
-extern void vprintf_filtered (const char *, va_list) ATTRIBUTE_PRINTF (1, 0);
+extern void gdb_vprintf (const char *, va_list) ATTRIBUTE_PRINTF (1, 0);
 
-extern void vfprintf_filtered (struct ui_file *, const char *, va_list)
+extern void gdb_vprintf (struct ui_file *, const char *, va_list)
   ATTRIBUTE_PRINTF (2, 0);
 
 extern void fprintf_filtered (struct ui_file *, const char *, ...)
@@ -254,11 +254,6 @@ extern void fprintf_filtered (struct ui_file *, const char *, ...)
 
 extern void printf_filtered (const char *, ...) ATTRIBUTE_PRINTF (1, 2);
 
-extern void vprintf_unfiltered (const char *, va_list) ATTRIBUTE_PRINTF (1, 0);
-
-extern void vfprintf_unfiltered (struct ui_file *, const char *, va_list)
-  ATTRIBUTE_PRINTF (2, 0);
-
 extern void fprintf_unfiltered (struct ui_file *, const char *, ...)
   ATTRIBUTE_PRINTF (2, 3);
 
-- 
2.31.1


  parent reply	other threads:[~2022-01-22  1:38 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-22  1:37 [PATCH 00/19] Simplify GDB output functions Tom Tromey
2022-01-22  1:37 ` [PATCH 01/19] Use unfiltered output in annotate.c Tom Tromey
2022-01-22  1:37 ` [PATCH 02/19] Remove some uses of printf_unfiltered Tom Tromey
2022-01-22  1:37 ` [PATCH 03/19] Only have one API for unfiltered output Tom Tromey
2022-01-22  1:37 ` [PATCH 04/19] Add puts_unfiltered method to ui_file Tom Tromey
2022-01-22  1:37 ` [PATCH 05/19] Add style-escape methods " Tom Tromey
2022-01-22  1:37 ` [PATCH 06/19] Remove vfprintf_styled_no_gdbfmt Tom Tromey
2022-01-22  1:37 ` [PATCH 07/19] Change the pager to a ui_file Tom Tromey
2022-01-22  1:37 ` [PATCH 08/19] Remove fputs_styled_unfiltered Tom Tromey
2022-01-22  1:37 ` Tom Tromey [this message]
2022-01-22  1:37 ` [PATCH 10/19] Unify gdb puts functions Tom Tromey
2022-01-22  1:37 ` [PATCH 11/19] Unify gdb putc functions Tom Tromey
2022-01-22  1:37 ` [PATCH 13/19] Rename print_spaces_filtered Tom Tromey
2022-01-22  1:37 ` [PATCH 14/19] Rename puts_filtered_tabular Tom Tromey
2022-01-22  1:37 ` [PATCH 15/19] Rename fprintf_symbol_filtered Tom Tromey
2022-01-22  1:37 ` [PATCH 16/19] Remove ui_out_flag::unfiltered_output Tom Tromey
2022-01-22  1:37 ` [PATCH 17/19] Remove vfprintf_styled Tom Tromey
2022-01-22  1:38 ` [PATCH 18/19] Minor comment updates in utils.h Tom Tromey
2022-03-24 18:05   ` Pedro Alves
2022-03-28 20:29     ` Tom Tromey
2022-01-22  1:38 ` [PATCH 19/19] Remove unnecessary calls to wrap_here and gdb_flush Tom Tromey
2022-01-22 17:40 ` [PATCH 00/19] Simplify GDB output functions John Baldwin
2022-03-24 16:25 ` Tom Tromey
2022-03-24 18:08 ` Pedro Alves
2022-03-29 19:38   ` Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220122013801.666659-10-tom@tromey.com \
    --to=tom@tromey.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).