rx: Treat scalars larger than 8 bytes as aggregates in rx_push_dummy_call.
[deliverable/binutils-gdb.git] / gdb / ada-valprint.c
index 12c84daa48ac9853d5898c36c5d4ca7e4257ca49..6b4b6d47e62629e07a0cef53bd365c8e9d3731f8 100644 (file)
@@ -1,6 +1,6 @@
 /* Support for printing Ada values for GDB, the GNU debugger.
 
-   Copyright (C) 1986-2014 Free Software Foundation, Inc.
+   Copyright (C) 1986-2016 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -19,7 +19,6 @@
 
 #include "defs.h"
 #include <ctype.h>
-#include <string.h>
 #include "symtab.h"
 #include "gdbtypes.h"
 #include "expression.h"
@@ -31,7 +30,6 @@
 #include "ada-lang.h"
 #include "c-lang.h"
 #include "infcall.h"
-#include "exceptions.h"
 #include "objfiles.h"
 
 static int print_field_values (struct type *, const gdb_byte *,
@@ -39,7 +37,8 @@ static int print_field_values (struct type *, const gdb_byte *,
                               struct ui_file *, int,
                               const struct value *,
                               const struct value_print_options *,
-                              int, struct type *, int);
+                              int, struct type *, int,
+                              const struct language_defn *);
 \f
 
 /* Make TYPE unsigned if its range of values includes no negatives.  */
@@ -78,7 +77,7 @@ print_optional_low_bound (struct ui_file *stream, struct type *type,
 
   index_type = TYPE_INDEX_TYPE (type);
 
-  if (TYPE_CODE (index_type) == TYPE_CODE_RANGE)
+  while (TYPE_CODE (index_type) == TYPE_CODE_RANGE)
     {
       /* We need to know what the base type is, in order to do the
          appropriate check below.  Otherwise, if this is a subrange
@@ -130,13 +129,11 @@ val_print_packed_array_elements (struct type *type, const gdb_byte *valaddr,
   unsigned int things_printed = 0;
   unsigned len;
   struct type *elttype, *index_type;
-  unsigned eltlen;
   unsigned long bitsize = TYPE_FIELD_BITSIZE (type, 0);
   struct value *mark = value_mark ();
   LONGEST low = 0;
 
   elttype = TYPE_TARGET_TYPE (type);
-  eltlen = TYPE_LENGTH (check_typedef (elttype));
   index_type = TYPE_INDEX_TYPE (type);
 
   {
@@ -185,9 +182,12 @@ val_print_packed_array_elements (struct type *type, const gdb_byte *valaddr,
                                               (i * bitsize) / HOST_CHAR_BIT,
                                               (i * bitsize) % HOST_CHAR_BIT,
                                               bitsize, elttype);
-         if (!value_available_contents_eq (v0, value_embedded_offset (v0),
-                                           v1, value_embedded_offset (v1),
-                                           eltlen))
+         if (TYPE_LENGTH (check_typedef (value_type (v0)))
+             != TYPE_LENGTH (check_typedef (value_type (v1))))
+           break;
+         if (!value_contents_eq (v0, value_embedded_offset (v0),
+                                 v1, value_embedded_offset (v1),
+                                 TYPE_LENGTH (check_typedef (value_type (v0)))))
            break;
        }
 
@@ -289,32 +289,22 @@ char_at (const gdb_byte *string, int i, int type_len,
                                            type_len, byte_order);
 }
 
-/* Wrapper around memcpy to make it legal argument to ui_file_put.  */
-static void
-ui_memcpy (void *dest, const char *buffer, long len)
-{
-  memcpy (dest, buffer, (size_t) len);
-  ((char *) dest)[len] = '\0';
-}
-
 /* Print a floating-point value of type TYPE, pointed to in GDB by
    VALADDR, on STREAM.  Use Ada formatting conventions: there must be
    a decimal point, and at least one digit before and after the
-   point.  We use GNAT format for NaNs and infinities.  */
+   point.  We use the GNAT format for NaNs and infinities.  */
+
 static void
 ada_print_floating (const gdb_byte *valaddr, struct type *type,
                    struct ui_file *stream)
 {
-  char buffer[64];
   char *s, *result;
   struct ui_file *tmp_stream = mem_fileopen ();
   struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_stream);
 
   print_floating (valaddr, type, tmp_stream);
-  ui_file_put (tmp_stream, ui_memcpy, buffer);
-  do_cleanups (cleanups);
-
-  result = buffer;
+  result = ui_file_xstrdup (tmp_stream, NULL);
+  make_cleanup (xfree, result);
 
   /* Modify for Ada rules.  */
 
@@ -348,9 +338,11 @@ ada_print_floating (const gdb_byte *valaddr, struct type *type,
        fprintf_filtered (stream, "%s.0", result);
       else
        fprintf_filtered (stream, "%.*s.0%s", (int) (s-result), result, s);
-      return;
     }
-  fprintf_filtered (stream, "%s", result);
+  else
+    fprintf_filtered (stream, "%s", result);
+
+  do_cleanups (cleanups);
 }
 
 void
@@ -537,71 +529,6 @@ ada_printstr (struct ui_file *stream, struct type *type,
            options);
 }
 
-
-/* Assuming TYPE is a simple array, print the value of this array located
-   at VALADDR + OFFSET.  See ada_val_print for a description of the various
-   parameters of this function; they are identical.  */
-
-static void
-ada_val_print_array (struct type *type, const gdb_byte *valaddr,
-                    int offset, CORE_ADDR address,
-                    struct ui_file *stream, int recurse,
-                    const struct value *val,
-                    const struct value_print_options *options)
-{
-  /* For an array of chars, print with string syntax.  */
-  if (ada_is_string_type (type)
-      && (options->format == 0 || options->format == 's'))
-    {
-      enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (type));
-      struct type *elttype = TYPE_TARGET_TYPE (type);
-      unsigned int eltlen;
-      unsigned int len;
-
-      /* We know that ELTTYPE cannot possibly be null, because we found
-        that TYPE is a string-like type.  Similarly, the size of ELTTYPE
-        should also be non-null, since it's a character-like type.  */
-      gdb_assert (elttype != NULL);
-      gdb_assert (TYPE_LENGTH (elttype) != 0);
-
-      eltlen = TYPE_LENGTH (elttype);
-      len = TYPE_LENGTH (type) / eltlen;
-
-      if (options->prettyformat_arrays)
-        print_spaces_filtered (2 + 2 * recurse, stream);
-
-      /* If requested, look for the first null char and only print
-         elements up to it.  */
-      if (options->stop_print_at_null)
-        {
-          int temp_len;
-
-          /* Look for a NULL char.  */
-          for (temp_len = 0;
-               (temp_len < len
-                && temp_len < options->print_max
-                && char_at (valaddr + offset,
-                           temp_len, eltlen, byte_order) != 0);
-               temp_len += 1);
-          len = temp_len;
-        }
-
-      printstr (stream, elttype, valaddr + offset, len, 0, eltlen, options);
-    }
-  else
-    {
-      fprintf_filtered (stream, "(");
-      print_optional_low_bound (stream, type, options);
-      if (TYPE_FIELD_BITSIZE (type, 0) > 0)
-        val_print_packed_array_elements (type, valaddr, offset,
-                                        0, stream, recurse, val, options);
-      else
-        val_print_array_elements (type, valaddr, offset, address,
-                                 stream, recurse, val, options, 0);
-      fprintf_filtered (stream, ")");
-    }
-}
-
 static int
 print_variant_part (struct type *type, int field_num,
                    const gdb_byte *valaddr, int offset,
@@ -609,7 +536,8 @@ print_variant_part (struct type *type, int field_num,
                    const struct value *val,
                    const struct value_print_options *options,
                    int comma_needed,
-                   struct type *outer_type, int outer_offset)
+                   struct type *outer_type, int outer_offset,
+                   const struct language_defn *language)
 {
   struct type *var_type = TYPE_FIELD_TYPE (type, field_num);
   int which = ada_which_variant_applies (var_type, outer_type,
@@ -624,7 +552,7 @@ print_variant_part (struct type *type, int field_num,
        offset + TYPE_FIELD_BITPOS (type, field_num) / HOST_CHAR_BIT
        + TYPE_FIELD_BITPOS (var_type, which) / HOST_CHAR_BIT,
        stream, recurse, val, options,
-       comma_needed, outer_type, outer_offset);
+       comma_needed, outer_type, outer_offset, language);
 }
 
 /* Print out fields of value at VALADDR + OFFSET having structure type TYPE.
@@ -648,7 +576,8 @@ print_field_values (struct type *type, const gdb_byte *valaddr,
                    const struct value *val,
                    const struct value_print_options *options,
                    int comma_needed,
-                   struct type *outer_type, int outer_offset)
+                   struct type *outer_type, int outer_offset,
+                   const struct language_defn *language)
 {
   int i, len;
 
@@ -667,7 +596,7 @@ print_field_values (struct type *type, const gdb_byte *valaddr,
                                (offset
                                 + TYPE_FIELD_BITPOS (type, i) / HOST_CHAR_BIT),
                                stream, recurse, val, options,
-                               comma_needed, type, offset);
+                               comma_needed, type, offset, language);
          continue;
        }
       else if (ada_is_variant_part (type, i))
@@ -676,7 +605,7 @@ print_field_values (struct type *type, const gdb_byte *valaddr,
            print_variant_part (type, i, valaddr,
                                offset, stream, recurse, val,
                                options, comma_needed,
-                               outer_type, outer_offset);
+                               outer_type, outer_offset, language);
          continue;
        }
 
@@ -730,7 +659,7 @@ print_field_values (struct type *type, const gdb_byte *valaddr,
                         value_contents_for_printing (v),
                         value_embedded_offset (v), 0,
                         stream, recurse + 1, v,
-                        &opts, current_language);
+                        &opts, language);
            }
        }
       else
@@ -738,11 +667,9 @@ print_field_values (struct type *type, const gdb_byte *valaddr,
          struct value_print_options opts = *options;
 
          opts.deref_ref = 0;
-         ada_val_print (TYPE_FIELD_TYPE (type, i),
-                        valaddr,
-                        (offset
-                         + TYPE_FIELD_BITPOS (type, i) / HOST_CHAR_BIT),
-                        0, stream, recurse + 1, val, &opts);
+         val_print (TYPE_FIELD_TYPE (type, i), valaddr,
+                    (offset + TYPE_FIELD_BITPOS (type, i) / HOST_CHAR_BIT),
+                    0, stream, recurse + 1, val, &opts, language);
        }
       annotate_field_end ();
     }
@@ -750,6 +677,54 @@ print_field_values (struct type *type, const gdb_byte *valaddr,
   return comma_needed;
 }
 
+/* Implement Ada val_print'ing for the case where TYPE is
+   a TYPE_CODE_ARRAY of characters.  */
+
+static void
+ada_val_print_string (struct type *type, const gdb_byte *valaddr,
+                     int offset, int offset_aligned, CORE_ADDR address,
+                     struct ui_file *stream, int recurse,
+                     const struct value *original_value,
+                     const struct value_print_options *options)
+{
+  enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (type));
+  struct type *elttype = TYPE_TARGET_TYPE (type);
+  unsigned int eltlen;
+  unsigned int len;
+
+  /* We know that ELTTYPE cannot possibly be null, because we assume
+     that we're called only when TYPE is a string-like type.
+     Similarly, the size of ELTTYPE should also be non-null, since
+     it's a character-like type.  */
+  gdb_assert (elttype != NULL);
+  gdb_assert (TYPE_LENGTH (elttype) != 0);
+
+  eltlen = TYPE_LENGTH (elttype);
+  len = TYPE_LENGTH (type) / eltlen;
+
+  if (options->prettyformat_arrays)
+    print_spaces_filtered (2 + 2 * recurse, stream);
+
+  /* If requested, look for the first null char and only print
+     elements up to it.  */
+  if (options->stop_print_at_null)
+    {
+      int temp_len;
+
+      /* Look for a NULL char.  */
+      for (temp_len = 0;
+          (temp_len < len
+           && temp_len < options->print_max
+           && char_at (valaddr + offset_aligned,
+                       temp_len, eltlen, byte_order) != 0);
+          temp_len += 1);
+      len = temp_len;
+    }
+
+  printstr (stream, elttype, valaddr + offset_aligned, len, 0,
+           eltlen, options);
+}
+
 /* Implement Ada val_print-ing for GNAT arrays (Eg. fat pointers,
    thin pointers, etc).  */
 
@@ -988,7 +963,7 @@ ada_val_print_struct_union
 
   if (print_field_values (type, valaddr, offset_aligned,
                          stream, recurse, original_value, options,
-                         0, type, offset_aligned) != 0
+                         0, type, offset_aligned, language) != 0
       && options->prettyformat)
     {
       fprintf_filtered (stream, "\n");
@@ -998,6 +973,39 @@ ada_val_print_struct_union
   fprintf_filtered (stream, ")");
 }
 
+/* Implement Ada val_print'ing for the case where TYPE is
+   a TYPE_CODE_ARRAY.  */
+
+static void
+ada_val_print_array (struct type *type, const gdb_byte *valaddr,
+                    int offset, int offset_aligned, CORE_ADDR address,
+                    struct ui_file *stream, int recurse,
+                    const struct value *original_value,
+                    const struct value_print_options *options)
+{
+  /* For an array of characters, print with string syntax.  */
+  if (ada_is_string_type (type)
+      && (options->format == 0 || options->format == 's'))
+    {
+      ada_val_print_string (type, valaddr, offset, offset_aligned,
+                           address, stream, recurse, original_value,
+                           options);
+      return;
+    }
+
+  fprintf_filtered (stream, "(");
+  print_optional_low_bound (stream, type, options);
+  if (TYPE_FIELD_BITSIZE (type, 0) > 0)
+    val_print_packed_array_elements (type, valaddr, offset_aligned,
+                                    0, stream, recurse,
+                                    original_value, options);
+  else
+    val_print_array_elements (type, valaddr, offset_aligned, address,
+                             stream, recurse, original_value,
+                             options, 0);
+  fprintf_filtered (stream, ")");
+}
+
 /* Implement Ada val_print'ing for the case where TYPE is
    a TYPE_CODE_REF.  */
 
@@ -1048,6 +1056,12 @@ ada_val_print_ref (struct type *type, const gdb_byte *valaddr,
   if (ada_is_tagged_type (value_type (deref_val), 1))
     deref_val = ada_tag_value_at_base_address (deref_val);
 
+  /* Make sure that the object does not have an unreasonable size
+     before trying to print it.  This can happen for instance with
+     references to dynamic objects whose contents is uninitialized
+     (Eg: an array whose bounds are not set yet).  */
+  ada_ensure_varsize_limit (value_type (deref_val));
+
   val_print (value_type (deref_val),
             value_contents_for_printing (deref_val),
             value_embedded_offset (deref_val),
@@ -1082,6 +1096,8 @@ ada_val_print_1 (struct type *type, const gdb_byte *valaddr,
 
   offset_aligned = offset + ada_aligned_value_addr (type, valaddr) - valaddr;
   type = printable_val_type (type, valaddr + offset_aligned);
+  type = resolve_dynamic_type (type, valaddr + offset_aligned,
+                              address + offset_aligned);
 
   switch (TYPE_CODE (type))
     {
@@ -1123,7 +1139,7 @@ ada_val_print_1 (struct type *type, const gdb_byte *valaddr,
       break;
 
     case TYPE_CODE_ARRAY:
-      ada_val_print_array (type, valaddr, offset_aligned,
+      ada_val_print_array (type, valaddr, offset, offset_aligned,
                           address, stream, recurse, original_value,
                           options);
       return;
@@ -1146,15 +1162,18 @@ ada_val_print (struct type *type, const gdb_byte *valaddr,
               const struct value *val,
               const struct value_print_options *options)
 {
-  volatile struct gdb_exception except;
 
   /* XXX: this catches QUIT/ctrl-c as well.  Isn't that busted?  */
-  TRY_CATCH (except, RETURN_MASK_ALL)
+  TRY
     {
       ada_val_print_1 (type, valaddr, embedded_offset, address,
                       stream, recurse, val, options,
                       current_language);
     }
+  CATCH (except, RETURN_MASK_ALL)
+    {
+    }
+  END_CATCH
 }
 
 void
@@ -1163,7 +1182,7 @@ ada_value_print (struct value *val0, struct ui_file *stream,
 {
   struct value *val = ada_to_fixed_value (val0);
   CORE_ADDR address = value_address (val);
-  struct type *type = ada_check_typedef (value_type (val));
+  struct type *type = ada_check_typedef (value_enclosing_type (val));
   struct value_print_options opts;
 
   /* If it is a pointer, indicate what it points to.  */
This page took 0.030116 seconds and 4 git commands to generate.