Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH 1/2] gdb: remove filtered_printing_initialized function
@ 2026-10-21 22:28 Simon Marchi
  2026-10-21 22:28 ` [PATCH 2/2] gdb: remove set_width Simon Marchi
  2026-10-22 13:05 ` [PATCH 1/2] gdb: remove filtered_printing_initialized function Tom Tromey
  0 siblings, 2 replies; 5+ messages in thread
From: Simon Marchi @ 2026-10-21 22:28 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

Since commit ebfc93611b64 ("Remove unnecessary calls to wrap_here and
gdb_flush", 2022-01-03), the filtered_printing_initialized function is
only used in utils.c, by internal_vproblem.  Remove it and its
declaration in utils.h.  Rename the filter_initialized variable it
returned to filtered_printing_initialized, and use it directly.

Move the variable up so that it is defined before internal_vproblem.
Replace its comment, which was really about the wrap buffer variables
and a general description of the wrap mechanism.  Fix the comment of
set_width, which was also stale.

The description of the wrapping mechanism in that old comment was
interesting to keep though, so add an updated version of it to the
comment of pager_file::m_wrap_buffer.

Change-Id: Ie927aa0f60a2cdf24c288b5ee5df3009a23a521e
---
 gdb/pager.h |  9 ++++++++-
 gdb/utils.c | 38 +++++++++++++-------------------------
 gdb/utils.h |  3 ---
 3 files changed, 21 insertions(+), 29 deletions(-)

diff --git a/gdb/pager.h b/gdb/pager.h
index 114024d5e5f3..f497ea931f7a 100644
--- a/gdb/pager.h
+++ b/gdb/pager.h
@@ -85,7 +85,14 @@ class pager_file : public wrapped_file<ui_file_up>
   }
 
   /* Contains characters which are waiting to be output (they have
-     already been counted in chars_printed).  */
+     already been counted in chars_printed).
+
+     All output is accumulated here.  A call to wrap_here flushes the
+     buffer and records the current column as a possible line break
+     point.  A newline flushes the buffer and cancels the break point.
+     If the line overflows while a break point is set, a newline and
+     the indentation are emitted at that point, and the buffered text
+     follows on the next line.  */
   std::string m_wrap_buffer;
 
   /* Amount to indent by if the wrap occurs.  */
diff --git a/gdb/utils.c b/gdb/utils.c
index b3ba01d0e47d..f6ebda29784e 100644
--- a/gdb/utils.c
+++ b/gdb/utils.c
@@ -89,6 +89,10 @@ void (*deprecated_error_begin_hook) (void);
 static void set_screen_size (void);
 static void set_width (void);
 
+/* True once set_width has run and filtered printing can be used.  */
+
+static bool filtered_printing_initialized = false;
+
 /* Time spent in prompt_for_continue in the currently executing command
    waiting for user to respond.
    Initialized in make_command_stats_cleanup.
@@ -419,13 +423,13 @@ internal_vproblem (struct internal_problem *problem,
       term_state.emplace ();
       target_terminal::ours_for_output ();
     }
-  if (filtered_printing_initialized ())
+  if (filtered_printing_initialized)
     begin_line ();
 
   /* Emit the message unless query will emit it below.  */
   if (problem->should_quit != internal_problem_ask
       || !confirm
-      || !filtered_printing_initialized ()
+      || !filtered_printing_initialized
       || !readline_initialized (current_ui)
       || problem->should_print_backtrace)
     gdb_printf (gdb_stderr, "%s\n", reason.c_str ());
@@ -438,7 +442,7 @@ internal_vproblem (struct internal_problem *problem,
       /* Default (yes/batch case) is to quit GDB.  When in batch mode
 	 this lessens the likelihood of GDB going into an infinite
 	 loop.  */
-      if (!confirm || !filtered_printing_initialized ()
+      if (!confirm || !filtered_printing_initialized
 	  || !readline_initialized (current_ui))
 	quit_p = 1;
       else
@@ -463,7 +467,7 @@ internal_vproblem (struct internal_problem *problem,
     {
       if (!can_dump_core_warn (LIMIT_MAX, reason.c_str ()))
 	dump_core_p = 0;
-      else if (!filtered_printing_initialized ()
+      else if (!filtered_printing_initialized
 	       || !readline_initialized (current_ui))
 	dump_core_p = 1;
       else
@@ -1091,16 +1095,6 @@ static unsigned int lines_printed, chars_printed;
 
 static bool pagination_disabled_for_command;
 
-/* Buffer and start column of buffered text, for doing smarter word-
-   wrapping.  When someone calls wrap_here(), we start buffering output
-   that comes through gdb_puts().  If we see a newline, we just
-   spit it out and forget about the wrap_here().  If we see another
-   wrap_here(), we spit it out and remember the newer one.  If we see
-   the end of the line, we spit out a newline, the indent, and then
-   the buffered output.  */
-
-static bool filter_initialized = false;
-
 \f
 
 /* See utils.h.  */
@@ -1185,13 +1179,6 @@ init_page_info (void)
   set_width ();
 }
 
-/* Return nonzero if filtered printing is initialized.  */
-int
-filtered_printing_initialized (void)
-{
-  return filter_initialized;
-}
-
 set_batch_flag_and_restore_page_info::set_batch_flag_and_restore_page_info ()
   : m_save_lines_per_page (lines_per_page),
     m_save_chars_per_line (chars_per_line),
@@ -1255,15 +1242,16 @@ set_screen_size (void)
   rl_set_screen_size (rows, cols);
 }
 
-/* Reinitialize WRAP_BUFFER.  */
+/* Initialize the page info if needed, and mark filtered printing as
+   initialized.  */
 
 static void
-set_width (void)
+set_width ()
 {
   if (chars_per_line == 0)
     init_page_info ();
 
-  filter_initialized = true;
+  filtered_printing_initialized = true;
 }
 
 static void
@@ -1565,7 +1553,7 @@ void
 pager_file::wrap_here (int indent)
 {
   /* This should have been allocated, but be paranoid anyway.  */
-  gdb_assert (filter_initialized);
+  gdb_assert (filtered_printing_initialized);
 
   flush_wrap_buffer ();
   if (chars_per_line == UINT_MAX)	/* No line overflow checking.  */
diff --git a/gdb/utils.h b/gdb/utils.h
index 7e59037bf5f5..4f465e7077f9 100644
--- a/gdb/utils.h
+++ b/gdb/utils.h
@@ -257,9 +257,6 @@ extern void print_spaces (int, struct ui_file *);
 
 extern const char *n_spaces (int);
 
-/* Return nonzero if filtered printing is initialized.  */
-extern int filtered_printing_initialized (void);
-
 /* Like gdb_printf, but styles the output according to STYLE,
    when appropriate.  */
 

base-commit: ecca519b2096f9a1f11ac34db1f6c4dddb5d995e
-- 
2.56.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-10-22 16:30 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-21 22:28 [PATCH 1/2] gdb: remove filtered_printing_initialized function Simon Marchi
2026-10-21 22:28 ` [PATCH 2/2] gdb: remove set_width Simon Marchi
2026-10-22 13:05   ` Tom Tromey
2026-10-22 16:30     ` Simon Marchi
2026-10-22 13:05 ` [PATCH 1/2] gdb: remove filtered_printing_initialized function Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox