gdb/MAINTAINERS: add Luis Machado as global maintainer
[binutils-gdb.git] / gdb / go-valprint.c
index d7026a4d9e702a30df8bb5d5cdc3cf9d1d58a998..05788af15a6f004225a0106a94ffd4f0a9b74eaf 100644 (file)
@@ -1,6 +1,6 @@
 /* Support for printing Go values for GDB, the GNU debugger.
 
-   Copyright (C) 2012-2014 Free Software Foundation, Inc.
+   Copyright (C) 2012-2023 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -29,6 +29,7 @@
 #include "go-lang.h"
 #include "c-lang.h"
 #include "valprint.h"
+#include "cli/cli-style.h"
 
 /* Print a Go string.
 
    gdb_assert (go_classify_struct_type (type) == GO_TYPE_STRING).  */
 
 static void
-print_go_string (struct type *type, const gdb_byte *valaddr,
-                int embedded_offset, CORE_ADDR address,
+print_go_string (struct type *type,
+                LONGEST embedded_offset, CORE_ADDR address,
                 struct ui_file *stream, int recurse,
-                const struct value *val,
+                struct value *val,
                 const struct value_print_options *options)
 {
-  struct gdbarch *gdbarch = get_type_arch (type);
-  struct type *elt_ptr_type = TYPE_FIELD_TYPE (type, 0);
-  struct type *elt_type = TYPE_TARGET_TYPE (elt_ptr_type);
+  struct gdbarch *gdbarch = type->arch ();
+  struct type *elt_ptr_type = type->field (0).type ();
+  struct type *elt_type = elt_ptr_type->target_type ();
   LONGEST length;
   /* TODO(dje): The encapsulation of what a pointer is belongs in value.c.
      I.e. If there's going to be unpack_pointer, there should be
      unpack_value_field_as_pointer.  Do this until we can get
      unpack_value_field_as_pointer.  */
   LONGEST addr;
+  const gdb_byte *valaddr = val->contents_for_printing ().data ();
 
-  gdb_assert (valaddr == value_contents_for_printing_const (val));
 
   if (! unpack_value_field_as_long (type, valaddr, embedded_offset, 0,
                                    val, &addr))
@@ -65,15 +66,15 @@ print_go_string (struct type *type, const gdb_byte *valaddr,
   /* TODO(dje): Print address of struct or actual string?  */
   if (options->addressprint)
     {
-      fputs_filtered (paddress (gdbarch, addr), stream);
-      fputs_filtered (" ", stream);
+      gdb_puts (paddress (gdbarch, addr), stream);
+      gdb_puts (" ", stream);
     }
 
   if (length < 0)
     {
-      fputs_filtered (_("<invalid length: "), stream);
-      fputs_filtered (plongest (addr), stream);
-      fputs_filtered (">", stream);
+      gdb_printf (_("<invalid length: %ps>"),
+                 styled_string (metadata_style.style (),
+                                plongest (addr)));
       return;
     }
 
@@ -83,17 +84,16 @@ print_go_string (struct type *type, const gdb_byte *valaddr,
   val_print_string (elt_type, NULL, addr, length, stream, options);
 }
 
-/* Implements the la_val_print routine for language Go.  */
+/* See go-lang.h.  */
 
 void
-go_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset,
-             CORE_ADDR address, struct ui_file *stream, int recurse,
-             const struct value *val,
-             const struct value_print_options *options)
+go_language::value_print_inner (struct value *val, struct ui_file *stream,
+                               int recurse,
+                               const struct value_print_options *options) const
 {
-  CHECK_TYPEDEF (type);
+  struct type *type = check_typedef (val->type ());
 
-  switch (TYPE_CODE (type))
+  switch (type->code ())
     {
       case TYPE_CODE_STRUCT:
        {
@@ -104,7 +104,8 @@ go_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset,
            case GO_TYPE_STRING:
              if (! options->raw)
                {
-                 print_go_string (type, valaddr, embedded_offset, address,
+                 print_go_string (type, val->embedded_offset (),
+                                  val->address (),
                                   stream, recurse, val, options);
                  return;
                }
@@ -116,8 +117,7 @@ go_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset,
        /* Fall through.  */
 
       default:
-       c_val_print (type, valaddr, embedded_offset, address, stream,
-                    recurse, val, options);
+       c_value_print_inner (val, stream, recurse, options);
        break;
     }
 }