Add `set print array-indexes' tests for C/C++ arrays
[binutils-gdb.git] / gdb / p-valprint.c
index b748c066fb0990d82a1c80d94589674b57142d12..e0c3868991b9c1a82206bdcc32c65a7fece1e405 100644 (file)
@@ -1,6 +1,6 @@
 /* Support for printing Pascal values for GDB, the GNU debugger.
 
-   Copyright (C) 2000-2020 Free Software Foundation, Inc.
+   Copyright (C) 2000-2022 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -20,7 +20,7 @@
 /* This file is derived from c-valprint.c */
 
 #include "defs.h"
-#include "gdb_obstack.h"
+#include "gdbsupport/gdb_obstack.h"
 #include "symtab.h"
 #include "gdbtypes.h"
 #include "expression.h"
@@ -70,7 +70,7 @@ pascal_language::value_print_inner (struct value *val,
 
 {
   struct type *type = check_typedef (value_type (val));
-  struct gdbarch *gdbarch = get_type_arch (type);
+  struct gdbarch *gdbarch = type->arch ();
   enum bfd_endian byte_order = type_byte_order (type);
   unsigned int i = 0;  /* Number of characters printed */
   unsigned len;
@@ -80,7 +80,7 @@ pascal_language::value_print_inner (struct value *val,
   struct type *char_type;
   CORE_ADDR addr;
   int want_space = 0;
-  const gdb_byte *valaddr = value_contents_for_printing (val);
+  const gdb_byte *valaddr = value_contents_for_printing (val).data ();
 
   switch (type->code ())
     {
@@ -116,8 +116,8 @@ pascal_language::value_print_inner (struct value *val,
                    len = temp_len;
                  }
 
-               LA_PRINT_STRING (stream, TYPE_TARGET_TYPE (type),
-                                valaddr, len, NULL, 0, options);
+               printstr (stream, TYPE_TARGET_TYPE (type), valaddr, len,
+                         NULL, 0, options);
                i = len;
              }
            else
@@ -306,7 +306,7 @@ pascal_language::value_print_inner (struct value *val,
          print_address_demangle
            (options, gdbarch,
             extract_unsigned_integer
-              (valaddr + TYPE_FIELD_BITPOS (type, VTBL_FNADDR_OFFSET) / 8,
+              (valaddr + type->field (VTBL_FNADDR_OFFSET).loc_bitpos () / 8,
                TYPE_LENGTH (type->field (VTBL_FNADDR_OFFSET).type ()),
                byte_order),
             stream, demangle);
@@ -318,8 +318,8 @@ pascal_language::value_print_inner (struct value *val,
            {
              len = extract_unsigned_integer (valaddr + length_pos,
                                              length_size, byte_order);
-             LA_PRINT_STRING (stream, char_type, valaddr + string_pos,
-                              len, NULL, 0, options);
+             printstr (stream, char_type, valaddr + string_pos, len,
+                       NULL, 0, options);
            }
          else
            pascal_object_print_value_fields (val, stream, recurse,
@@ -536,7 +536,7 @@ pascal_object_print_value_fields (struct value *val, struct ui_file *stream,
     {
       struct obstack tmp_obstack = dont_print_statmem_obstack;
       int fields_seen = 0;
-      const gdb_byte *valaddr = value_contents_for_printing (val);
+      const gdb_byte *valaddr = value_contents_for_printing (val).data ();
 
       if (dont_print_statmem == 0)
        {
@@ -583,12 +583,12 @@ pascal_object_print_value_fields (struct value *val, struct ui_file *stream,
            {
              fputs_filtered ("static ", stream);
              fprintf_symbol_filtered (stream,
-                                      TYPE_FIELD_NAME (type, i),
+                                      type->field (i).name (),
                                       current_language->la_language,
                                       DMGL_PARAMS | DMGL_ANSI);
            }
          else
-           fputs_styled (TYPE_FIELD_NAME (type, i),
+           fputs_styled (type->field (i).name (),
                          variable_name_style.style (), stream);
          annotate_field_name_end ();
          fputs_filtered (" = ", stream);
@@ -606,11 +606,9 @@ pascal_object_print_value_fields (struct value *val, struct ui_file *stream,
                  fputs_styled ("<optimized out or zero length>",
                                metadata_style.style (), stream);
                }
-             else if (value_bits_synthetic_pointer (val,
-                                                    TYPE_FIELD_BITPOS (type,
-                                                                       i),
-                                                    TYPE_FIELD_BITSIZE (type,
-                                                                        i)))
+             else if (value_bits_synthetic_pointer
+                        (val, type->field (i).loc_bitpos (),
+                         TYPE_FIELD_BITSIZE (type, i)))
                {
                  fputs_styled (_("<synthetic pointer>"),
                                metadata_style.style (), stream);