[23/55] Convert Go printing to value-based API

Message ID 20191208182958.10181-24-tom@tromey.com
State New, archived
Headers

Commit Message

Tom Tromey Dec. 8, 2019, 6:29 p.m. UTC
  This introduces go_value_print_inner, a modified copy of go_val_print.
Unlike some of the other languages, Go was straightforward to convert
to the value-based API all at once, so this patch takes that approach.

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

	* go-valprint.c (go_value_print_inner): New function.
	* go-lang.h (go_value_print_inner): Declare.
	* go-lang.c (go_language_defn): Use go_value_print_inner.

Change-Id: Ie0bc393633a11e56991ea82f9fc45e48604c1a17
---
 gdb/ChangeLog     |  6 ++++++
 gdb/go-lang.c     |  2 +-
 gdb/go-lang.h     |  6 ++++++
 gdb/go-valprint.c | 37 +++++++++++++++++++++++++++++++++++++
 4 files changed, 50 insertions(+), 1 deletion(-)
  

Patch

diff --git a/gdb/go-lang.c b/gdb/go-lang.c
index 38eb0d74836..7e092229583 100644
--- a/gdb/go-lang.c
+++ b/gdb/go-lang.c
@@ -596,7 +596,7 @@  extern const struct language_defn go_language_defn =
   c_print_typedef,		/* Print a typedef using appropriate
 				   syntax.  */
   go_val_print,			/* Print a value using appropriate syntax.  */
-  nullptr,			/* la_value_print_inner */
+  go_value_print_inner,		/* la_value_print_inner */
   c_value_print,		/* Print a top-level value.  */
   default_read_var_value,	/* la_read_var_value */
   NULL,				/* Language specific skip_trampoline.  */
diff --git a/gdb/go-lang.h b/gdb/go-lang.h
index 18748b0acbe..19dc43cd33d 100644
--- a/gdb/go-lang.h
+++ b/gdb/go-lang.h
@@ -88,4 +88,10 @@  extern void go_val_print (struct type *type,
 			  struct value *val,
 			  const struct value_print_options *options);
 
+/* Implement la_value_print_inner for Go.  */
+
+extern void go_value_print_inner (struct value *value,
+				  struct ui_file *stream, int recurse,
+				  const struct value_print_options *options);
+
 #endif /* !defined (GO_LANG_H) */
diff --git a/gdb/go-valprint.c b/gdb/go-valprint.c
index 64761b98221..5282aa2e34b 100644
--- a/gdb/go-valprint.c
+++ b/gdb/go-valprint.c
@@ -122,3 +122,40 @@  go_val_print (struct type *type, int embedded_offset,
 	break;
     }
 }
+
+/* See go-lang.h.  */
+
+void
+go_value_print_inner (struct value *val, struct ui_file *stream,
+		      int recurse, const struct value_print_options *options)
+{
+  struct type *type = check_typedef (value_type (val));
+
+  switch (TYPE_CODE (type))
+    {
+      case TYPE_CODE_STRUCT:
+	{
+	  enum go_type go_type = go_classify_struct_type (type);
+
+	  switch (go_type)
+	    {
+	    case GO_TYPE_STRING:
+	      if (! options->raw)
+		{
+		  print_go_string (type, value_embedded_offset (val),
+				   value_address (val),
+				   stream, recurse, val, options);
+		  return;
+		}
+	      break;
+	    default:
+	      break;
+	    }
+	}
+	/* Fall through.  */
+
+      default:
+	c_value_print_inner (val, stream, recurse, options);
+	break;
+    }
+}