public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Remove print_spaces
@ 2021-12-11 21:59 Tom Tromey
  2021-12-20 17:25 ` Tom Tromey
  0 siblings, 1 reply; 2+ messages in thread
From: Tom Tromey @ 2021-12-11 21:59 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This removes the print_spaces helper function, in favor of using the
"*%s" idiom that's already used in many places in gdb.  One spot (in
symmisc.c) is changed to use print_spaces_filtered, because the rest
of that function is using filtered output.  (This highlights one way
that the printf idiom is better -- this error is harder to make when
using that.)

Regression tested on x86-64 Fedora 34.
---
 gdb/cli-out.c               |  2 +-
 gdb/compile/compile-loc2c.c |  2 +-
 gdb/dwarf2/read.c           | 32 ++++++++++++++------------------
 gdb/symmisc.c               |  6 +++---
 gdb/utils.c                 |  6 ------
 gdb/utils.h                 |  2 --
 6 files changed, 19 insertions(+), 31 deletions(-)

diff --git a/gdb/cli-out.c b/gdb/cli-out.c
index d4259902657..a3c189e4a8e 100644
--- a/gdb/cli-out.c
+++ b/gdb/cli-out.c
@@ -206,7 +206,7 @@ cli_ui_out::do_spaces (int numspaces)
     return;
 
   if (test_flags (unfiltered_output))
-    print_spaces (numspaces, m_streams.back ());
+    fprintf_unfiltered (m_streams.back (), "%*s", numspaces, "");
   else
     print_spaces_filtered (numspaces, m_streams.back ());
 }
diff --git a/gdb/compile/compile-loc2c.c b/gdb/compile/compile-loc2c.c
index fb1a4ff02b6..bc74ca5ce9b 100644
--- a/gdb/compile/compile-loc2c.c
+++ b/gdb/compile/compile-loc2c.c
@@ -675,7 +675,7 @@ do_compile_dwarf_expr_to_c (int indent, string_file *stream,
       uint64_t uoffset, reg;
       int64_t offset;
 
-      print_spaces (indent - 2, stream);
+      stream->printf ("%*s", indent - 2, "");
       if (info[op_ptr - base].label)
 	{
 	  print_label (stream, scope, op_ptr - base);
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index dd2134b3c63..36b7432803b 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -22980,31 +22980,28 @@ dump_die_shallow (struct ui_file *f, int indent, struct die_info *die)
 {
   unsigned int i;
 
-  print_spaces (indent, f);
-  fprintf_unfiltered (f, "Die: %s (abbrev %d, offset %s)\n",
+  fprintf_unfiltered (f, "%*sDie: %s (abbrev %d, offset %s)\n",
+		      indent, "",
 		      dwarf_tag_name (die->tag), die->abbrev,
 		      sect_offset_str (die->sect_off));
 
   if (die->parent != NULL)
-    {
-      print_spaces (indent, f);
-      fprintf_unfiltered (f, "  parent at offset: %s\n",
-			  sect_offset_str (die->parent->sect_off));
-    }
+    fprintf_unfiltered (f, "%*s  parent at offset: %s\n",
+			indent, "",
+			sect_offset_str (die->parent->sect_off));
 
-  print_spaces (indent, f);
-  fprintf_unfiltered (f, "  has children: %s\n",
-	   dwarf_bool_name (die->child != NULL));
+  fprintf_unfiltered (f, "%*s  has children: %s\n",
+		      indent, "",
+		      dwarf_bool_name (die->child != NULL));
 
-  print_spaces (indent, f);
-  fprintf_unfiltered (f, "  attributes:\n");
+  fprintf_unfiltered (f, "%*s  attributes:\n", indent, "");
 
   for (i = 0; i < die->num_attrs; ++i)
     {
-      print_spaces (indent, f);
-      fprintf_unfiltered (f, "    %s (%s) ",
-	       dwarf_attr_name (die->attrs[i].name),
-	       dwarf_form_name (die->attrs[i].form));
+      fprintf_unfiltered (f, "%*s    %s (%s) ",
+			  indent, "",
+			  dwarf_attr_name (die->attrs[i].name),
+			  dwarf_form_name (die->attrs[i].form));
 
       switch (die->attrs[i].form)
 	{
@@ -23120,8 +23117,7 @@ dump_die_1 (struct ui_file *f, int level, int max_level, struct die_info *die)
 
   if (die->child != NULL)
     {
-      print_spaces (indent, f);
-      fprintf_unfiltered (f, "  Children:");
+      fprintf_unfiltered (f, "%*s  Children:", indent, "");
       if (level + 1 < max_level)
 	{
 	  fprintf_unfiltered (f, "\n");
diff --git a/gdb/symmisc.c b/gdb/symmisc.c
index 7e215595cd8..ca15ab41f2d 100644
--- a/gdb/symmisc.c
+++ b/gdb/symmisc.c
@@ -286,8 +286,8 @@ dump_symtab_1 (struct symtab *symtab, struct ui_file *outfile)
 	{
 	  b = BLOCKVECTOR_BLOCK (bv, i);
 	  depth = block_depth (b) * 2;
-	  print_spaces (depth, outfile);
-	  fprintf_filtered (outfile, "block #%03d, object at ", i);
+	  fprintf_filtered (outfile, "%*sblock #%03d, object at ",
+			    depth, "", i);
 	  gdb_print_host_address (b, outfile);
 	  if (BLOCK_SUPERBLOCK (b))
 	    {
@@ -510,7 +510,7 @@ print_symbol (struct gdbarch *gdbarch, struct symbol *symbol,
   else
     section = NULL;
 
-  print_spaces (depth, outfile);
+  print_spaces_filtered (depth, outfile);
   if (SYMBOL_DOMAIN (symbol) == LABEL_DOMAIN)
     {
       fprintf_filtered (outfile, "label %s at ", symbol->print_name ());
diff --git a/gdb/utils.c b/gdb/utils.c
index e27a8818b94..f0437288912 100644
--- a/gdb/utils.c
+++ b/gdb/utils.c
@@ -779,12 +779,6 @@ uinteger_pow (ULONGEST v1, LONGEST v2)
     }
 }
 
-void
-print_spaces (int n, struct ui_file *file)
-{
-  fputs_unfiltered (n_spaces (n), file);
-}
-
 /* Print a host address.  */
 
 void
diff --git a/gdb/utils.h b/gdb/utils.h
index 6f3a70213a4..5cf07afe7ae 100644
--- a/gdb/utils.h
+++ b/gdb/utils.h
@@ -469,8 +469,6 @@ extern void fprintf_unfiltered (struct ui_file *, const char *, ...)
 
 extern void printf_unfiltered (const char *, ...) ATTRIBUTE_PRINTF (1, 2);
 
-extern void print_spaces (int, struct ui_file *);
-
 extern void print_spaces_filtered (int, struct ui_file *);
 
 extern char *n_spaces (int);
-- 
2.31.1


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

* Re: [PATCH] Remove print_spaces
  2021-12-11 21:59 [PATCH] Remove print_spaces Tom Tromey
@ 2021-12-20 17:25 ` Tom Tromey
  0 siblings, 0 replies; 2+ messages in thread
From: Tom Tromey @ 2021-12-20 17:25 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches

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

Tom> This removes the print_spaces helper function, in favor of using the
Tom> "*%s" idiom that's already used in many places in gdb.  One spot (in
Tom> symmisc.c) is changed to use print_spaces_filtered, because the rest
Tom> of that function is using filtered output.  (This highlights one way
Tom> that the printf idiom is better -- this error is harder to make when
Tom> using that.)

I'm checking this in now.

Tom

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

end of thread, other threads:[~2021-12-20 17:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-11 21:59 [PATCH] Remove print_spaces Tom Tromey
2021-12-20 17:25 ` 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).