]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Convert Go printing to value-based API
authorTom Tromey <tom@tromey.com>
Fri, 13 Mar 2020 23:39:52 +0000 (17:39 -0600)
committerTom Tromey <tom@tromey.com>
Sat, 14 Mar 2020 00:03:40 +0000 (18:03 -0600)
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
2020-03-13  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.

gdb/ChangeLog
gdb/go-lang.c
gdb/go-lang.h
gdb/go-valprint.c

index 79ed024125521386d0c85ee1ed2524c272d57cfe..862d4bc7e93e1aaff10ca23c6ccd5f478a75189f 100644 (file)
@@ -1,3 +1,9 @@
+2020-03-13  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.
+
 2020-03-13  Tom Tromey  <tom@tromey.com>
 
        * rust-lang.c (val_print_struct, rust_print_enum): Use the value
index 314c281197290266e13f6c47a0f6647f4f71976d..667c4aeb1a56e4f1bdc488c3b3ca2ff77c9cf0d2 100644 (file)
@@ -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.  */
index ccfcb8d8cafeb797c7779cd78cdda14011e53276..8647964ab60145d4b9e310a1c10eda573744981c 100644 (file)
@@ -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) */
index 1648a6c02c0876654fbe877a9c1abc7753789343..79b3ad58d5a2f1a185f44811a92d95e15af3e82e 100644 (file)
@@ -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;
+    }
+}