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

* [PATCH 2/2] gdb: remove set_width
  2026-10-21 22:28 [PATCH 1/2] gdb: remove filtered_printing_initialized function Simon Marchi
@ 2026-10-21 22:28 ` Simon Marchi
  2026-10-22 13:05   ` Tom Tromey
  2026-10-22 13:05 ` [PATCH 1/2] gdb: remove filtered_printing_initialized function Tom Tromey
  1 sibling, 1 reply; 5+ messages in thread
From: Simon Marchi @ 2026-10-21 22:28 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

set_width does not do anything useful anymore.  What remains is:

 - Calling init_page_info if chars_per_line is 0.  This can't happen:
   all callers call set_screen_size just before, which changes a
   chars_per_line of 0 to UINT_MAX.

 - Setting filtered_printing_initialized.  This only matters the first
   time, when called from init_page_info, from gdb_init.  The other
   callers (the "set width" command, set_screen_width_and_height and
   ~set_batch_flag_and_restore_page_info) can only run after that.

Remove set_width, and set filtered_printing_initialized directly in
init_page_info.  The "set width" and "set height" callbacks are now
identical, so replace them with a single set_screen_size_command.

Change-Id: I3631223cd02c0ffe4b8e9ccef958e8ea8782d6aa
---
 gdb/utils.c | 33 +++++++--------------------------
 1 file changed, 7 insertions(+), 26 deletions(-)

diff --git a/gdb/utils.c b/gdb/utils.c
index f6ebda29784e..4d03ccd5c2da 100644
--- a/gdb/utils.c
+++ b/gdb/utils.c
@@ -87,9 +87,8 @@ void (*deprecated_error_begin_hook) (void);
 /* Prototypes for local functions */
 
 static void set_screen_size (void);
-static void set_width (void);
 
-/* True once set_width has run and filtered printing can be used.  */
+/* True once init_page_info has run and filtered printing can be used.  */
 
 static bool filtered_printing_initialized = false;
 
@@ -1176,7 +1175,7 @@ init_page_info (void)
   rl_catch_sigwinch = 0;
 
   set_screen_size ();
-  set_width ();
+  filtered_printing_initialized = true;
 }
 
 set_batch_flag_and_restore_page_info::set_batch_flag_and_restore_page_info ()
@@ -1195,7 +1194,6 @@ set_batch_flag_and_restore_page_info::~set_batch_flag_and_restore_page_info ()
   lines_per_page = m_save_lines_per_page;
 
   set_screen_size ();
-  set_width ();
 }
 
 /* An approximation of SQRT(INT_MAX) that is:
@@ -1242,27 +1240,11 @@ set_screen_size (void)
   rl_set_screen_size (rows, cols);
 }
 
-/* Initialize the page info if needed, and mark filtered printing as
-   initialized.  */
+/* Callback for "set width" and "set height".  */
 
 static void
-set_width ()
-{
-  if (chars_per_line == 0)
-    init_page_info ();
-
-  filtered_printing_initialized = true;
-}
-
-static void
-set_width_command (const char *args, int from_tty, struct cmd_list_element *c)
-{
-  set_screen_size ();
-  set_width ();
-}
-
-static void
-set_height_command (const char *args, int from_tty, struct cmd_list_element *c)
+set_screen_size_command (const char *args, int from_tty,
+			 cmd_list_element *c)
 {
   set_screen_size ();
 }
@@ -1276,7 +1258,6 @@ set_screen_width_and_height (int width, int height)
   chars_per_line = width;
 
   set_screen_size ();
-  set_width ();
 }
 
 /* Import termcap variable UP (instead of readline private variable
@@ -3678,7 +3659,7 @@ Set number of characters where GDB should wrap lines of its output."), _("\
 Show number of characters where GDB should wrap lines of its output."), _("\
 This affects where GDB wraps its output to fit the screen width.\n\
 Setting this to \"unlimited\" or zero prevents GDB from wrapping its output."),
-			    set_width_command,
+			    set_screen_size_command,
 			    show_chars_per_line,
 			    &setlist, &showlist);
 
@@ -3688,7 +3669,7 @@ Show number of lines in a page for GDB output pagination."), _("\
 This affects the number of lines after which GDB will pause\n\
 its output and ask you whether to continue.\n\
 Setting this to \"unlimited\" or zero causes GDB never pause during output."),
-			    set_height_command,
+			    set_screen_size_command,
 			    show_lines_per_page,
 			    &setlist, &showlist);
 
-- 
2.56.0


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

* Re: [PATCH 1/2] gdb: remove filtered_printing_initialized function
  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
  1 sibling, 0 replies; 5+ messages in thread
From: Tom Tromey @ 2026-10-22 13:05 UTC (permalink / raw)
  To: Simon Marchi; +Cc: gdb-patches

>>>>> "Simon" == Simon Marchi <simon.marchi@efficios.com> writes:

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

Seems reasonable.
Approved-By: Tom Tromey <tom@tromey.com>

Tom

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

* Re: [PATCH 2/2] gdb: remove set_width
  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
  0 siblings, 1 reply; 5+ messages in thread
From: Tom Tromey @ 2026-10-22 13:05 UTC (permalink / raw)
  To: Simon Marchi; +Cc: gdb-patches

>>>>> "Simon" == Simon Marchi <simon.marchi@efficios.com> writes:

Simon> Remove set_width, and set filtered_printing_initialized directly in
Simon> init_page_info.  The "set width" and "set height" callbacks are now
Simon> identical, so replace them with a single set_screen_size_command.

Thanks.
Approved-By: Tom Tromey <tom@tromey.com>

Tom

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

* Re: [PATCH 2/2] gdb: remove set_width
  2026-10-22 13:05   ` Tom Tromey
@ 2026-10-22 16:30     ` Simon Marchi
  0 siblings, 0 replies; 5+ messages in thread
From: Simon Marchi @ 2026-10-22 16:30 UTC (permalink / raw)
  To: Tom Tromey, Simon Marchi; +Cc: gdb-patches

On 10/22/26 9:05 AM, Tom Tromey wrote:
>>>>>> "Simon" == Simon Marchi <simon.marchi@efficios.com> writes:
> 
> Simon> Remove set_width, and set filtered_printing_initialized directly in
> Simon> init_page_info.  The "set width" and "set height" callbacks are now
> Simon> identical, so replace them with a single set_screen_size_command.
> 
> Thanks.
> Approved-By: Tom Tromey <tom@tromey.com>
> 
> Tom

Thanks, pushed both.

Simon

^ 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