public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 0/4] Clean up wrap_here function a little
@ 2021-12-31 22:25 Tom Tromey
  2021-12-31 22:25 ` [PATCH 1/4] Convert wrap_here to use integer parameter Tom Tromey
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Tom Tromey @ 2021-12-31 22:25 UTC (permalink / raw)
  To: gdb-patches

One oddity in gdb is that wrap_here doesn't take a stream parameter.
This is a historical relic from before my involvement in gdb, but it
leads to kind of weird code that intermixes calls to wrap_here (which
only affects gdb_stdout) with writes to other streams.

This series is a step toward cleaning this up.  It's part of a larger
project to un-spaghettify gdb's output pager.

Regression tested on x86-64 Fedora 34.

Tom



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

* [PATCH 1/4] Convert wrap_here to use integer parameter
  2021-12-31 22:25 [PATCH 0/4] Clean up wrap_here function a little Tom Tromey
@ 2021-12-31 22:25 ` Tom Tromey
  2021-12-31 22:25 ` [PATCH 2/4] Add ui_file::wrap_here Tom Tromey
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Tom Tromey @ 2021-12-31 22:25 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

I think it only really makes sense to call wrap_here with an argument
consisting solely of spaces.  Given this, it seemed better to me that
the argument be an int, rather than a string.  This patch is the
result.  Much of it was written by a script.
---
 gdb/ada-typeprint.c          |  8 +++---
 gdb/ada-valprint.c           |  6 ++---
 gdb/breakpoint.c             | 15 +++--------
 gdb/c-typeprint.c            | 16 +++++------
 gdb/cli-out.c                |  4 +--
 gdb/cli-out.h                |  2 +-
 gdb/cli/cli-cmds.c           |  2 +-
 gdb/cli/cli-decode.c         | 12 ++++-----
 gdb/cp-valprint.c            |  2 +-
 gdb/disasm.c                 |  4 +--
 gdb/exceptions.c             |  2 +-
 gdb/exec.c                   |  2 +-
 gdb/f-typeprint.c            |  4 +--
 gdb/guile/scm-pretty-print.c |  2 +-
 gdb/m2-typeprint.c           |  8 +++---
 gdb/main.c                   |  8 +++---
 gdb/maint.c                  |  4 +--
 gdb/mi/mi-out.c              |  4 +--
 gdb/mi/mi-out.h              |  2 +-
 gdb/p-typeprint.c            | 10 +++----
 gdb/p-valprint.c             |  2 +-
 gdb/printcmd.c               |  8 +++---
 gdb/psymtab.c                | 10 +++----
 gdb/python/py-framefilter.c  |  6 ++---
 gdb/python/py-prettyprint.c  |  2 +-
 gdb/source.c                 | 10 +++----
 gdb/stack.c                  | 20 +++++++-------
 gdb/symfile.c                |  4 +--
 gdb/symmisc.c                |  6 ++---
 gdb/symtab.c                 |  2 +-
 gdb/top.c                    |  2 +-
 gdb/tracepoint.c             | 15 +++++------
 gdb/ui-out.c                 |  4 +--
 gdb/ui-out.h                 |  4 +--
 gdb/utils.c                  | 52 +++++++++++++-----------------------
 gdb/utils.h                  |  2 +-
 gdb/valprint.c               |  2 +-
 37 files changed, 122 insertions(+), 146 deletions(-)

diff --git a/gdb/ada-typeprint.c b/gdb/ada-typeprint.c
index e336e034480..22cce5ec5b1 100644
--- a/gdb/ada-typeprint.c
+++ b/gdb/ada-typeprint.c
@@ -317,7 +317,7 @@ print_enum_type (struct type *type, struct ui_file *stream)
   LONGEST lastval;
 
   fprintf_filtered (stream, "(");
-  wrap_here (" ");
+  wrap_here (1);
 
   lastval = 0;
   for (i = 0; i < len; i++)
@@ -325,7 +325,7 @@ print_enum_type (struct type *type, struct ui_file *stream)
       QUIT;
       if (i)
 	fprintf_filtered (stream, ", ");
-      wrap_here ("    ");
+      wrap_here (4);
       fputs_styled (ada_enum_name (type->field (i).name ()),
 		    variable_name_style.style (), stream);
       if (lastval != type->field (i).loc_enumval ())
@@ -416,7 +416,7 @@ print_array_type (struct type *type, struct ui_file *stream, int show,
 
   elt_type = ada_array_element_type (type, n_indices);
   fprintf_filtered (stream, ") of ");
-  wrap_here ("");
+  wrap_here (0);
   ada_print_type (elt_type, "", stream, show == 0 ? 0 : show - 1, level + 1,
 		  flags);
   /* Arrays with variable-length elements are never bit-packed in practice but
@@ -892,7 +892,7 @@ print_func_type (struct type *type, struct ui_file *stream, const char *name,
 	  if (i > 0)
 	    {
 	      fputs_filtered ("; ", stream);
-	      wrap_here ("    ");
+	      wrap_here (4);
 	    }
 	  fprintf_filtered (stream, "a%d: ", i + 1);
 	  ada_print_type (type->field (i).type (), "", stream, -1, 0,
diff --git a/gdb/ada-valprint.c b/gdb/ada-valprint.c
index 6813af56dda..cc663e73ac6 100644
--- a/gdb/ada-valprint.c
+++ b/gdb/ada-valprint.c
@@ -178,7 +178,7 @@ val_print_packed_array_elements (struct type *type, const gdb_byte *valaddr,
 	  fprintf_filtered (stream, "\n");
 	  print_spaces_filtered (2 + 2 * recurse, stream);
 	}
-      wrap_here (n_spaces (2 + 2 * recurse));
+      wrap_here (2 + 2 * recurse);
       maybe_print_array_index (index_type, i + low, stream, options);
 
       i0 = i;
@@ -235,7 +235,7 @@ val_print_packed_array_elements (struct type *type, const gdb_byte *valaddr,
 		    {
 		      fprintf_filtered (stream, ", ");
 		    }
-		  wrap_here (n_spaces (2 + 2 * recurse));
+		  wrap_here (2 + 2 * recurse);
 		  maybe_print_array_index (index_type, j + low,
 					   stream, options);
 		}
@@ -614,7 +614,7 @@ print_field_values (struct value *value, struct value *outer_value,
 	}
       else
 	{
-	  wrap_here (n_spaces (2 + 2 * recurse));
+	  wrap_here (2 + 2 * recurse);
 	}
 
       annotate_field_begin (type->field (i).type ());
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index 877ca83984e..f76636d377c 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -5788,14 +5788,13 @@ bpstat_causes_stop (bpstat *bs)
 
 \f
 
-/* Compute a string of spaces suitable to indent the next line
+/* Compute a number of spaces suitable to indent the next line
    so it starts at the position corresponding to the table column
    named COL_NAME in the currently active table of UIOUT.  */
 
-static char *
+static int
 wrap_indent_at_field (struct ui_out *uiout, const char *col_name)
 {
-  static char wrap_indent[80];
   int i, total_width, width, align;
   const char *text;
 
@@ -5803,18 +5802,12 @@ wrap_indent_at_field (struct ui_out *uiout, const char *col_name)
   for (i = 1; uiout->query_table_field (i, &width, &align, &text); i++)
     {
       if (strcmp (text, col_name) == 0)
-	{
-	  gdb_assert (total_width < sizeof wrap_indent);
-	  memset (wrap_indent, ' ', total_width);
-	  wrap_indent[total_width] = 0;
-
-	  return wrap_indent;
-	}
+	return total_width;
 
       total_width += width + 1;
     }
 
-  return NULL;
+  return 0;
 }
 
 /* Determine if the locations of this breakpoint will have their conditions
diff --git a/gdb/c-typeprint.c b/gdb/c-typeprint.c
index a6228248e9e..4bef48aae37 100644
--- a/gdb/c-typeprint.c
+++ b/gdb/c-typeprint.c
@@ -250,7 +250,7 @@ cp_type_print_derivation_info (struct ui_file *stream,
 
   for (i = 0; i < TYPE_N_BASECLASSES (type); i++)
     {
-      wrap_here ("        ");
+      wrap_here (8);
       fputs_filtered (i == 0 ? ": " : ", ", stream);
       fprintf_filtered (stream, "%s%s ",
 			BASETYPE_VIA_PUBLIC (type, i)
@@ -310,7 +310,7 @@ cp_type_print_method_args (struct type *mtype, const char *prefix,
 	  else if (i < nargs)
 	    {
 	      fprintf_filtered (stream, ", ");
-	      wrap_here ("        ");
+	      wrap_here (8);
 	    }
 	}
     }
@@ -573,7 +573,7 @@ c_type_print_args (struct type *type, struct ui_file *stream,
       if (printed_any)
 	{
 	  fprintf_filtered (stream, ", ");
-	  wrap_here ("    ");
+	  wrap_here (4);
 	}
 
       param_type = type->field (i).type ();
@@ -602,7 +602,7 @@ c_type_print_args (struct type *type, struct ui_file *stream,
       if (printed_any && type->has_varargs ())
 	{
 	  fprintf_filtered (stream, ", ");
-	  wrap_here ("    ");
+	  wrap_here (4);
 	  fprintf_filtered (stream, "...");
 	}
     }
@@ -888,14 +888,14 @@ c_type_print_template_args (const struct type_print_options *flags,
 
       if (first)
 	{
-	  wrap_here ("    ");
+	  wrap_here (4);
 	  fprintf_filtered (stream, _("[with %s = "), sym->linkage_name ());
 	  first = 0;
 	}
       else
 	{
 	  fputs_filtered (", ", stream);
-	  wrap_here ("         ");
+	  wrap_here (9);
 	  fprintf_filtered (stream, "%s = ", sym->linkage_name ());
 	}
 
@@ -1559,7 +1559,7 @@ c_type_print_base_1 (struct type *type, struct ui_file *stream,
 	    fputs_filtered (" ", stream);
 	}
 
-      wrap_here ("    ");
+      wrap_here (4);
       if (show < 0)
 	{
 	  /* If we just printed a tag name, no need to print anything
@@ -1594,7 +1594,7 @@ c_type_print_base_1 (struct type *type, struct ui_file *stream,
 	      QUIT;
 	      if (i)
 		fprintf_filtered (stream, ", ");
-	      wrap_here ("    ");
+	      wrap_here (4);
 	      fputs_styled (type->field (i).name (),
 			    variable_name_style.style (), stream);
 	      if (lastval != type->field (i).loc_enumval ())
diff --git a/gdb/cli-out.c b/gdb/cli-out.c
index a3c189e4a8e..68cf284cf44 100644
--- a/gdb/cli-out.c
+++ b/gdb/cli-out.c
@@ -238,12 +238,12 @@ cli_ui_out::do_message (const ui_file_style &style,
 }
 
 void
-cli_ui_out::do_wrap_hint (const char *identstring)
+cli_ui_out::do_wrap_hint (int indent)
 {
   if (m_suppress_output)
     return;
 
-  wrap_here (identstring);
+  wrap_here (indent);
 }
 
 void
diff --git a/gdb/cli-out.h b/gdb/cli-out.h
index cf9abedd464..e079d780da9 100644
--- a/gdb/cli-out.h
+++ b/gdb/cli-out.h
@@ -67,7 +67,7 @@ class cli_ui_out : public ui_out
   virtual void do_message (const ui_file_style &style,
 			   const char *format, va_list args) override
     ATTRIBUTE_PRINTF (3,0);
-  virtual void do_wrap_hint (const char *identstring) override;
+  virtual void do_wrap_hint (int indent) override;
   virtual void do_flush () override;
   virtual void do_redirect (struct ui_file *outstream) override;
 
diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c
index eca92ef71d4..ff7a951778a 100644
--- a/gdb/cli/cli-cmds.c
+++ b/gdb/cli/cli-cmds.c
@@ -841,7 +841,7 @@ echo_command (const char *text, int from_tty)
   reset_terminal_style (gdb_stdout);
 
   /* Force this output to appear now.  */
-  wrap_here ("");
+  wrap_here (0);
   gdb_flush (gdb_stdout);
 }
 
diff --git a/gdb/cli/cli-decode.c b/gdb/cli/cli-decode.c
index 9b965ea9989..69cf808a4ee 100644
--- a/gdb/cli/cli-decode.c
+++ b/gdb/cli/cli-decode.c
@@ -1390,7 +1390,7 @@ fput_command_names_styled (const cmd_list_element &c,
 	continue;
 
       fputs_filtered (", ", stream);
-      wrap_here ("   ");
+      wrap_here (3);
       fput_command_name_styled (alias, stream);
     }
 
@@ -1627,7 +1627,7 @@ help_list (struct cmd_list_element *list, const char *cmdtype,
       fprintf_filtered (stream, "\n\
 Type \"help%s\" followed by a class name for a list of commands in ",
 			cmdtype1);
-      wrap_here ("");
+      wrap_here (0);
       fprintf_filtered (stream, "that class.");
 
       fprintf_filtered (stream, "\n\
@@ -1636,16 +1636,16 @@ Type \"help all\" for the list of all commands.");
 
   fprintf_filtered (stream, "\nType \"help%s\" followed by %scommand name ",
 		    cmdtype1, cmdtype2);
-  wrap_here ("");
+  wrap_here (0);
   fputs_filtered ("for ", stream);
-  wrap_here ("");
+  wrap_here (0);
   fputs_filtered ("full ", stream);
-  wrap_here ("");
+  wrap_here (0);
   fputs_filtered ("documentation.\n", stream);
   fputs_filtered ("Type \"apropos word\" to search "
 		  "for commands related to \"word\".\n", stream);
   fputs_filtered ("Type \"apropos -v word\" for full documentation", stream);
-  wrap_here ("");
+  wrap_here (0);
   fputs_filtered (" of commands related to \"word\".\n", stream);
   fputs_filtered ("Command name abbreviations are allowed if unambiguous.\n",
 		  stream);
diff --git a/gdb/cp-valprint.c b/gdb/cp-valprint.c
index 27884102e10..efa2de7f9c1 100644
--- a/gdb/cp-valprint.c
+++ b/gdb/cp-valprint.c
@@ -222,7 +222,7 @@ cp_print_value_fields (struct value *val, struct ui_file *stream,
 	    }
 	  else
 	    {
-	      wrap_here (n_spaces (2 + 2 * recurse));
+	      wrap_here (2 + 2 * recurse);
 	    }
 
 	  annotate_field_begin (type->field (i).type ());
diff --git a/gdb/disasm.c b/gdb/disasm.c
index 4d1ee6893f5..ad1706f570f 100644
--- a/gdb/disasm.c
+++ b/gdb/disasm.c
@@ -1118,7 +1118,7 @@ The following disassembler options are supported for use with the\n\
 	    fprintf_filtered (file, "%s", valid_options->arg[i]->name);
 	  if (valid_options->name[i + 1] != NULL)
 	    fprintf_filtered (file, ", ");
-	  wrap_here ("  ");
+	  wrap_here (2);
 	}
       fprintf_filtered (file, "\n");
     }
@@ -1136,7 +1136,7 @@ The following disassembler options are supported for use with the\n\
 	  for (j = 0; valid_args[i].values[j] != NULL; j++)
 	    {
 	      fprintf_filtered (file, " %s", valid_args[i].values[j]);
-	      wrap_here ("   ");
+	      wrap_here (3);
 	    }
 	  fprintf_filtered (file, "\n");
 	}
diff --git a/gdb/exceptions.c b/gdb/exceptions.c
index 5245b7ca28d..d3dd9617804 100644
--- a/gdb/exceptions.c
+++ b/gdb/exceptions.c
@@ -52,7 +52,7 @@ print_flush (void)
 
   /* 1.  The _filtered buffer.  */
   if (filtered_printing_initialized ())
-    wrap_here ("");
+    wrap_here (0);
 
   /* 2.  The stdio buffer.  */
   gdb_flush (gdb_stdout);
diff --git a/gdb/exec.c b/gdb/exec.c
index 3d4cbdfcf45..60237d0319f 100644
--- a/gdb/exec.c
+++ b/gdb/exec.c
@@ -908,7 +908,7 @@ print_section_info (const target_section_table *t, bfd *abfd)
   printf_filtered ("\t`%ps', ",
 		   styled_string (file_name_style.style (),
 				  bfd_get_filename (abfd)));
-  wrap_here ("        ");
+  wrap_here (8);
   printf_filtered (_("file type %s.\n"), bfd_get_target (abfd));
   if (abfd == current_program_space->exec_bfd ())
     {
diff --git a/gdb/f-typeprint.c b/gdb/f-typeprint.c
index 1791cb29451..18d7b8f1af1 100644
--- a/gdb/f-typeprint.c
+++ b/gdb/f-typeprint.c
@@ -250,7 +250,7 @@ f_language::f_type_print_varspec_suffix (struct type *type,
 	      if (i > 0)
 		{
 		  fputs_filtered (", ", stream);
-		  wrap_here ("    ");
+		  wrap_here (4);
 		}
 	      print_type (type->field (i).type (), "", stream, -1, 0, 0);
 	    }
@@ -290,7 +290,7 @@ f_language::f_type_print_base (struct type *type, struct ui_file *stream,
 
   QUIT;
 
-  wrap_here ("    ");
+  wrap_here (4);
   if (type == NULL)
     {
       fputs_styled ("<type unknown>", metadata_style.style (), stream);
diff --git a/gdb/guile/scm-pretty-print.c b/gdb/guile/scm-pretty-print.c
index 96a3ef584c9..92ea7efd904 100644
--- a/gdb/guile/scm-pretty-print.c
+++ b/gdb/guile/scm-pretty-print.c
@@ -861,7 +861,7 @@ ppscm_print_children (SCM printer, enum display_hint hint,
 	      print_spaces_filtered (2 + 2 * recurse, stream);
 	    }
 	  else
-	    wrap_here (n_spaces (2 + 2 *recurse));
+	    wrap_here (2 + 2 *recurse);
 	}
 
       if (is_map && i % 2 == 0)
diff --git a/gdb/m2-typeprint.c b/gdb/m2-typeprint.c
index c4504e7c266..4935c9c81a8 100644
--- a/gdb/m2-typeprint.c
+++ b/gdb/m2-typeprint.c
@@ -79,7 +79,7 @@ m2_print_type (struct type *type, const char *varstring,
 
   QUIT;
 
-  wrap_here ("    ");
+  wrap_here (4);
   if (type == NULL)
     {
       fputs_styled (_("<type unknown>"), metadata_style.style (), stream);
@@ -292,7 +292,7 @@ m2_procedure (struct type *type, struct ui_file *stream,
 	  if (i > 0)
 	    {
 	      fputs_filtered (", ", stream);
-	      wrap_here ("    ");
+	      wrap_here (4);
 	    }
 	  m2_print_type (type->field (i).type (), "", stream, -1, 0, flags);
 	}
@@ -539,7 +539,7 @@ m2_record_fields (struct type *type, struct ui_file *stream, int show,
 	    fprintf_filtered (stream, " = ");
 	}
     }
-  wrap_here ("    ");
+  wrap_here (4);
   if (show < 0)
     {
       if (type->code () == TYPE_CODE_STRUCT)
@@ -608,7 +608,7 @@ m2_enum (struct type *type, struct ui_file *stream, int show, int level)
 	  QUIT;
 	  if (i > 0)
 	    fprintf_filtered (stream, ", ");
-	  wrap_here ("    ");
+	  wrap_here (4);
 	  fputs_styled (type->field (i).name (),
 			variable_name_style.style (), stream);
 	  if (lastval != type->field (i).loc_enumval ())
diff --git a/gdb/main.c b/gdb/main.c
index 5e97f98e928..be71566ad2a 100644
--- a/gdb/main.c
+++ b/gdb/main.c
@@ -1121,7 +1121,7 @@ captured_main_1 (struct captured_main_args *context)
   if (print_version)
     {
       print_gdb_version (gdb_stdout, false);
-      wrap_here ("");
+      wrap_here (0);
       printf_filtered ("\n");
       exit (0);
     }
@@ -1135,7 +1135,7 @@ captured_main_1 (struct captured_main_args *context)
   if (print_configuration)
     {
       print_gdb_configuration (gdb_stdout);
-      wrap_here ("");
+      wrap_here (0);
       printf_filtered ("\n");
       exit (0);
     }
@@ -1151,7 +1151,7 @@ captured_main_1 (struct captured_main_args *context)
       print_gdb_version (gdb_stdout, true);
       if (symarg)
 	printf_filtered ("..");
-      wrap_here ("");
+      wrap_here (0);
       printf_filtered ("\n");
       gdb_flush (gdb_stdout);	/* Force to screen during slow
 				   operations.  */
@@ -1172,7 +1172,7 @@ captured_main_1 (struct captured_main_args *context)
       print_gdb_version (gdb_stdout, true);
       if (symarg)
 	printf_filtered ("..");
-      wrap_here ("");
+      wrap_here (0);
       printf_filtered ("\n");
       gdb_flush (gdb_stdout);	/* Force to screen during slow
 				   operations.  */
diff --git a/gdb/maint.c b/gdb/maint.c
index 4eb98384580..d460ebbcb93 100644
--- a/gdb/maint.c
+++ b/gdb/maint.c
@@ -364,9 +364,9 @@ maint_print_all_sections (const char *header, bfd *abfd, objfile *objfile,
 			  const char *arg)
 {
   puts_filtered (header);
-  wrap_here ("        ");
+  wrap_here (8);
   printf_filtered ("`%s', ", bfd_get_filename (abfd));
-  wrap_here ("        ");
+  wrap_here (8);
   printf_filtered (_("file type %s.\n"), bfd_get_target (abfd));
 
   int section_count = gdb_bfd_count_sections (abfd);
diff --git a/gdb/mi/mi-out.c b/gdb/mi/mi-out.c
index 0b223476167..6c0d2f04e48 100644
--- a/gdb/mi/mi-out.c
+++ b/gdb/mi/mi-out.c
@@ -172,9 +172,9 @@ mi_ui_out::do_message (const ui_file_style &style,
 }
 
 void
-mi_ui_out::do_wrap_hint (const char *identstring)
+mi_ui_out::do_wrap_hint (int indent)
 {
-  wrap_here (identstring);
+  wrap_here (indent);
 }
 
 void
diff --git a/gdb/mi/mi-out.h b/gdb/mi/mi-out.h
index 7941dc2896b..362917ea47a 100644
--- a/gdb/mi/mi-out.h
+++ b/gdb/mi/mi-out.h
@@ -76,7 +76,7 @@ class mi_ui_out : public ui_out
   virtual void do_message (const ui_file_style &style,
 			   const char *format, va_list args) override
     ATTRIBUTE_PRINTF (3,0);
-  virtual void do_wrap_hint (const char *identstring) override;
+  virtual void do_wrap_hint (int indent) override;
   virtual void do_flush () override;
   virtual void do_redirect (struct ui_file *outstream) override;
 
diff --git a/gdb/p-typeprint.c b/gdb/p-typeprint.c
index b2d167f68bf..b43f1362a6b 100644
--- a/gdb/p-typeprint.c
+++ b/gdb/p-typeprint.c
@@ -287,7 +287,7 @@ pascal_language::print_func_args (struct type *type, struct ui_file *stream,
       if (i > 0)
 	{
 	  fputs_filtered (", ", stream);
-	  wrap_here ("    ");
+	  wrap_here (4);
 	}
       /*  Can we find if it is a var parameter ??
 	  if ( TYPE_FIELD(type, i) == )
@@ -419,7 +419,7 @@ pascal_language::type_print_base (struct type *type, struct ui_file *stream, int
   section_type;
 
   QUIT;
-  wrap_here ("    ");
+  wrap_here (4);
   if (type == NULL)
     {
       fputs_styled ("<type unknown>", metadata_style.style (), stream);
@@ -487,7 +487,7 @@ pascal_language::type_print_base (struct type *type, struct ui_file *stream, int
       fprintf_filtered (stream, "case <?> of ");
 
     struct_union:
-      wrap_here ("    ");
+      wrap_here (4);
       if (show < 0)
 	{
 	  /* If we just printed a tag name, no need to print anything else.  */
@@ -692,7 +692,7 @@ pascal_language::type_print_base (struct type *type, struct ui_file *stream, int
       /* enum is just defined by
 	 type enume_name = (enum_member1,enum_member2,...)  */
       fprintf_filtered (stream, " = ");
-      wrap_here ("    ");
+      wrap_here (4);
       if (show < 0)
 	{
 	  /* If we just printed a tag name, no need to print anything else.  */
@@ -709,7 +709,7 @@ pascal_language::type_print_base (struct type *type, struct ui_file *stream, int
 	      QUIT;
 	      if (i)
 		fprintf_filtered (stream, ", ");
-	      wrap_here ("    ");
+	      wrap_here (4);
 	      fputs_filtered (type->field (i).name (), stream);
 	      if (lastval != type->field (i).loc_enumval ())
 		{
diff --git a/gdb/p-valprint.c b/gdb/p-valprint.c
index e3c524c3b59..91d01ca0c34 100644
--- a/gdb/p-valprint.c
+++ b/gdb/p-valprint.c
@@ -574,7 +574,7 @@ pascal_object_print_value_fields (struct value *val, struct ui_file *stream,
 	    }
 	  else
 	    {
-	      wrap_here (n_spaces (2 + 2 * recurse));
+	      wrap_here (2 + 2 * recurse);
 	    }
 
 	  annotate_field_begin (type->field (i).type ());
diff --git a/gdb/printcmd.c b/gdb/printcmd.c
index e408b19db63..ed97f39b056 100644
--- a/gdb/printcmd.c
+++ b/gdb/printcmd.c
@@ -317,7 +317,7 @@ print_formatted (struct value *val, int size,
 
 	case 'i':
 	  /* We often wrap here if there are long symbolic names.  */
-	  wrap_here ("    ");
+	  wrap_here (4);
 	  next_address = (value_address (val)
 			  + gdb_print_insn (type->arch (),
 					    value_address (val), stream,
@@ -826,7 +826,7 @@ find_instruction_backward (struct gdbarch *gdbarch, CORE_ADDR addr,
 	     is calculated after the loop.  */
 	  printf_filtered (_("No line number information available "
 			     "for address "));
-	  wrap_here ("  ");
+	  wrap_here (2);
 	  print_address (gdbarch, loop_start - 1, gdb_stdout);
 	  printf_filtered ("\n");
 	  break;
@@ -1498,7 +1498,7 @@ output_command (const char *exp, int from_tty)
 
   annotate_value_end ();
 
-  wrap_here ("");
+  wrap_here (0);
   gdb_flush (gdb_stdout);
 }
 
@@ -2895,7 +2895,7 @@ printf_command (const char *arg, int from_tty)
 {
   ui_printf (arg, gdb_stdout);
   reset_terminal_style (gdb_stdout);
-  wrap_here ("");
+  wrap_here (0);
   gdb_stdout->flush ();
 }
 
diff --git a/gdb/psymtab.c b/gdb/psymtab.c
index d0821b30271..4d9a9b67809 100644
--- a/gdb/psymtab.c
+++ b/gdb/psymtab.c
@@ -1421,11 +1421,11 @@ partial_symtab::expand_dependencies (struct objfile *objfile)
 	  if (info_verbose)
 	    {
 	      fputs_filtered (" ", gdb_stdout);
-	      wrap_here ("");
+	      wrap_here (0);
 	      fputs_filtered ("and ", gdb_stdout);
-	      wrap_here ("");
+	      wrap_here (0);
 	      printf_filtered ("%s...", dependencies[i]->filename);
-	      wrap_here ("");	/* Flush output */
+	      wrap_here (0);	/* Flush output */
 	      gdb_flush (gdb_stdout);
 	    }
 	  dependencies[i]->expand_psymtab (objfile);
@@ -1678,14 +1678,14 @@ maintenance_info_psymtabs (const char *regexp, int from_tty)
 		    if (! printed_objfile_start)
 		      {
 			printf_filtered ("{ objfile %s ", objfile_name (objfile));
-			wrap_here ("  ");
+			wrap_here (2);
 			printf_filtered ("((struct objfile *) %s)\n",
 					 host_address_to_string (objfile));
 			printed_objfile_start = 1;
 		      }
 
 		    printf_filtered ("  { psymtab %s ", psymtab->filename);
-		    wrap_here ("    ");
+		    wrap_here (4);
 		    printf_filtered ("((struct partial_symtab *) %s)\n",
 				     host_address_to_string (psymtab));
 
diff --git a/gdb/python/py-framefilter.c b/gdb/python/py-framefilter.c
index fd0b7f9e1f2..bb1b88dde93 100644
--- a/gdb/python/py-framefilter.c
+++ b/gdb/python/py-framefilter.c
@@ -501,7 +501,7 @@ enumerate_args (PyObject *iter,
 	      if (arg.entry_kind != print_entry_values_only)
 		{
 		  out->text (", ");
-		  out->wrap_hint ("    ");
+		  out->wrap_hint (4);
 		}
 
 	      py_print_single_arg (out, NULL, &entryarg, NULL, &opts,
@@ -705,7 +705,7 @@ py_print_args (PyObject *filter,
 
   ui_out_emit_list list_emitter (out, "args");
 
-  out->wrap_hint ("   ");
+  out->wrap_hint (3);
   annotate_frame_args ();
   out->text (" (");
 
@@ -984,7 +984,7 @@ py_print_frame (PyObject *filter, frame_filter_flags flags,
 	      if (filename == NULL)
 		return EXT_LANG_BT_ERROR;
 
-	      out->wrap_hint ("   ");
+	      out->wrap_hint (3);
 	      out->text (" at ");
 	      annotate_frame_source_file ();
 	      out->field_string ("file", filename.get (),
diff --git a/gdb/python/py-prettyprint.c b/gdb/python/py-prettyprint.c
index fe33747ca21..b7a5dbc2ede 100644
--- a/gdb/python/py-prettyprint.c
+++ b/gdb/python/py-prettyprint.c
@@ -474,7 +474,7 @@ print_children (PyObject *printer, const char *hint,
 	      print_spaces_filtered (2 + 2 * recurse, stream);
 	    }
 	  else
-	    wrap_here (n_spaces (2 + 2 *recurse));
+	    wrap_here (2 + 2 *recurse);
 	}
 
       if (is_map && i % 2 == 0)
diff --git a/gdb/source.c b/gdb/source.c
index f2f116091b3..4ea1db310d2 100644
--- a/gdb/source.c
+++ b/gdb/source.c
@@ -1547,7 +1547,7 @@ info_line_command (const char *arg, int from_tty)
 		 user about a source line, at least let them have the symbolic
 		 address.  */
 	      printf_filtered (" for address ");
-	      wrap_here ("  ");
+	      wrap_here (2);
 	      print_address (gdbarch, sal.pc, gdb_stdout);
 	    }
 	  else
@@ -1564,10 +1564,10 @@ info_line_command (const char *arg, int from_tty)
 	      printf_filtered ("Line %d of \"%s\"",
 			       sal.line,
 			       symtab_to_filename_for_display (sal.symtab));
-	      wrap_here ("  ");
+	      wrap_here (2);
 	      printf_filtered (" is at address ");
 	      print_address (gdbarch, start_pc, gdb_stdout);
-	      wrap_here ("  ");
+	      wrap_here (2);
 	      printf_filtered (" but contains no code.\n");
 	    }
 	  else
@@ -1575,10 +1575,10 @@ info_line_command (const char *arg, int from_tty)
 	      printf_filtered ("Line %d of \"%s\"",
 			       sal.line,
 			       symtab_to_filename_for_display (sal.symtab));
-	      wrap_here ("  ");
+	      wrap_here (2);
 	      printf_filtered (" starts at address ");
 	      print_address (gdbarch, start_pc, gdb_stdout);
-	      wrap_here ("  ");
+	      wrap_here (2);
 	      printf_filtered (" and ends at ");
 	      print_address (gdbarch, end_pc, gdb_stdout);
 	      printf_filtered (".\n");
diff --git a/gdb/stack.c b/gdb/stack.c
index 66517cf1860..adfda2921a0 100644
--- a/gdb/stack.c
+++ b/gdb/stack.c
@@ -874,7 +874,7 @@ print_frame_args (const frame_print_options &fp_opts,
 	  /* Print the current arg.  */
 	  if (!first)
 	    uiout->text (", ");
-	  uiout->wrap_hint ("    ");
+	  uiout->wrap_hint (4);
 
 	  if (!print_args)
 	    {
@@ -894,7 +894,7 @@ print_frame_args (const frame_print_options &fp_opts,
 	      if (arg.entry_kind != print_entry_values_only)
 		{
 		  uiout->text (", ");
-		  uiout->wrap_hint ("    ");
+		  uiout->wrap_hint (4);
 		}
 
 	      print_frame_arg (fp_opts, &entryarg);
@@ -1367,7 +1367,7 @@ print_frame (const frame_print_options &fp_opts,
     string_file stb;
     fputs_filtered (funname ? funname.get () : "??", &stb);
     uiout->field_stream ("func", stb, function_name_style.style ());
-    uiout->wrap_hint ("   ");
+    uiout->wrap_hint (3);
     annotate_frame_args ();
 
     uiout->text (" (");
@@ -1405,7 +1405,7 @@ print_frame (const frame_print_options &fp_opts,
       
 	filename_display = symtab_to_filename_for_display (sal.symtab);
 	annotate_frame_source_begin ();
-	uiout->wrap_hint ("   ");
+	uiout->wrap_hint (3);
 	uiout->text (" at ");
 	annotate_frame_source_file ();
 	uiout->field_string ("file", filename_display,
@@ -1432,7 +1432,7 @@ print_frame (const frame_print_options &fp_opts,
 	if (lib)
 	  {
 	    annotate_frame_where ();
-	    uiout->wrap_hint ("  ");
+	    uiout->wrap_hint (2);
 	    uiout->text (" from ");
 	    uiout->field_string ("from", lib, file_name_style.style ());
 	  }
@@ -1556,13 +1556,13 @@ info_frame_command_core (struct frame_info *fi, bool selected_frame_p)
   else
     fputs_styled ("<unavailable>", metadata_style.style (), gdb_stdout);
 
-  wrap_here ("   ");
+  wrap_here (3);
   if (funname)
     {
       printf_filtered (" in ");
       fputs_filtered (funname, gdb_stdout);
     }
-  wrap_here ("   ");
+  wrap_here (3);
   if (sal.symtab)
     printf_filtered
       (" (%ps:%d)",
@@ -1570,7 +1570,7 @@ info_frame_command_core (struct frame_info *fi, bool selected_frame_p)
 		      symtab_to_filename_for_display (sal.symtab)),
        sal.line);
   puts_filtered ("; ");
-  wrap_here ("    ");
+  wrap_here (4);
   printf_filtered ("saved %s = ", pc_regname);
 
   if (!frame_id_p (frame_unwind_caller_id (fi)))
@@ -1627,7 +1627,7 @@ info_frame_command_core (struct frame_info *fi, bool selected_frame_p)
     }
   if (get_next_frame (fi) && calling_frame_info)
     puts_filtered (",");
-  wrap_here ("   ");
+  wrap_here (3);
   if (get_next_frame (fi))
     {
       printf_filtered (" caller of frame at ");
@@ -1767,7 +1767,7 @@ info_frame_command_core (struct frame_info *fi, bool selected_frame_p)
 		puts_filtered (" Saved registers:\n ");
 	      else
 		puts_filtered (",");
-	      wrap_here (" ");
+	      wrap_here (1);
 	      printf_filtered (" %s at ",
 			       gdbarch_register_name (gdbarch, i));
 	      fputs_filtered (paddress (gdbarch, addr), gdb_stdout);
diff --git a/gdb/symfile.c b/gdb/symfile.c
index 6787f37d5c3..80502f205a3 100644
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -2606,9 +2606,9 @@ reread_symbols (int from_tty)
 
 	  if (!objfile_has_symbols (objfile))
 	    {
-	      wrap_here ("");
+	      wrap_here (0);
 	      printf_filtered (_("(no debugging symbols found)\n"));
-	      wrap_here ("");
+	      wrap_here (0);
 	    }
 
 	  /* We're done reading the symbol file; finish off complaints.  */
diff --git a/gdb/symmisc.c b/gdb/symmisc.c
index b5e3ef7acaa..217778b8a60 100644
--- a/gdb/symmisc.c
+++ b/gdb/symmisc.c
@@ -765,7 +765,7 @@ maintenance_info_symtabs (const char *regexp, int from_tty)
 		    if (! printed_objfile_start)
 		      {
 			printf_filtered ("{ objfile %s ", objfile_name (objfile));
-			wrap_here ("  ");
+			wrap_here (2);
 			printf_filtered ("((struct objfile *) %s)\n",
 					 host_address_to_string (objfile));
 			printed_objfile_start = 1;
@@ -815,7 +815,7 @@ maintenance_info_symtabs (const char *regexp, int from_tty)
 
 		    printf_filtered ("\t{ symtab %s ",
 				     symtab_to_filename_for_display (symtab));
-		    wrap_here ("    ");
+		    wrap_here (4);
 		    printf_filtered ("((struct symtab *) %s)\n",
 				     host_address_to_string (symtab));
 		    printf_filtered ("\t  fullname %s\n",
@@ -872,7 +872,7 @@ maintenance_check_symtabs (const char *ignore, int from_tty)
 		if (! printed_objfile_start)
 		  {
 		    printf_filtered ("{ objfile %s ", objfile_name (objfile));
-		    wrap_here ("  ");
+		    wrap_here (2);
 		    printf_filtered ("((struct objfile *) %s)\n",
 				     host_address_to_string (objfile));
 		    printed_objfile_start = 1;
diff --git a/gdb/symtab.c b/gdb/symtab.c
index d38628faf7c..ae2b230b13d 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -4380,7 +4380,7 @@ output_source_filename_data::output (const char *disp_name,
     m_uiout->text (", ");
   m_first = false;
 
-  wrap_here ("");
+  wrap_here (0);
   if (m_uiout->is_mi_like_p ())
     {
       m_uiout->field_string ("file", disp_name, file_name_style.style ());
diff --git a/gdb/top.c b/gdb/top.c
index 1f9e649a85d..94f308a85b9 100644
--- a/gdb/top.c
+++ b/gdb/top.c
@@ -1364,7 +1364,7 @@ command_line_input (const char *prompt_arg, const char *annotation_suffix)
       /* Make sure that all output has been output.  Some machines may
 	 let you get away with leaving out some of the gdb_flush, but
 	 not all.  */
-      wrap_here ("");
+      wrap_here (0);
       gdb_flush (gdb_stdout);
       gdb_flush (gdb_stderr);
 
diff --git a/gdb/tracepoint.c b/gdb/tracepoint.c
index 15506fdbf4e..ebd2879445f 100644
--- a/gdb/tracepoint.c
+++ b/gdb/tracepoint.c
@@ -2394,10 +2394,10 @@ tfind_line_command (const char *args, int from_tty)
 	  printf_filtered ("Line %d of \"%s\"",
 			   sal.line,
 			   symtab_to_filename_for_display (sal.symtab));
-	  wrap_here ("  ");
+	  wrap_here (2);
 	  printf_filtered (" is at address ");
 	  print_address (get_current_arch (), start_pc, gdb_stdout);
-	  wrap_here ("  ");
+	  wrap_here (2);
 	  printf_filtered (" but contains no code.\n");
 	  sal = find_pc_line (start_pc, 0);
 	  if (sal.line > 0
@@ -3659,8 +3659,6 @@ print_one_static_tracepoint_marker (int count,
 {
   struct symbol *sym;
 
-  char wrap_indent[80];
-  char extra_field_indent[80];
   struct ui_out *uiout = current_uiout;
 
   symtab_and_line sal;
@@ -3681,14 +3679,13 @@ print_one_static_tracepoint_marker (int count,
 		    !tracepoints.empty () ? 'y' : 'n');
   uiout->spaces (2);
 
-  strcpy (wrap_indent, "                                   ");
-
+  int wrap_indent = 35;
   if (gdbarch_addr_bit (marker.gdbarch) <= 32)
-    strcat (wrap_indent, "           ");
+    wrap_indent += 11;
   else
-    strcat (wrap_indent, "                   ");
+    wrap_indent += 19;
 
-  strcpy (extra_field_indent, "         ");
+  const char *extra_field_indent = "         ";
 
   uiout->field_core_addr ("addr", marker.gdbarch, marker.address);
 
diff --git a/gdb/ui-out.c b/gdb/ui-out.c
index fe0e18ba0c6..58b4461c838 100644
--- a/gdb/ui-out.c
+++ b/gdb/ui-out.c
@@ -790,9 +790,9 @@ ui_out::message (const char *format, ...)
 }
 
 void
-ui_out::wrap_hint (const char *identstring)
+ui_out::wrap_hint (int indent)
 {
-  do_wrap_hint (identstring);
+  do_wrap_hint (indent);
 }
 
 void
diff --git a/gdb/ui-out.h b/gdb/ui-out.h
index ecf62e8b601..4460eb7326e 100644
--- a/gdb/ui-out.h
+++ b/gdb/ui-out.h
@@ -257,7 +257,7 @@ class ui_out
   void vmessage (const ui_file_style &in_style,
 		 const char *format, va_list args) ATTRIBUTE_PRINTF (3, 0);
 
-  void wrap_hint (const char *identstring);
+  void wrap_hint (int indent);
 
   void flush ();
 
@@ -343,7 +343,7 @@ class ui_out
   virtual void do_message (const ui_file_style &style,
 			   const char *format, va_list args)
     ATTRIBUTE_PRINTF (3,0) = 0;
-  virtual void do_wrap_hint (const char *identstring) = 0;
+  virtual void do_wrap_hint (int indent) = 0;
   virtual void do_flush () = 0;
   virtual void do_redirect (struct ui_file *outstream) = 0;
 
diff --git a/gdb/utils.c b/gdb/utils.c
index f8c898dd502..6a0acf862a0 100644
--- a/gdb/utils.c
+++ b/gdb/utils.c
@@ -153,7 +153,7 @@ vwarning (const char *string, va_list args)
 	  target_terminal::ours_for_output ();
 	}
       if (filtered_printing_initialized ())
-	wrap_here ("");		/* Force out any buffered output.  */
+	wrap_here (0);		/* Force out any buffered output.  */
       gdb_flush (gdb_stdout);
       if (warning_pre_print)
 	fputs_unfiltered (warning_pre_print, gdb_stderr);
@@ -880,7 +880,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 ();
-      wrap_here ("");
+      wrap_here (0);
       vfprintf_filtered (gdb_stdout, ctlstr, args);
 
       printf_filtered (_("(%s or %s) [answered %c; "
@@ -1271,9 +1271,8 @@ static bool filter_initialized = false;
    already been counted in chars_printed).  */
 static std::string wrap_buffer;
 
-/* String to indent by if the wrap occurs.  Must not be NULL if wrap_column
-   is non-zero.  */
-static const char *wrap_indent;
+/* String to indent by if the wrap occurs.  */
+static int wrap_indent;
 
 /* Column number on the screen where wrap_buffer begins, or 0 if wrapping
    is not in effect.  */
@@ -1616,12 +1615,10 @@ get_chars_per_line ()
   return chars_per_line;
 }
 
-/* Indicate that if the next sequence of characters overflows the line,
-   a newline should be inserted here rather than when it hits the end.
-   If INDENT is non-null, it is a string to be printed to indent the
-   wrapped part on the next line.  INDENT must remain accessible until
-   the next call to wrap_here() or until a newline is printed through
-   fputs_filtered().
+/* Indicate that if the next sequence of characters overflows the
+   line, a newline should be inserted here rather than when it hits
+   the end.  If INDENT is non-zero, it is a number of spaces to be
+   printed to indent the wrapped part on the next line.
 
    If the line is already overfull, we immediately print a newline and
    the indentation, and disable further wrapping.
@@ -1630,15 +1627,12 @@ get_chars_per_line ()
    we must not wrap words, but should still keep track of newlines
    that were explicitly printed.
 
-   INDENT should not contain tabs, as that will mess up the char count
-   on the next line.  FIXME.
-
    This routine is guaranteed to force out any output which has been
-   squirreled away in the wrap_buffer, so wrap_here ((char *)0) can be
+   squirreled away in the wrap_buffer, so wrap_here (0) can be
    used to force out output from the wrap_buffer.  */
 
 void
-wrap_here (const char *indent)
+wrap_here (int indent)
 {
   /* This should have been allocated, but be paranoid anyway.  */
   gdb_assert (filter_initialized);
@@ -1651,17 +1645,14 @@ wrap_here (const char *indent)
   else if (chars_printed >= chars_per_line)
     {
       puts_filtered ("\n");
-      if (indent != NULL)
-	puts_filtered (indent);
+      if (indent != 0)
+	puts_filtered (n_spaces (indent));
       wrap_column = 0;
     }
   else
     {
       wrap_column = chars_printed;
-      if (indent == NULL)
-	wrap_indent = "";
-      else
-	wrap_indent = indent;
+      wrap_indent = indent;
       wrap_style = applied_style;
     }
 }
@@ -1767,7 +1758,7 @@ fputs_maybe_filtered (const char *linebuffer, struct ui_file *stream,
 		       {
 			 wrap_buffer.clear ();
 			 wrap_column = 0;
-			 wrap_indent = "";
+			 wrap_indent = 0;
 		       });
 
   /* Go through and output each character.  Show line extension
@@ -1872,7 +1863,7 @@ fputs_maybe_filtered (const char *linebuffer, struct ui_file *stream,
 	      /* Now output indentation and wrapped string.  */
 	      if (wrap_column)
 		{
-		  stream->puts (wrap_indent);
+		  stream->puts (n_spaces (wrap_indent));
 
 		  /* Having finished inserting the wrapping we should
 		     restore the style as it was at the WRAP_COLUMN.  */
@@ -1886,14 +1877,9 @@ fputs_maybe_filtered (const char *linebuffer, struct ui_file *stream,
 		     in WRAP_BUFFER.  */
 		  applied_style = save_style;
 
-		  /* FIXME, this strlen is what prevents wrap_indent from
-		     containing tabs.  However, if we recurse to print it
-		     and count its chars, we risk trouble if wrap_indent is
-		     longer than (the user settable) chars_per_line.
-		     Note also that this can set chars_printed > chars_per_line
+		  /* Note that this can set chars_printed > chars_per_line
 		     if we are printing a long string.  */
-		  chars_printed = strlen (wrap_indent)
-		    + (save_chars - wrap_column);
+		  chars_printed = wrap_indent + (save_chars - wrap_column);
 		  wrap_column = 0;	/* And disable fancy wrap */
 		}
 	      else if (did_paginate && stream->can_emit_style_escape ())
@@ -1904,8 +1890,8 @@ fputs_maybe_filtered (const char *linebuffer, struct ui_file *stream,
       if (*lineptr == '\n')
 	{
 	  chars_printed = 0;
-	  wrap_here ((char *) 0);	/* Spit out chars, cancel
-					   further wraps.  */
+	  wrap_here (0);	/* Spit out chars, cancel
+				   further wraps.  */
 	  lines_printed++;
 	  /* XXX: The ideal thing would be to call
 	     'stream->putc' here, but we can't because it
diff --git a/gdb/utils.h b/gdb/utils.h
index 54cf090974a..2db11679639 100644
--- a/gdb/utils.h
+++ b/gdb/utils.h
@@ -367,7 +367,7 @@ extern int yquery (const char *, ...) ATTRIBUTE_PRINTF (1, 2);
 
 extern void begin_line (void);
 
-extern void wrap_here (const char *);
+extern void wrap_here (int);
 
 extern void reinitialize_more_filter (void);
 
diff --git a/gdb/valprint.c b/gdb/valprint.c
index 4230dcec228..afecbee3d14 100644
--- a/gdb/valprint.c
+++ b/gdb/valprint.c
@@ -1946,7 +1946,7 @@ value_print_array_elements (struct value *val, struct ui_file *stream,
 	  fprintf_filtered (stream, "\n");
 	  print_spaces_filtered (2 + 2 * recurse, stream);
 	}
-      wrap_here (n_spaces (2 + 2 * recurse));
+      wrap_here (2 + 2 * recurse);
       maybe_print_array_index (index_type, i + low_bound,
 			       stream, options);
 
-- 
2.31.1


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

* [PATCH 2/4] Add ui_file::wrap_here
  2021-12-31 22:25 [PATCH 0/4] Clean up wrap_here function a little Tom Tromey
  2021-12-31 22:25 ` [PATCH 1/4] Convert wrap_here to use integer parameter Tom Tromey
@ 2021-12-31 22:25 ` Tom Tromey
  2021-12-31 22:25 ` [PATCH 3/4] Always call the wrap_here method Tom Tromey
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Tom Tromey @ 2021-12-31 22:25 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

Right now, wrap_here is a global function.  In the long run, we'd like
output streams to be relatively self-contained objects, and having a
global function like this is counter to that goal.  Also, existing
code freely mixes writes to some parameterized stream with calls to
wrap_here -- but wrap_here only really affects gdb_stdout, so this is
also incoherent.

This step is a patch toward making wrap_here more sane.  It adds a
wrap_here method to ui_file and changes ui_out implementations to use
it.
---
 gdb/cli-out.c   |  2 +-
 gdb/mi/mi-out.c |  2 +-
 gdb/ui-file.c   |  6 ++++++
 gdb/ui-file.h   | 17 +++++++++++++++++
 4 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/gdb/cli-out.c b/gdb/cli-out.c
index 68cf284cf44..02633e5bbbe 100644
--- a/gdb/cli-out.c
+++ b/gdb/cli-out.c
@@ -243,7 +243,7 @@ cli_ui_out::do_wrap_hint (int indent)
   if (m_suppress_output)
     return;
 
-  wrap_here (indent);
+  m_streams.back ()->wrap_here (indent);
 }
 
 void
diff --git a/gdb/mi/mi-out.c b/gdb/mi/mi-out.c
index 6c0d2f04e48..fe58adbbad5 100644
--- a/gdb/mi/mi-out.c
+++ b/gdb/mi/mi-out.c
@@ -174,7 +174,7 @@ mi_ui_out::do_message (const ui_file_style &style,
 void
 mi_ui_out::do_wrap_hint (int indent)
 {
-  wrap_here (indent);
+  m_streams.back ()->wrap_here (indent);
 }
 
 void
diff --git a/gdb/ui-file.c b/gdb/ui-file.c
index eb1d72bf8b3..bde90a9e6ed 100644
--- a/gdb/ui-file.c
+++ b/gdb/ui-file.c
@@ -68,6 +68,12 @@ ui_file::vprintf (const char *format, va_list args)
   vfprintf_unfiltered (this, format, args);
 }
 
+void
+ui_file::wrap_here (int indent)
+{
+  ::wrap_here (indent);
+}
+
 \f
 
 void
diff --git a/gdb/ui-file.h b/gdb/ui-file.h
index 0faf84996aa..4e72524b7f0 100644
--- a/gdb/ui-file.h
+++ b/gdb/ui-file.h
@@ -96,6 +96,23 @@ class ui_file
        default.  */
     return false;
   }
+
+  /* Indicate that if the next sequence of characters overflows the
+     line, a newline should be inserted here rather than when it hits
+     the end.  If INDENT is non-zero, it is a number of spaces to be
+     printed to indent the wrapped part on the next line.
+
+     If the line is already overfull, we immediately print a newline and
+     the indentation, and disable further wrapping.
+
+     If we don't know the width of lines, but we know the page height,
+     we must not wrap words, but should still keep track of newlines
+     that were explicitly printed.
+
+     This routine is guaranteed to force out any output which has been
+     squirreled away in the wrap_buffer, so wrap_here (0) can be
+     used to force out output from the wrap_buffer.  */
+  void wrap_here (int indent);
 };
 
 typedef std::unique_ptr<ui_file> ui_file_up;
-- 
2.31.1


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

* [PATCH 3/4] Always call the wrap_here method
  2021-12-31 22:25 [PATCH 0/4] Clean up wrap_here function a little Tom Tromey
  2021-12-31 22:25 ` [PATCH 1/4] Convert wrap_here to use integer parameter Tom Tromey
  2021-12-31 22:25 ` [PATCH 2/4] Add ui_file::wrap_here Tom Tromey
@ 2021-12-31 22:25 ` Tom Tromey
  2021-12-31 22:25 ` [PATCH 4/4] Remove global wrap_here function Tom Tromey
  2022-01-26 22:21 ` [PATCH 0/4] Clean up wrap_here function a little Tom Tromey
  4 siblings, 0 replies; 6+ messages in thread
From: Tom Tromey @ 2021-12-31 22:25 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This changes all existing calls to wrap_here to call the method on the
appropriate ui_file instead.  The choice of ui_file is determined by
context.
---
 gdb/ada-typeprint.c          |  8 ++++----
 gdb/ada-valprint.c           |  6 +++---
 gdb/c-typeprint.c            | 16 ++++++++--------
 gdb/cli/cli-cmds.c           |  2 +-
 gdb/cli/cli-decode.c         | 12 ++++++------
 gdb/cp-valprint.c            |  2 +-
 gdb/disasm.c                 |  4 ++--
 gdb/exceptions.c             |  2 +-
 gdb/exec.c                   |  2 +-
 gdb/f-typeprint.c            |  4 ++--
 gdb/guile/scm-pretty-print.c |  2 +-
 gdb/m2-typeprint.c           |  8 ++++----
 gdb/main.c                   |  8 ++++----
 gdb/maint.c                  |  4 ++--
 gdb/p-typeprint.c            | 10 +++++-----
 gdb/p-valprint.c             |  2 +-
 gdb/printcmd.c               |  8 ++++----
 gdb/psymtab.c                | 10 +++++-----
 gdb/python/py-prettyprint.c  |  2 +-
 gdb/source.c                 | 10 +++++-----
 gdb/stack.c                  | 10 +++++-----
 gdb/symfile.c                |  4 ++--
 gdb/symmisc.c                |  6 +++---
 gdb/symtab.c                 |  2 +-
 gdb/top.c                    |  2 +-
 gdb/tracepoint.c             |  4 ++--
 gdb/utils.c                  |  8 ++++----
 gdb/valprint.c               |  2 +-
 28 files changed, 80 insertions(+), 80 deletions(-)

diff --git a/gdb/ada-typeprint.c b/gdb/ada-typeprint.c
index 22cce5ec5b1..ed38d4b763a 100644
--- a/gdb/ada-typeprint.c
+++ b/gdb/ada-typeprint.c
@@ -317,7 +317,7 @@ print_enum_type (struct type *type, struct ui_file *stream)
   LONGEST lastval;
 
   fprintf_filtered (stream, "(");
-  wrap_here (1);
+  stream->wrap_here (1);
 
   lastval = 0;
   for (i = 0; i < len; i++)
@@ -325,7 +325,7 @@ print_enum_type (struct type *type, struct ui_file *stream)
       QUIT;
       if (i)
 	fprintf_filtered (stream, ", ");
-      wrap_here (4);
+      stream->wrap_here (4);
       fputs_styled (ada_enum_name (type->field (i).name ()),
 		    variable_name_style.style (), stream);
       if (lastval != type->field (i).loc_enumval ())
@@ -416,7 +416,7 @@ print_array_type (struct type *type, struct ui_file *stream, int show,
 
   elt_type = ada_array_element_type (type, n_indices);
   fprintf_filtered (stream, ") of ");
-  wrap_here (0);
+  stream->wrap_here (0);
   ada_print_type (elt_type, "", stream, show == 0 ? 0 : show - 1, level + 1,
 		  flags);
   /* Arrays with variable-length elements are never bit-packed in practice but
@@ -892,7 +892,7 @@ print_func_type (struct type *type, struct ui_file *stream, const char *name,
 	  if (i > 0)
 	    {
 	      fputs_filtered ("; ", stream);
-	      wrap_here (4);
+	      stream->wrap_here (4);
 	    }
 	  fprintf_filtered (stream, "a%d: ", i + 1);
 	  ada_print_type (type->field (i).type (), "", stream, -1, 0,
diff --git a/gdb/ada-valprint.c b/gdb/ada-valprint.c
index cc663e73ac6..910990a815f 100644
--- a/gdb/ada-valprint.c
+++ b/gdb/ada-valprint.c
@@ -178,7 +178,7 @@ val_print_packed_array_elements (struct type *type, const gdb_byte *valaddr,
 	  fprintf_filtered (stream, "\n");
 	  print_spaces_filtered (2 + 2 * recurse, stream);
 	}
-      wrap_here (2 + 2 * recurse);
+      stream->wrap_here (2 + 2 * recurse);
       maybe_print_array_index (index_type, i + low, stream, options);
 
       i0 = i;
@@ -235,7 +235,7 @@ val_print_packed_array_elements (struct type *type, const gdb_byte *valaddr,
 		    {
 		      fprintf_filtered (stream, ", ");
 		    }
-		  wrap_here (2 + 2 * recurse);
+		  stream->wrap_here (2 + 2 * recurse);
 		  maybe_print_array_index (index_type, j + low,
 					   stream, options);
 		}
@@ -614,7 +614,7 @@ print_field_values (struct value *value, struct value *outer_value,
 	}
       else
 	{
-	  wrap_here (2 + 2 * recurse);
+	  stream->wrap_here (2 + 2 * recurse);
 	}
 
       annotate_field_begin (type->field (i).type ());
diff --git a/gdb/c-typeprint.c b/gdb/c-typeprint.c
index 4bef48aae37..f4f71e8cc8e 100644
--- a/gdb/c-typeprint.c
+++ b/gdb/c-typeprint.c
@@ -250,7 +250,7 @@ cp_type_print_derivation_info (struct ui_file *stream,
 
   for (i = 0; i < TYPE_N_BASECLASSES (type); i++)
     {
-      wrap_here (8);
+      stream->wrap_here (8);
       fputs_filtered (i == 0 ? ": " : ", ", stream);
       fprintf_filtered (stream, "%s%s ",
 			BASETYPE_VIA_PUBLIC (type, i)
@@ -310,7 +310,7 @@ cp_type_print_method_args (struct type *mtype, const char *prefix,
 	  else if (i < nargs)
 	    {
 	      fprintf_filtered (stream, ", ");
-	      wrap_here (8);
+	      stream->wrap_here (8);
 	    }
 	}
     }
@@ -573,7 +573,7 @@ c_type_print_args (struct type *type, struct ui_file *stream,
       if (printed_any)
 	{
 	  fprintf_filtered (stream, ", ");
-	  wrap_here (4);
+	  stream->wrap_here (4);
 	}
 
       param_type = type->field (i).type ();
@@ -602,7 +602,7 @@ c_type_print_args (struct type *type, struct ui_file *stream,
       if (printed_any && type->has_varargs ())
 	{
 	  fprintf_filtered (stream, ", ");
-	  wrap_here (4);
+	  stream->wrap_here (4);
 	  fprintf_filtered (stream, "...");
 	}
     }
@@ -888,14 +888,14 @@ c_type_print_template_args (const struct type_print_options *flags,
 
       if (first)
 	{
-	  wrap_here (4);
+	  stream->wrap_here (4);
 	  fprintf_filtered (stream, _("[with %s = "), sym->linkage_name ());
 	  first = 0;
 	}
       else
 	{
 	  fputs_filtered (", ", stream);
-	  wrap_here (9);
+	  stream->wrap_here (9);
 	  fprintf_filtered (stream, "%s = ", sym->linkage_name ());
 	}
 
@@ -1559,7 +1559,7 @@ c_type_print_base_1 (struct type *type, struct ui_file *stream,
 	    fputs_filtered (" ", stream);
 	}
 
-      wrap_here (4);
+      stream->wrap_here (4);
       if (show < 0)
 	{
 	  /* If we just printed a tag name, no need to print anything
@@ -1594,7 +1594,7 @@ c_type_print_base_1 (struct type *type, struct ui_file *stream,
 	      QUIT;
 	      if (i)
 		fprintf_filtered (stream, ", ");
-	      wrap_here (4);
+	      stream->wrap_here (4);
 	      fputs_styled (type->field (i).name (),
 			    variable_name_style.style (), stream);
 	      if (lastval != type->field (i).loc_enumval ())
diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c
index ff7a951778a..1370f160b89 100644
--- a/gdb/cli/cli-cmds.c
+++ b/gdb/cli/cli-cmds.c
@@ -841,7 +841,7 @@ echo_command (const char *text, int from_tty)
   reset_terminal_style (gdb_stdout);
 
   /* Force this output to appear now.  */
-  wrap_here (0);
+  gdb_stdout->wrap_here (0);
   gdb_flush (gdb_stdout);
 }
 
diff --git a/gdb/cli/cli-decode.c b/gdb/cli/cli-decode.c
index 69cf808a4ee..64737283830 100644
--- a/gdb/cli/cli-decode.c
+++ b/gdb/cli/cli-decode.c
@@ -1390,7 +1390,7 @@ fput_command_names_styled (const cmd_list_element &c,
 	continue;
 
       fputs_filtered (", ", stream);
-      wrap_here (3);
+      stream->wrap_here (3);
       fput_command_name_styled (alias, stream);
     }
 
@@ -1627,7 +1627,7 @@ help_list (struct cmd_list_element *list, const char *cmdtype,
       fprintf_filtered (stream, "\n\
 Type \"help%s\" followed by a class name for a list of commands in ",
 			cmdtype1);
-      wrap_here (0);
+      stream->wrap_here (0);
       fprintf_filtered (stream, "that class.");
 
       fprintf_filtered (stream, "\n\
@@ -1636,16 +1636,16 @@ Type \"help all\" for the list of all commands.");
 
   fprintf_filtered (stream, "\nType \"help%s\" followed by %scommand name ",
 		    cmdtype1, cmdtype2);
-  wrap_here (0);
+  stream->wrap_here (0);
   fputs_filtered ("for ", stream);
-  wrap_here (0);
+  stream->wrap_here (0);
   fputs_filtered ("full ", stream);
-  wrap_here (0);
+  stream->wrap_here (0);
   fputs_filtered ("documentation.\n", stream);
   fputs_filtered ("Type \"apropos word\" to search "
 		  "for commands related to \"word\".\n", stream);
   fputs_filtered ("Type \"apropos -v word\" for full documentation", stream);
-  wrap_here (0);
+  stream->wrap_here (0);
   fputs_filtered (" of commands related to \"word\".\n", stream);
   fputs_filtered ("Command name abbreviations are allowed if unambiguous.\n",
 		  stream);
diff --git a/gdb/cp-valprint.c b/gdb/cp-valprint.c
index efa2de7f9c1..e7c232156ff 100644
--- a/gdb/cp-valprint.c
+++ b/gdb/cp-valprint.c
@@ -222,7 +222,7 @@ cp_print_value_fields (struct value *val, struct ui_file *stream,
 	    }
 	  else
 	    {
-	      wrap_here (2 + 2 * recurse);
+	      stream->wrap_here (2 + 2 * recurse);
 	    }
 
 	  annotate_field_begin (type->field (i).type ());
diff --git a/gdb/disasm.c b/gdb/disasm.c
index ad1706f570f..29947ef440f 100644
--- a/gdb/disasm.c
+++ b/gdb/disasm.c
@@ -1118,7 +1118,7 @@ The following disassembler options are supported for use with the\n\
 	    fprintf_filtered (file, "%s", valid_options->arg[i]->name);
 	  if (valid_options->name[i + 1] != NULL)
 	    fprintf_filtered (file, ", ");
-	  wrap_here (2);
+	  file->wrap_here (2);
 	}
       fprintf_filtered (file, "\n");
     }
@@ -1136,7 +1136,7 @@ The following disassembler options are supported for use with the\n\
 	  for (j = 0; valid_args[i].values[j] != NULL; j++)
 	    {
 	      fprintf_filtered (file, " %s", valid_args[i].values[j]);
-	      wrap_here (3);
+	      file->wrap_here (3);
 	    }
 	  fprintf_filtered (file, "\n");
 	}
diff --git a/gdb/exceptions.c b/gdb/exceptions.c
index d3dd9617804..f009981007f 100644
--- a/gdb/exceptions.c
+++ b/gdb/exceptions.c
@@ -52,7 +52,7 @@ print_flush (void)
 
   /* 1.  The _filtered buffer.  */
   if (filtered_printing_initialized ())
-    wrap_here (0);
+    gdb_stdout->wrap_here (0);
 
   /* 2.  The stdio buffer.  */
   gdb_flush (gdb_stdout);
diff --git a/gdb/exec.c b/gdb/exec.c
index 60237d0319f..81f3a44264f 100644
--- a/gdb/exec.c
+++ b/gdb/exec.c
@@ -908,7 +908,7 @@ print_section_info (const target_section_table *t, bfd *abfd)
   printf_filtered ("\t`%ps', ",
 		   styled_string (file_name_style.style (),
 				  bfd_get_filename (abfd)));
-  wrap_here (8);
+  gdb_stdout->wrap_here (8);
   printf_filtered (_("file type %s.\n"), bfd_get_target (abfd));
   if (abfd == current_program_space->exec_bfd ())
     {
diff --git a/gdb/f-typeprint.c b/gdb/f-typeprint.c
index 18d7b8f1af1..fe27e5bb560 100644
--- a/gdb/f-typeprint.c
+++ b/gdb/f-typeprint.c
@@ -250,7 +250,7 @@ f_language::f_type_print_varspec_suffix (struct type *type,
 	      if (i > 0)
 		{
 		  fputs_filtered (", ", stream);
-		  wrap_here (4);
+		  stream->wrap_here (4);
 		}
 	      print_type (type->field (i).type (), "", stream, -1, 0, 0);
 	    }
@@ -290,7 +290,7 @@ f_language::f_type_print_base (struct type *type, struct ui_file *stream,
 
   QUIT;
 
-  wrap_here (4);
+  stream->wrap_here (4);
   if (type == NULL)
     {
       fputs_styled ("<type unknown>", metadata_style.style (), stream);
diff --git a/gdb/guile/scm-pretty-print.c b/gdb/guile/scm-pretty-print.c
index 92ea7efd904..ab06f341b47 100644
--- a/gdb/guile/scm-pretty-print.c
+++ b/gdb/guile/scm-pretty-print.c
@@ -861,7 +861,7 @@ ppscm_print_children (SCM printer, enum display_hint hint,
 	      print_spaces_filtered (2 + 2 * recurse, stream);
 	    }
 	  else
-	    wrap_here (2 + 2 *recurse);
+	    stream->wrap_here (2 + 2 *recurse);
 	}
 
       if (is_map && i % 2 == 0)
diff --git a/gdb/m2-typeprint.c b/gdb/m2-typeprint.c
index 4935c9c81a8..c7aabe3af49 100644
--- a/gdb/m2-typeprint.c
+++ b/gdb/m2-typeprint.c
@@ -79,7 +79,7 @@ m2_print_type (struct type *type, const char *varstring,
 
   QUIT;
 
-  wrap_here (4);
+  stream->wrap_here (4);
   if (type == NULL)
     {
       fputs_styled (_("<type unknown>"), metadata_style.style (), stream);
@@ -292,7 +292,7 @@ m2_procedure (struct type *type, struct ui_file *stream,
 	  if (i > 0)
 	    {
 	      fputs_filtered (", ", stream);
-	      wrap_here (4);
+	      stream->wrap_here (4);
 	    }
 	  m2_print_type (type->field (i).type (), "", stream, -1, 0, flags);
 	}
@@ -539,7 +539,7 @@ m2_record_fields (struct type *type, struct ui_file *stream, int show,
 	    fprintf_filtered (stream, " = ");
 	}
     }
-  wrap_here (4);
+  stream->wrap_here (4);
   if (show < 0)
     {
       if (type->code () == TYPE_CODE_STRUCT)
@@ -608,7 +608,7 @@ m2_enum (struct type *type, struct ui_file *stream, int show, int level)
 	  QUIT;
 	  if (i > 0)
 	    fprintf_filtered (stream, ", ");
-	  wrap_here (4);
+	  stream->wrap_here (4);
 	  fputs_styled (type->field (i).name (),
 			variable_name_style.style (), stream);
 	  if (lastval != type->field (i).loc_enumval ())
diff --git a/gdb/main.c b/gdb/main.c
index be71566ad2a..9e57b3520ad 100644
--- a/gdb/main.c
+++ b/gdb/main.c
@@ -1121,7 +1121,7 @@ captured_main_1 (struct captured_main_args *context)
   if (print_version)
     {
       print_gdb_version (gdb_stdout, false);
-      wrap_here (0);
+      gdb_stdout->wrap_here (0);
       printf_filtered ("\n");
       exit (0);
     }
@@ -1135,7 +1135,7 @@ captured_main_1 (struct captured_main_args *context)
   if (print_configuration)
     {
       print_gdb_configuration (gdb_stdout);
-      wrap_here (0);
+      gdb_stdout->wrap_here (0);
       printf_filtered ("\n");
       exit (0);
     }
@@ -1151,7 +1151,7 @@ captured_main_1 (struct captured_main_args *context)
       print_gdb_version (gdb_stdout, true);
       if (symarg)
 	printf_filtered ("..");
-      wrap_here (0);
+      gdb_stdout->wrap_here (0);
       printf_filtered ("\n");
       gdb_flush (gdb_stdout);	/* Force to screen during slow
 				   operations.  */
@@ -1172,7 +1172,7 @@ captured_main_1 (struct captured_main_args *context)
       print_gdb_version (gdb_stdout, true);
       if (symarg)
 	printf_filtered ("..");
-      wrap_here (0);
+      gdb_stdout->wrap_here (0);
       printf_filtered ("\n");
       gdb_flush (gdb_stdout);	/* Force to screen during slow
 				   operations.  */
diff --git a/gdb/maint.c b/gdb/maint.c
index d460ebbcb93..0ad4dd5ddde 100644
--- a/gdb/maint.c
+++ b/gdb/maint.c
@@ -364,9 +364,9 @@ maint_print_all_sections (const char *header, bfd *abfd, objfile *objfile,
 			  const char *arg)
 {
   puts_filtered (header);
-  wrap_here (8);
+  gdb_stdout->wrap_here (8);
   printf_filtered ("`%s', ", bfd_get_filename (abfd));
-  wrap_here (8);
+  gdb_stdout->wrap_here (8);
   printf_filtered (_("file type %s.\n"), bfd_get_target (abfd));
 
   int section_count = gdb_bfd_count_sections (abfd);
diff --git a/gdb/p-typeprint.c b/gdb/p-typeprint.c
index b43f1362a6b..d9dedffaaa2 100644
--- a/gdb/p-typeprint.c
+++ b/gdb/p-typeprint.c
@@ -287,7 +287,7 @@ pascal_language::print_func_args (struct type *type, struct ui_file *stream,
       if (i > 0)
 	{
 	  fputs_filtered (", ", stream);
-	  wrap_here (4);
+	  stream->wrap_here (4);
 	}
       /*  Can we find if it is a var parameter ??
 	  if ( TYPE_FIELD(type, i) == )
@@ -419,7 +419,7 @@ pascal_language::type_print_base (struct type *type, struct ui_file *stream, int
   section_type;
 
   QUIT;
-  wrap_here (4);
+  stream->wrap_here (4);
   if (type == NULL)
     {
       fputs_styled ("<type unknown>", metadata_style.style (), stream);
@@ -487,7 +487,7 @@ pascal_language::type_print_base (struct type *type, struct ui_file *stream, int
       fprintf_filtered (stream, "case <?> of ");
 
     struct_union:
-      wrap_here (4);
+      stream->wrap_here (4);
       if (show < 0)
 	{
 	  /* If we just printed a tag name, no need to print anything else.  */
@@ -692,7 +692,7 @@ pascal_language::type_print_base (struct type *type, struct ui_file *stream, int
       /* enum is just defined by
 	 type enume_name = (enum_member1,enum_member2,...)  */
       fprintf_filtered (stream, " = ");
-      wrap_here (4);
+      stream->wrap_here (4);
       if (show < 0)
 	{
 	  /* If we just printed a tag name, no need to print anything else.  */
@@ -709,7 +709,7 @@ pascal_language::type_print_base (struct type *type, struct ui_file *stream, int
 	      QUIT;
 	      if (i)
 		fprintf_filtered (stream, ", ");
-	      wrap_here (4);
+	      stream->wrap_here (4);
 	      fputs_filtered (type->field (i).name (), stream);
 	      if (lastval != type->field (i).loc_enumval ())
 		{
diff --git a/gdb/p-valprint.c b/gdb/p-valprint.c
index 91d01ca0c34..85193569cc8 100644
--- a/gdb/p-valprint.c
+++ b/gdb/p-valprint.c
@@ -574,7 +574,7 @@ pascal_object_print_value_fields (struct value *val, struct ui_file *stream,
 	    }
 	  else
 	    {
-	      wrap_here (2 + 2 * recurse);
+	      stream->wrap_here (2 + 2 * recurse);
 	    }
 
 	  annotate_field_begin (type->field (i).type ());
diff --git a/gdb/printcmd.c b/gdb/printcmd.c
index ed97f39b056..5b26b6c818e 100644
--- a/gdb/printcmd.c
+++ b/gdb/printcmd.c
@@ -317,7 +317,7 @@ print_formatted (struct value *val, int size,
 
 	case 'i':
 	  /* We often wrap here if there are long symbolic names.  */
-	  wrap_here (4);
+	  stream->wrap_here (4);
 	  next_address = (value_address (val)
 			  + gdb_print_insn (type->arch (),
 					    value_address (val), stream,
@@ -826,7 +826,7 @@ find_instruction_backward (struct gdbarch *gdbarch, CORE_ADDR addr,
 	     is calculated after the loop.  */
 	  printf_filtered (_("No line number information available "
 			     "for address "));
-	  wrap_here (2);
+	  gdb_stdout->wrap_here (2);
 	  print_address (gdbarch, loop_start - 1, gdb_stdout);
 	  printf_filtered ("\n");
 	  break;
@@ -1498,7 +1498,7 @@ output_command (const char *exp, int from_tty)
 
   annotate_value_end ();
 
-  wrap_here (0);
+  gdb_stdout->wrap_here (0);
   gdb_flush (gdb_stdout);
 }
 
@@ -2895,7 +2895,7 @@ printf_command (const char *arg, int from_tty)
 {
   ui_printf (arg, gdb_stdout);
   reset_terminal_style (gdb_stdout);
-  wrap_here (0);
+  gdb_stdout->wrap_here (0);
   gdb_stdout->flush ();
 }
 
diff --git a/gdb/psymtab.c b/gdb/psymtab.c
index 4d9a9b67809..3df3cd55107 100644
--- a/gdb/psymtab.c
+++ b/gdb/psymtab.c
@@ -1421,11 +1421,11 @@ partial_symtab::expand_dependencies (struct objfile *objfile)
 	  if (info_verbose)
 	    {
 	      fputs_filtered (" ", gdb_stdout);
-	      wrap_here (0);
+	      gdb_stdout->wrap_here (0);
 	      fputs_filtered ("and ", gdb_stdout);
-	      wrap_here (0);
+	      gdb_stdout->wrap_here (0);
 	      printf_filtered ("%s...", dependencies[i]->filename);
-	      wrap_here (0);	/* Flush output */
+	      gdb_stdout->wrap_here (0);	/* Flush output */
 	      gdb_flush (gdb_stdout);
 	    }
 	  dependencies[i]->expand_psymtab (objfile);
@@ -1678,14 +1678,14 @@ maintenance_info_psymtabs (const char *regexp, int from_tty)
 		    if (! printed_objfile_start)
 		      {
 			printf_filtered ("{ objfile %s ", objfile_name (objfile));
-			wrap_here (2);
+			gdb_stdout->wrap_here (2);
 			printf_filtered ("((struct objfile *) %s)\n",
 					 host_address_to_string (objfile));
 			printed_objfile_start = 1;
 		      }
 
 		    printf_filtered ("  { psymtab %s ", psymtab->filename);
-		    wrap_here (4);
+		    gdb_stdout->wrap_here (4);
 		    printf_filtered ("((struct partial_symtab *) %s)\n",
 				     host_address_to_string (psymtab));
 
diff --git a/gdb/python/py-prettyprint.c b/gdb/python/py-prettyprint.c
index b7a5dbc2ede..6ac96cd8a1c 100644
--- a/gdb/python/py-prettyprint.c
+++ b/gdb/python/py-prettyprint.c
@@ -474,7 +474,7 @@ print_children (PyObject *printer, const char *hint,
 	      print_spaces_filtered (2 + 2 * recurse, stream);
 	    }
 	  else
-	    wrap_here (2 + 2 *recurse);
+	    stream->wrap_here (2 + 2 *recurse);
 	}
 
       if (is_map && i % 2 == 0)
diff --git a/gdb/source.c b/gdb/source.c
index 4ea1db310d2..52858c3e30d 100644
--- a/gdb/source.c
+++ b/gdb/source.c
@@ -1547,7 +1547,7 @@ info_line_command (const char *arg, int from_tty)
 		 user about a source line, at least let them have the symbolic
 		 address.  */
 	      printf_filtered (" for address ");
-	      wrap_here (2);
+	      gdb_stdout->wrap_here (2);
 	      print_address (gdbarch, sal.pc, gdb_stdout);
 	    }
 	  else
@@ -1564,10 +1564,10 @@ info_line_command (const char *arg, int from_tty)
 	      printf_filtered ("Line %d of \"%s\"",
 			       sal.line,
 			       symtab_to_filename_for_display (sal.symtab));
-	      wrap_here (2);
+	      gdb_stdout->wrap_here (2);
 	      printf_filtered (" is at address ");
 	      print_address (gdbarch, start_pc, gdb_stdout);
-	      wrap_here (2);
+	      gdb_stdout->wrap_here (2);
 	      printf_filtered (" but contains no code.\n");
 	    }
 	  else
@@ -1575,10 +1575,10 @@ info_line_command (const char *arg, int from_tty)
 	      printf_filtered ("Line %d of \"%s\"",
 			       sal.line,
 			       symtab_to_filename_for_display (sal.symtab));
-	      wrap_here (2);
+	      gdb_stdout->wrap_here (2);
 	      printf_filtered (" starts at address ");
 	      print_address (gdbarch, start_pc, gdb_stdout);
-	      wrap_here (2);
+	      gdb_stdout->wrap_here (2);
 	      printf_filtered (" and ends at ");
 	      print_address (gdbarch, end_pc, gdb_stdout);
 	      printf_filtered (".\n");
diff --git a/gdb/stack.c b/gdb/stack.c
index adfda2921a0..dbf0d593395 100644
--- a/gdb/stack.c
+++ b/gdb/stack.c
@@ -1556,13 +1556,13 @@ info_frame_command_core (struct frame_info *fi, bool selected_frame_p)
   else
     fputs_styled ("<unavailable>", metadata_style.style (), gdb_stdout);
 
-  wrap_here (3);
+  gdb_stdout->wrap_here (3);
   if (funname)
     {
       printf_filtered (" in ");
       fputs_filtered (funname, gdb_stdout);
     }
-  wrap_here (3);
+  gdb_stdout->wrap_here (3);
   if (sal.symtab)
     printf_filtered
       (" (%ps:%d)",
@@ -1570,7 +1570,7 @@ info_frame_command_core (struct frame_info *fi, bool selected_frame_p)
 		      symtab_to_filename_for_display (sal.symtab)),
        sal.line);
   puts_filtered ("; ");
-  wrap_here (4);
+  gdb_stdout->wrap_here (4);
   printf_filtered ("saved %s = ", pc_regname);
 
   if (!frame_id_p (frame_unwind_caller_id (fi)))
@@ -1627,7 +1627,7 @@ info_frame_command_core (struct frame_info *fi, bool selected_frame_p)
     }
   if (get_next_frame (fi) && calling_frame_info)
     puts_filtered (",");
-  wrap_here (3);
+  gdb_stdout->wrap_here (3);
   if (get_next_frame (fi))
     {
       printf_filtered (" caller of frame at ");
@@ -1767,7 +1767,7 @@ info_frame_command_core (struct frame_info *fi, bool selected_frame_p)
 		puts_filtered (" Saved registers:\n ");
 	      else
 		puts_filtered (",");
-	      wrap_here (1);
+	      gdb_stdout->wrap_here (1);
 	      printf_filtered (" %s at ",
 			       gdbarch_register_name (gdbarch, i));
 	      fputs_filtered (paddress (gdbarch, addr), gdb_stdout);
diff --git a/gdb/symfile.c b/gdb/symfile.c
index 80502f205a3..dc0f4f9ae27 100644
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -2606,9 +2606,9 @@ reread_symbols (int from_tty)
 
 	  if (!objfile_has_symbols (objfile))
 	    {
-	      wrap_here (0);
+	      gdb_stdout->wrap_here (0);
 	      printf_filtered (_("(no debugging symbols found)\n"));
-	      wrap_here (0);
+	      gdb_stdout->wrap_here (0);
 	    }
 
 	  /* We're done reading the symbol file; finish off complaints.  */
diff --git a/gdb/symmisc.c b/gdb/symmisc.c
index 217778b8a60..6fd49656a19 100644
--- a/gdb/symmisc.c
+++ b/gdb/symmisc.c
@@ -765,7 +765,7 @@ maintenance_info_symtabs (const char *regexp, int from_tty)
 		    if (! printed_objfile_start)
 		      {
 			printf_filtered ("{ objfile %s ", objfile_name (objfile));
-			wrap_here (2);
+			gdb_stdout->wrap_here (2);
 			printf_filtered ("((struct objfile *) %s)\n",
 					 host_address_to_string (objfile));
 			printed_objfile_start = 1;
@@ -815,7 +815,7 @@ maintenance_info_symtabs (const char *regexp, int from_tty)
 
 		    printf_filtered ("\t{ symtab %s ",
 				     symtab_to_filename_for_display (symtab));
-		    wrap_here (4);
+		    gdb_stdout->wrap_here (4);
 		    printf_filtered ("((struct symtab *) %s)\n",
 				     host_address_to_string (symtab));
 		    printf_filtered ("\t  fullname %s\n",
@@ -872,7 +872,7 @@ maintenance_check_symtabs (const char *ignore, int from_tty)
 		if (! printed_objfile_start)
 		  {
 		    printf_filtered ("{ objfile %s ", objfile_name (objfile));
-		    wrap_here (2);
+		    gdb_stdout->wrap_here (2);
 		    printf_filtered ("((struct objfile *) %s)\n",
 				     host_address_to_string (objfile));
 		    printed_objfile_start = 1;
diff --git a/gdb/symtab.c b/gdb/symtab.c
index ae2b230b13d..84c29b86453 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -4380,7 +4380,7 @@ output_source_filename_data::output (const char *disp_name,
     m_uiout->text (", ");
   m_first = false;
 
-  wrap_here (0);
+  m_uiout->wrap_hint (0);
   if (m_uiout->is_mi_like_p ())
     {
       m_uiout->field_string ("file", disp_name, file_name_style.style ());
diff --git a/gdb/top.c b/gdb/top.c
index 94f308a85b9..565b647491d 100644
--- a/gdb/top.c
+++ b/gdb/top.c
@@ -1364,7 +1364,7 @@ command_line_input (const char *prompt_arg, const char *annotation_suffix)
       /* Make sure that all output has been output.  Some machines may
 	 let you get away with leaving out some of the gdb_flush, but
 	 not all.  */
-      wrap_here (0);
+      gdb_stdout->wrap_here (0);
       gdb_flush (gdb_stdout);
       gdb_flush (gdb_stderr);
 
diff --git a/gdb/tracepoint.c b/gdb/tracepoint.c
index ebd2879445f..4f0ae8f5c61 100644
--- a/gdb/tracepoint.c
+++ b/gdb/tracepoint.c
@@ -2394,10 +2394,10 @@ tfind_line_command (const char *args, int from_tty)
 	  printf_filtered ("Line %d of \"%s\"",
 			   sal.line,
 			   symtab_to_filename_for_display (sal.symtab));
-	  wrap_here (2);
+	  gdb_stdout->wrap_here (2);
 	  printf_filtered (" is at address ");
 	  print_address (get_current_arch (), start_pc, gdb_stdout);
-	  wrap_here (2);
+	  gdb_stdout->wrap_here (2);
 	  printf_filtered (" but contains no code.\n");
 	  sal = find_pc_line (start_pc, 0);
 	  if (sal.line > 0
diff --git a/gdb/utils.c b/gdb/utils.c
index 6a0acf862a0..eebdfd57963 100644
--- a/gdb/utils.c
+++ b/gdb/utils.c
@@ -153,7 +153,7 @@ vwarning (const char *string, va_list args)
 	  target_terminal::ours_for_output ();
 	}
       if (filtered_printing_initialized ())
-	wrap_here (0);		/* Force out any buffered output.  */
+	gdb_stdout->wrap_here (0);	/* Force out any buffered output.  */
       gdb_flush (gdb_stdout);
       if (warning_pre_print)
 	fputs_unfiltered (warning_pre_print, gdb_stderr);
@@ -880,7 +880,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 ();
-      wrap_here (0);
+      gdb_stdout->wrap_here (0);
       vfprintf_filtered (gdb_stdout, ctlstr, args);
 
       printf_filtered (_("(%s or %s) [answered %c; "
@@ -1890,8 +1890,8 @@ fputs_maybe_filtered (const char *linebuffer, struct ui_file *stream,
       if (*lineptr == '\n')
 	{
 	  chars_printed = 0;
-	  wrap_here (0);	/* Spit out chars, cancel
-				   further wraps.  */
+	  stream->wrap_here (0); /* Spit out chars, cancel
+				    further wraps.  */
 	  lines_printed++;
 	  /* XXX: The ideal thing would be to call
 	     'stream->putc' here, but we can't because it
diff --git a/gdb/valprint.c b/gdb/valprint.c
index afecbee3d14..e91dcd9d490 100644
--- a/gdb/valprint.c
+++ b/gdb/valprint.c
@@ -1946,7 +1946,7 @@ value_print_array_elements (struct value *val, struct ui_file *stream,
 	  fprintf_filtered (stream, "\n");
 	  print_spaces_filtered (2 + 2 * recurse, stream);
 	}
-      wrap_here (2 + 2 * recurse);
+      stream->wrap_here (2 + 2 * recurse);
       maybe_print_array_index (index_type, i + low_bound,
 			       stream, options);
 
-- 
2.31.1


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

* [PATCH 4/4] Remove global wrap_here function
  2021-12-31 22:25 [PATCH 0/4] Clean up wrap_here function a little Tom Tromey
                   ` (2 preceding siblings ...)
  2021-12-31 22:25 ` [PATCH 3/4] Always call the wrap_here method Tom Tromey
@ 2021-12-31 22:25 ` Tom Tromey
  2022-01-26 22:21 ` [PATCH 0/4] Clean up wrap_here function a little Tom Tromey
  4 siblings, 0 replies; 6+ messages in thread
From: Tom Tromey @ 2021-12-31 22:25 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This removes the global wrap_here function, so that future calls
cannot be introduced.  Instead, all callers must use the method on the
appropriate ui_file.

This temporarily moves the implementation of this method to utils.c.
This will change once the remaining patches to untangle the pager have
been written.
---
 gdb/ui-file.c |  6 ------
 gdb/utils.c   | 20 +++-----------------
 2 files changed, 3 insertions(+), 23 deletions(-)

diff --git a/gdb/ui-file.c b/gdb/ui-file.c
index bde90a9e6ed..eb1d72bf8b3 100644
--- a/gdb/ui-file.c
+++ b/gdb/ui-file.c
@@ -68,12 +68,6 @@ ui_file::vprintf (const char *format, va_list args)
   vfprintf_unfiltered (this, format, args);
 }
 
-void
-ui_file::wrap_here (int indent)
-{
-  ::wrap_here (indent);
-}
-
 \f
 
 void
diff --git a/gdb/utils.c b/gdb/utils.c
index eebdfd57963..5c14cb2268c 100644
--- a/gdb/utils.c
+++ b/gdb/utils.c
@@ -1615,29 +1615,15 @@ get_chars_per_line ()
   return chars_per_line;
 }
 
-/* Indicate that if the next sequence of characters overflows the
-   line, a newline should be inserted here rather than when it hits
-   the end.  If INDENT is non-zero, it is a number of spaces to be
-   printed to indent the wrapped part on the next line.
-
-   If the line is already overfull, we immediately print a newline and
-   the indentation, and disable further wrapping.
-
-   If we don't know the width of lines, but we know the page height,
-   we must not wrap words, but should still keep track of newlines
-   that were explicitly printed.
-
-   This routine is guaranteed to force out any output which has been
-   squirreled away in the wrap_buffer, so wrap_here (0) can be
-   used to force out output from the wrap_buffer.  */
+/* See ui-file.h.  */
 
 void
-wrap_here (int indent)
+ui_file::wrap_here (int indent)
 {
   /* This should have been allocated, but be paranoid anyway.  */
   gdb_assert (filter_initialized);
 
-  flush_wrap_buffer (gdb_stdout);
+  flush_wrap_buffer (this);
   if (chars_per_line == UINT_MAX)	/* No line overflow checking.  */
     {
       wrap_column = 0;
-- 
2.31.1


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

* Re: [PATCH 0/4] Clean up wrap_here function a little
  2021-12-31 22:25 [PATCH 0/4] Clean up wrap_here function a little Tom Tromey
                   ` (3 preceding siblings ...)
  2021-12-31 22:25 ` [PATCH 4/4] Remove global wrap_here function Tom Tromey
@ 2022-01-26 22:21 ` Tom Tromey
  4 siblings, 0 replies; 6+ messages in thread
From: Tom Tromey @ 2022-01-26 22:21 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches

>>>>> "Tom" == Tom Tromey <tom@tromey.com> writes:

Tom> One oddity in gdb is that wrap_here doesn't take a stream parameter.
Tom> This is a historical relic from before my involvement in gdb, but it
Tom> leads to kind of weird code that intermixes calls to wrap_here (which
Tom> only affects gdb_stdout) with writes to other streams.

Tom> This series is a step toward cleaning this up.  It's part of a larger
Tom> project to un-spaghettify gdb's output pager.

I'm checking this in now.

Tom

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

end of thread, other threads:[~2022-01-26 22:21 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-31 22:25 [PATCH 0/4] Clean up wrap_here function a little Tom Tromey
2021-12-31 22:25 ` [PATCH 1/4] Convert wrap_here to use integer parameter Tom Tromey
2021-12-31 22:25 ` [PATCH 2/4] Add ui_file::wrap_here Tom Tromey
2021-12-31 22:25 ` [PATCH 3/4] Always call the wrap_here method Tom Tromey
2021-12-31 22:25 ` [PATCH 4/4] Remove global wrap_here function Tom Tromey
2022-01-26 22:21 ` [PATCH 0/4] Clean up wrap_here function a little Tom Tromey

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).