gdb: LoongArch: Remove nonportable #include
[binutils-gdb.git] / gdb / m2-valprint.c
index c285543f4bfd5379f1b9732c91b51ed4519b4a12..9e3f16a896f18e6362620fcc2f27dfcb125cd883 100644 (file)
@@ -1,6 +1,6 @@
 /* Support for printing Modula 2 values for GDB, the GNU debugger.
 
-   Copyright (C) 1986-2020 Free Software Foundation, Inc.
+   Copyright (C) 1986-2022 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -42,7 +42,7 @@ m2_print_array_contents (struct value *val,
 
 
 /* get_long_set_bounds - assigns the bounds of the long set to low and
-                         high.  */
+                        high.  */
 
 int
 get_long_set_bounds (struct type *type, LONGEST *low, LONGEST *high)
@@ -81,7 +81,7 @@ m2_print_long_set (struct type *type, const gdb_byte *valaddr,
 
   type = check_typedef (type);
 
-  fprintf_filtered (stream, "{");
+  gdb_printf (stream, "{");
   len = type->num_fields ();
   if (get_long_set_bounds (type, &low_bound, &high_bound))
     {
@@ -97,12 +97,12 @@ m2_print_long_set (struct type *type, const gdb_byte *valaddr,
 
   target = TYPE_TARGET_TYPE (range);
 
-  if (get_discrete_bounds (range, &field_low, &field_high) >= 0)
+  if (get_discrete_bounds (range, &field_low, &field_high))
     {
       for (i = low_bound; i <= high_bound; i++)
        {
          bitval = value_bit_index (type->field (field).type (),
-                                   (TYPE_FIELD_BITPOS (type, field) / 8) +
+                                   (type->field (field).loc_bitpos () / 8) +
                                    valaddr + embedded_offset, i);
          if (bitval < 0)
            error (_("bit test is out of range"));
@@ -112,7 +112,7 @@ m2_print_long_set (struct type *type, const gdb_byte *valaddr,
              if (! element_seen)
                {
                  if (! empty_set)
-                   fprintf_filtered (stream, ", ");
+                   gdb_printf (stream, ", ");
                  print_type_scalar (target, i, stream);
                  empty_set    = 0;
                  element_seen = 1;
@@ -125,7 +125,7 @@ m2_print_long_set (struct type *type, const gdb_byte *valaddr,
              if (element_seen)
                {
                  if (previous_low+1 < previous_high)
-                   fprintf_filtered (stream, "..");
+                   gdb_printf (stream, "..");
                  if (previous_low+1 < previous_high)
                    print_type_scalar (target, previous_high, stream);
                  element_seen = 0;
@@ -137,7 +137,7 @@ m2_print_long_set (struct type *type, const gdb_byte *valaddr,
              if (field == len)
                break;
              range = type->field (field).type ()->index_type ();
-             if (get_discrete_bounds (range, &field_low, &field_high) < 0)
+             if (!get_discrete_bounds (range, &field_low, &field_high))
                break;
              target = TYPE_TARGET_TYPE (range);
            }
@@ -146,12 +146,12 @@ m2_print_long_set (struct type *type, const gdb_byte *valaddr,
        {
          if (previous_low+1 < previous_high)
            {
-             fprintf_filtered (stream, "..");
+             gdb_printf (stream, "..");
              print_type_scalar (target, previous_high, stream);
            }
          element_seen = 0;
        }
-      fprintf_filtered (stream, "}");
+      gdb_printf (stream, "}");
     }
 }
 
@@ -165,19 +165,19 @@ m2_print_unbounded_array (struct value *value,
   struct value *val;
 
   struct type *type = check_typedef (value_type (value));
-  const gdb_byte *valaddr = value_contents_for_printing (value);
+  const gdb_byte *valaddr = value_contents_for_printing (value).data ();
 
   addr = unpack_pointer (type->field (0).type (),
-                        (TYPE_FIELD_BITPOS (type, 0) / 8) +
+                        (type->field (0).loc_bitpos () / 8) +
                         valaddr);
 
   val = value_at_lazy (TYPE_TARGET_TYPE (type->field (0).type ()),
                       addr);
   len = unpack_field_as_long (type, valaddr, 1);
 
-  fprintf_filtered (stream, "{");  
+  gdb_printf (stream, "{");  
   m2_print_array_contents (val, stream, recurse, options, len);
-  fprintf_filtered (stream, ", HIGH = %d}", (int) len);
+  gdb_printf (stream, ", HIGH = %d}", (int) len);
 }
 
 static int
@@ -186,7 +186,7 @@ print_unpacked_pointer (struct type *type,
                        const struct value_print_options *options,
                        struct ui_file *stream)
 {
-  struct gdbarch *gdbarch = get_type_arch (type);
+  struct gdbarch *gdbarch = type->arch ();
   struct type *elttype = check_typedef (TYPE_TARGET_TYPE (type));
   int want_space = 0;
 
@@ -200,7 +200,7 @@ print_unpacked_pointer (struct type *type,
 
   if (options->addressprint && options->format != 's')
     {
-      fputs_filtered (paddress (gdbarch, address), stream);
+      gdb_puts (paddress (gdbarch, address), stream);
       want_space = 1;
     }
 
@@ -213,7 +213,7 @@ print_unpacked_pointer (struct type *type,
       && addr != 0)
     {
       if (want_space)
-       fputs_filtered (" ", stream);
+       gdb_puts (" ", stream);
       return val_print_string (TYPE_TARGET_TYPE (type), NULL, addr, -1,
                               stream, options);
     }
@@ -228,13 +228,13 @@ print_variable_at_address (struct type *type,
                           int recurse,
                           const struct value_print_options *options)
 {
-  struct gdbarch *gdbarch = get_type_arch (type);
+  struct gdbarch *gdbarch = type->arch ();
   CORE_ADDR addr = unpack_pointer (type, valaddr);
   struct type *elttype = check_typedef (TYPE_TARGET_TYPE (type));
 
-  fprintf_filtered (stream, "[");
-  fputs_filtered (paddress (gdbarch, addr), stream);
-  fprintf_filtered (stream, "] : ");
+  gdb_printf (stream, "[");
+  gdb_puts (paddress (gdbarch, addr), stream);
+  gdb_printf (stream, "] : ");
   
   if (elttype->code () != TYPE_CODE_UNDEF)
     {
@@ -244,15 +244,15 @@ print_variable_at_address (struct type *type,
       common_val_print (deref_val, stream, recurse, options, current_language);
     }
   else
-    fputs_filtered ("???", stream);
+    gdb_puts ("???", stream);
 }
 
 
 /* m2_print_array_contents - prints out the contents of an
-                             array up to a max_print values.
-                             It prints arrays of char as a string
-                             and all other data types as comma
-                             separated values.  */
+                            array up to a max_print values.
+                            It prints arrays of char as a string
+                            and all other data types as comma
+                            separated values.  */
 
 static void
 m2_print_array_contents (struct value *val,
@@ -274,9 +274,9 @@ m2_print_array_contents (struct value *val,
                          options);
       else
        {
-         fprintf_filtered (stream, "{");
+         gdb_printf (stream, "{");
          value_print_array_elements (val, stream, recurse, options, 0);
-         fprintf_filtered (stream, "}");
+         gdb_printf (stream, "}");
        }
     }
 }
@@ -298,13 +298,14 @@ static const struct generic_val_print_decorations m2_decorations =
 /* See m2-lang.h.  */
 
 void
-m2_value_print_inner (struct value *val, struct ui_file *stream, int recurse,
-                     const struct value_print_options *options)
+m2_language::value_print_inner (struct value *val, struct ui_file *stream,
+                               int recurse,
+                               const struct value_print_options *options) const
 {
   unsigned len;
   struct type *elttype;
   CORE_ADDR addr;
-  const gdb_byte *valaddr = value_contents_for_printing (val);
+  const gdb_byte *valaddr = value_contents_for_printing (val).data ();
   const CORE_ADDR address = value_address (val);
 
   struct type *type = check_typedef (value_type (val));
@@ -323,7 +324,7 @@ m2_value_print_inner (struct value *val, struct ui_file *stream, int recurse,
              && (options->format == 0 || options->format == 's'))
            {
              /* If requested, look for the first null char and only print
-                elements up to it.  */
+                elements up to it.  */
              if (options->stop_print_at_null)
                {
                  unsigned int temp_len;
@@ -336,15 +337,15 @@ m2_value_print_inner (struct value *val, struct ui_file *stream, int recurse,
                  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);
            }
          else
            {
-             fprintf_filtered (stream, "{");
+             gdb_printf (stream, "{");
              value_print_array_elements (val, stream, recurse,
                                          options, 0);
-             fprintf_filtered (stream, "}");
+             gdb_printf (stream, "}");
            }
          break;
        }
@@ -367,7 +368,7 @@ m2_value_print_inner (struct value *val, struct ui_file *stream, int recurse,
     case TYPE_CODE_UNION:
       if (recurse && !options->unionprint)
        {
-         fprintf_filtered (stream, "{...}");
+         gdb_printf (stream, "{...}");
          break;
        }
       /* Fall through.  */
@@ -396,9 +397,9 @@ m2_value_print_inner (struct value *val, struct ui_file *stream, int recurse,
          int i;
          int need_comma = 0;
 
-         fputs_filtered ("{", stream);
+         gdb_puts ("{", stream);
 
-         i = get_discrete_bounds (range, &low_bound, &high_bound);
+         i = get_discrete_bounds (range, &low_bound, &high_bound) ? 0 : -1;
        maybe_bad_bstring:
          if (i < 0)
            {
@@ -419,7 +420,7 @@ m2_value_print_inner (struct value *val, struct ui_file *stream, int recurse,
              if (element)
                {
                  if (need_comma)
-                   fputs_filtered (", ", stream);
+                   gdb_puts (", ", stream);
                  print_type_scalar (range, i, stream);
                  need_comma = 1;
 
@@ -428,7 +429,7 @@ m2_value_print_inner (struct value *val, struct ui_file *stream, int recurse,
                    {
                      int j = i;
 
-                     fputs_filtered ("..", stream);
+                     gdb_puts ("..", stream);
                      while (i + 1 <= high_bound
                             && value_bit_index (type, valaddr, ++i))
                        j = i;
@@ -437,7 +438,7 @@ m2_value_print_inner (struct value *val, struct ui_file *stream, int recurse,
                }
            }
        done:
-         fputs_filtered ("}", stream);
+         gdb_puts ("}", stream);
        }
       break;
 
@@ -445,7 +446,7 @@ m2_value_print_inner (struct value *val, struct ui_file *stream, int recurse,
       if (TYPE_LENGTH (type) == TYPE_LENGTH (TYPE_TARGET_TYPE (type)))
        {
          struct value *v = value_cast (TYPE_TARGET_TYPE (type), val);
-         m2_value_print_inner (v, stream, recurse, options);
+         value_print_inner (v, stream, recurse, options);
          break;
        }
       /* FALLTHROUGH */