diff mbox

[11/55] Introduce generic_value_print

Message ID 20191208182958.10181-12-tom@tromey.com
State New
Headers show

Commit Message

Tom Tromey Dec. 8, 2019, 6:29 p.m. UTC
This introduces generic_value_print, which is a value-based analogue
to generic_val_print.  For now this is unused and simply calls
generic_val_print, but subsequent patches will both change this
function to work using the value API directly, and convert callers of
generic_val_print to call this instead.

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

	* valprint.h (generic_value_print): Declare.
	* valprint.c (generic_value_print): New function.

Change-Id: I00b9ef91c1f3bf351b0e13e9873b849e80dfd944
---
 gdb/ChangeLog  |  5 +++++
 gdb/valprint.c | 12 ++++++++++++
 gdb/valprint.h | 11 +++++++++++
 3 files changed, 28 insertions(+)

Comments

Doug Evans via gdb-patches Dec. 9, 2019, 4:04 a.m. UTC | #1
On Sun, Dec 8, 2019 at 1:33 PM Tom Tromey <tom@tromey.com> wrote:
>
> This introduces generic_value_print, which is a value-based analogue
> to generic_val_print.  For now this is unused and simply calls
> generic_val_print, but subsequent patches will both change this
> function to work using the value API directly, and convert callers of
> generic_val_print to call this instead.

I'm really not familiar with this code at all, but since this is new,
should this be a member function on struct value?

Christian

> gdb/ChangeLog
> 2019-12-08  Tom Tromey  <tom@tromey.com>
>
>         * valprint.h (generic_value_print): Declare.
>         * valprint.c (generic_value_print): New function.
>
> Change-Id: I00b9ef91c1f3bf351b0e13e9873b849e80dfd944
> ---
>  gdb/ChangeLog  |  5 +++++
>  gdb/valprint.c | 12 ++++++++++++
>  gdb/valprint.h | 11 +++++++++++
>  3 files changed, 28 insertions(+)
>
> diff --git a/gdb/valprint.c b/gdb/valprint.c
> index d595a1d54e6..0e13e2b2d62 100644
> --- a/gdb/valprint.c
> +++ b/gdb/valprint.c
> @@ -1007,6 +1007,18 @@ generic_val_print (struct type *type,
>      }
>  }
>
> +/* See valprint.h.  */
> +
> +void
> +generic_value_print (struct value *val, struct ui_file *stream, int recurse,
> +                    const struct value_print_options *options,
> +                    const struct generic_val_print_decorations *decorations)
> +{
> +  generic_val_print (value_type (val), value_embedded_offset (val),
> +                    value_address (val), stream, recurse, val, options,
> +                    decorations);
> +}
> +
>  /* 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.  */
> diff --git a/gdb/valprint.h b/gdb/valprint.h
> index c63ac8de19b..e4b90404fa2 100644
> --- a/gdb/valprint.h
> +++ b/gdb/valprint.h
> @@ -211,6 +211,17 @@ extern void generic_val_print (struct type *type,
>                                const struct value_print_options *options,
>                                const struct generic_val_print_decorations *);
>
> +/* Print a value in a generic way.  VAL is the value, STREAM is where
> +   to print it, RECURSE is the recursion depth, OPTIONS describe how
> +   the printing should be done, and D is the language-specific
> +   decorations object.  Note that structs and unions cannot be printed
> +   by this function.  */
> +
> +extern void generic_value_print (struct value *val, struct ui_file *stream,
> +                                int recurse,
> +                                const struct value_print_options *options,
> +                                const struct generic_val_print_decorations *d);
> +
>  extern void generic_emit_char (int c, struct type *type, struct ui_file *stream,
>                                int quoter, const char *encoding);
>
> --
> 2.17.2
>
Tom Tromey Dec. 9, 2019, 11:40 p.m. UTC | #2
Christian> I'm really not familiar with this code at all, but since this is new,
Christian> should this be a member function on struct value?

Possibly, but there aren't really methods there now (it's opaque
currently), and anyway for this series I wanted to try to keep each
patch reasonably close to the existing code, to make the transition more
clear.

FWIW once I had some scripts to try to convert struct value to be more
like a class.  This is difficult to do in its entirety though.  There
are many potential methods.

Tom
diff mbox

Patch

diff --git a/gdb/valprint.c b/gdb/valprint.c
index d595a1d54e6..0e13e2b2d62 100644
--- a/gdb/valprint.c
+++ b/gdb/valprint.c
@@ -1007,6 +1007,18 @@  generic_val_print (struct type *type,
     }
 }
 
+/* See valprint.h.  */
+
+void
+generic_value_print (struct value *val, struct ui_file *stream, int recurse,
+		     const struct value_print_options *options,
+		     const struct generic_val_print_decorations *decorations)
+{
+  generic_val_print (value_type (val), value_embedded_offset (val),
+		     value_address (val), stream, recurse, val, options,
+		     decorations);
+}
+
 /* 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.  */
diff --git a/gdb/valprint.h b/gdb/valprint.h
index c63ac8de19b..e4b90404fa2 100644
--- a/gdb/valprint.h
+++ b/gdb/valprint.h
@@ -211,6 +211,17 @@  extern void generic_val_print (struct type *type,
 			       const struct value_print_options *options,
 			       const struct generic_val_print_decorations *);
 
+/* Print a value in a generic way.  VAL is the value, STREAM is where
+   to print it, RECURSE is the recursion depth, OPTIONS describe how
+   the printing should be done, and D is the language-specific
+   decorations object.  Note that structs and unions cannot be printed
+   by this function.  */
+
+extern void generic_value_print (struct value *val, struct ui_file *stream,
+				 int recurse,
+				 const struct value_print_options *options,
+				 const struct generic_val_print_decorations *d);
+
 extern void generic_emit_char (int c, struct type *type, struct ui_file *stream,
 			       int quoter, const char *encoding);