Patchwork [02/55] Refactor val_print and common_val_print

login
register
mail settings
Submitter Tom Tromey
Date Dec. 8, 2019, 6:29 p.m.
Message ID <20191208182958.10181-3-tom@tromey.com>
Download mbox | patch
Permalink /patch/36608/
State New
Headers show

Comments

Tom Tromey - Dec. 8, 2019, 6:29 p.m.
This changes val_print and common_val_print to use a new helper
function.  A theme in the coming patches is that calls to val_print
itself should be removed.  This is the first such patch; at the end of
the series, we'll remove val_print and simplify do_val_print.

gdb/ChangeLog
2019-12-08  Tom Tromey  <tom@tromey.com>

	* valprint.c (do_val_print): New function, from val_print.
	(val_print): Use do_val_print.
	(common_val_print): Use do_val_print.

Change-Id: I09056cff7b7154995812029808704223f2e049bd
---
 gdb/ChangeLog  |  6 +++++
 gdb/valprint.c | 72 ++++++++++++++++++++++++++++++--------------------
 2 files changed, 50 insertions(+), 28 deletions(-)

Patch

diff --git a/gdb/valprint.c b/gdb/valprint.c
index 5bc860f13f1..62c78b95ad2 100644
--- a/gdb/valprint.c
+++ b/gdb/valprint.c
@@ -1007,31 +1007,17 @@  generic_val_print (struct type *type,
     }
 }
 
-/* Print using the given LANGUAGE the data of type TYPE located at
-   VAL's contents buffer + EMBEDDED_OFFSET (within GDB), which came
-   from the inferior at address ADDRESS + EMBEDDED_OFFSET, onto
-   stdio stream STREAM according to OPTIONS.  VAL is the whole object
-   that came from ADDRESS.
-
-   The language printers will pass down an adjusted EMBEDDED_OFFSET to
-   further helper subroutines as subfields of TYPE are printed.  In
-   such cases, VAL is passed down unadjusted, so
-   that VAL can be queried for metadata about the contents data being
-   printed, using EMBEDDED_OFFSET as an offset into VAL's contents
-   buffer.  For example: "has this field been optimized out", or "I'm
-   printing an object while inspecting a traceframe; has this
-   particular piece of data been collected?".
+/* Helper function for val_print and common_val_print that does the
+   work.  Arguments are as to val_print, but FULL_VALUE, if given, is
+   the value to be printed.  */
 
-   RECURSE indicates the amount of indentation to supply before
-   continuation lines; this amount is roughly twice the value of
-   RECURSE.  */
-
-void
-val_print (struct type *type, LONGEST embedded_offset,
-	   CORE_ADDR address, struct ui_file *stream, int recurse,
-	   struct value *val,
-	   const struct value_print_options *options,
-	   const struct language_defn *language)
+static void
+do_val_print (struct value *full_value,
+	      struct type *type, LONGEST embedded_offset,
+	      CORE_ADDR address, struct ui_file *stream, int recurse,
+	      struct value *val,
+	      const struct value_print_options *options,
+	      const struct language_defn *language)
 {
   int ret = 0;
   struct value_print_options local_opts = *options;
@@ -1091,6 +1077,36 @@  val_print (struct type *type, LONGEST embedded_offset,
     }
 }
 
+/* Print using the given LANGUAGE the data of type TYPE located at
+   VAL's contents buffer + EMBEDDED_OFFSET (within GDB), which came
+   from the inferior at address ADDRESS + EMBEDDED_OFFSET, onto
+   stdio stream STREAM according to OPTIONS.  VAL is the whole object
+   that came from ADDRESS.
+
+   The language printers will pass down an adjusted EMBEDDED_OFFSET to
+   further helper subroutines as subfields of TYPE are printed.  In
+   such cases, VAL is passed down unadjusted, so
+   that VAL can be queried for metadata about the contents data being
+   printed, using EMBEDDED_OFFSET as an offset into VAL's contents
+   buffer.  For example: "has this field been optimized out", or "I'm
+   printing an object while inspecting a traceframe; has this
+   particular piece of data been collected?".
+
+   RECURSE indicates the amount of indentation to supply before
+   continuation lines; this amount is roughly twice the value of
+   RECURSE.  */
+
+void
+val_print (struct type *type, LONGEST embedded_offset,
+	   CORE_ADDR address, struct ui_file *stream, int recurse,
+	   struct value *val,
+	   const struct value_print_options *options,
+	   const struct language_defn *language)
+{
+  do_val_print (nullptr, type, embedded_offset, address, stream,
+		recurse, val, options, language);
+}
+
 /* See valprint.h.  */
 
 bool
@@ -1188,10 +1204,10 @@  common_val_print (struct value *val, struct ui_file *stream, int recurse,
   if (value_lazy (val))
     value_fetch_lazy (val);
 
-  val_print (value_type (val),
-	     value_embedded_offset (val), value_address (val),
-	     stream, recurse,
-	     val, options, language);
+  do_val_print (val, value_type (val),
+		value_embedded_offset (val), value_address (val),
+		stream, recurse,
+		val, options, language);
 }
 
 /* Print on stream STREAM the value VAL according to OPTIONS.  The value