Update copyright dates.
[deliverable/binutils-gdb.git] / gdb / ada-valprint.c
index 2ab2ba2f3dec678c00b5f9acd98828f6130cadbd..c67266f90231ee89b68c3ac5a923d322c1a9e0e3 100644 (file)
@@ -1,7 +1,7 @@
 /* Support for printing Ada values for GDB, the GNU debugger.
 
    Copyright (C) 1986, 1988, 1989, 1991, 1992, 1993, 1994, 1997, 2001, 2002,
-   2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
+   2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
    Free Software Foundation, Inc.
 
    This file is part of GDB.
@@ -296,7 +296,7 @@ char_at (const gdb_byte *string, int i, int type_len,
     return (int) extract_unsigned_integer (string + 2 * i, 2, byte_order);
 }
 
-/* Wrapper around memcpy to make it legal argument to ui_file_put */
+/* Wrapper around memcpy to make it legal argument to ui_file_put */
 static void
 ui_memcpy (void *dest, const char *buffer, long len)
 {
@@ -453,9 +453,8 @@ ada_print_scalar (struct type *type, LONGEST val, struct ui_file *stream)
 /* Print the character string STRING, printing at most LENGTH characters.
    Printing stops early if the number hits print_max; repeat counts
    are printed as appropriate.  Print ellipses at the end if we
-   had to stop before printing LENGTH characters, or if
-   FORCE_ELLIPSES.   TYPE_LEN is the length (1 or 2) of the character type.
- */
+   had to stop before printing LENGTH characters, or if FORCE_ELLIPSES.
+   TYPE_LEN is the length (1 or 2) of the character type.  */
 
 static void
 printstr (struct ui_file *stream, struct type *elttype, const gdb_byte *string,
@@ -549,8 +548,9 @@ printstr (struct ui_file *stream, struct type *elttype, const gdb_byte *string,
 }
 
 void
-ada_printstr (struct ui_file *stream, struct type *type, const gdb_byte *string,
-             unsigned int length, const char *encoding, int force_ellipses,
+ada_printstr (struct ui_file *stream, struct type *type,
+             const gdb_byte *string, unsigned int length,
+             const char *encoding, int force_ellipses,
              const struct value_print_options *options)
 {
   printstr (stream, type, string, length, force_ellipses, TYPE_LENGTH (type),
@@ -603,23 +603,24 @@ ada_val_print_array (struct type *type, const gdb_byte *valaddr,
 {
   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;
   int result = 0;
 
-  if (elttype == NULL)
-    eltlen = 0;
-  else
-    eltlen = TYPE_LENGTH (elttype);
-  if (eltlen == 0)
-    len = 0;
-  else
-    len = TYPE_LENGTH (type) / eltlen;
-
   /* For an array of chars, print with string syntax.  */
   if (ada_is_string_type (type)
       && (options->format == 0 || options->format == 's'))
     {
+      unsigned int eltlen;
+      unsigned int len;
+
+      if (elttype == NULL)
+        eltlen = 0;
+      else
+        eltlen = TYPE_LENGTH (elttype);
+      if (eltlen == 0)
+        len = 0;
+      else
+        len = TYPE_LENGTH (type) / eltlen;
+
       if (options->prettyprint_arrays)
         print_spaces_filtered (2 + 2 * recurse, stream);
 
@@ -683,10 +684,14 @@ ada_val_print_1 (struct type *type, const gdb_byte *valaddr0,
       struct value *val;
 
       val = value_from_contents_and_address (type, valaddr, address);
-      val = ada_coerce_to_simple_array_ptr (val);
+      if (TYPE_CODE (type) == TYPE_CODE_TYPEDEF)  /* array access type.  */
+       val = ada_coerce_to_simple_array_ptr (val);
+      else
+       val = ada_coerce_to_simple_array (val);
       if (val == NULL)
        {
-         fprintf_filtered (stream, "(null)");
+         gdb_assert (TYPE_CODE (type) == TYPE_CODE_TYPEDEF);
+         fprintf_filtered (stream, "0x0");
          retn = 0;
        }
       else
@@ -756,7 +761,8 @@ ada_val_print_1 (struct type *type, const gdb_byte *valaddr0,
          else
            return ada_val_print_1 (TYPE_TARGET_TYPE (type),
                                    valaddr0, embedded_offset,
-                                   address, stream, recurse, original_value, options);
+                                   address, stream, recurse,
+                                   original_value, options);
        }
       else
        {
@@ -904,7 +910,8 @@ static int
 print_variant_part (struct type *type, int field_num, const gdb_byte *valaddr,
                    struct ui_file *stream, int recurse,
                    const struct value *val,
-                   const struct value_print_options *options, int comma_needed,
+                   const struct value_print_options *options,
+                   int comma_needed,
                    struct type *outer_type, const gdb_byte *outer_valaddr)
 {
   struct type *var_type = TYPE_FIELD_TYPE (type, field_num);
@@ -946,9 +953,15 @@ ada_value_print (struct value *val0, struct ui_file *stream,
     }
   else if (ada_is_array_descriptor_type (type))
     {
-      fprintf_filtered (stream, "(");
-      type_print (type, "", stream, -1);
-      fprintf_filtered (stream, ") ");
+      /* We do not print the type description unless TYPE is an array
+        access type (this is encoded by the compiler as a typedef to
+        a fat pointer - hence the check against TYPE_CODE_TYPEDEF).  */
+      if (TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
+        {
+         fprintf_filtered (stream, "(");
+         type_print (type, "", stream, -1);
+         fprintf_filtered (stream, ") ");
+       }
     }
   else if (ada_is_bogus_array_descriptor (type))
     {
This page took 0.028739 seconds and 4 git commands to generate.