Home | History | Annotate | Line # | Download | only in gdb
ada-valprint.c revision 1.1.1.6
      1      1.1  christos /* Support for printing Ada values for GDB, the GNU debugger.
      2      1.1  christos 
      3  1.1.1.6  christos    Copyright (C) 1986-2019 Free Software Foundation, Inc.
      4      1.1  christos 
      5      1.1  christos    This file is part of GDB.
      6      1.1  christos 
      7      1.1  christos    This program is free software; you can redistribute it and/or modify
      8      1.1  christos    it under the terms of the GNU General Public License as published by
      9      1.1  christos    the Free Software Foundation; either version 3 of the License, or
     10      1.1  christos    (at your option) any later version.
     11      1.1  christos 
     12      1.1  christos    This program is distributed in the hope that it will be useful,
     13      1.1  christos    but WITHOUT ANY WARRANTY; without even the implied warranty of
     14      1.1  christos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15      1.1  christos    GNU General Public License for more details.
     16      1.1  christos 
     17      1.1  christos    You should have received a copy of the GNU General Public License
     18      1.1  christos    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
     19      1.1  christos 
     20      1.1  christos #include "defs.h"
     21      1.1  christos #include <ctype.h>
     22      1.1  christos #include "symtab.h"
     23      1.1  christos #include "gdbtypes.h"
     24      1.1  christos #include "expression.h"
     25      1.1  christos #include "value.h"
     26      1.1  christos #include "demangle.h"
     27      1.1  christos #include "valprint.h"
     28      1.1  christos #include "language.h"
     29      1.1  christos #include "annotate.h"
     30      1.1  christos #include "ada-lang.h"
     31      1.1  christos #include "c-lang.h"
     32      1.1  christos #include "infcall.h"
     33      1.1  christos #include "objfiles.h"
     34  1.1.1.6  christos #include "target-float.h"
     35      1.1  christos 
     36      1.1  christos static int print_field_values (struct type *, const gdb_byte *,
     37      1.1  christos 			       int,
     38      1.1  christos 			       struct ui_file *, int,
     39  1.1.1.5  christos 			       struct value *,
     40      1.1  christos 			       const struct value_print_options *,
     41      1.1  christos 			       int, struct type *, int,
     42      1.1  christos 			       const struct language_defn *);
     43      1.1  christos 
     44      1.1  christos 
     46      1.1  christos /* Make TYPE unsigned if its range of values includes no negatives.  */
     47      1.1  christos static void
     48      1.1  christos adjust_type_signedness (struct type *type)
     49      1.1  christos {
     50      1.1  christos   if (type != NULL && TYPE_CODE (type) == TYPE_CODE_RANGE
     51      1.1  christos       && TYPE_LOW_BOUND (type) >= 0)
     52      1.1  christos     TYPE_UNSIGNED (type) = 1;
     53      1.1  christos }
     54      1.1  christos 
     55      1.1  christos /* Assuming TYPE is a simple array type, prints its lower bound on STREAM,
     56      1.1  christos    if non-standard (i.e., other than 1 for numbers, other than lower bound
     57      1.1  christos    of index type for enumerated type).  Returns 1 if something printed,
     58      1.1  christos    otherwise 0.  */
     59      1.1  christos 
     60      1.1  christos static int
     61      1.1  christos print_optional_low_bound (struct ui_file *stream, struct type *type,
     62      1.1  christos 			  const struct value_print_options *options)
     63      1.1  christos {
     64      1.1  christos   struct type *index_type;
     65      1.1  christos   LONGEST low_bound;
     66      1.1  christos   LONGEST high_bound;
     67      1.1  christos 
     68      1.1  christos   if (options->print_array_indexes)
     69      1.1  christos     return 0;
     70      1.1  christos 
     71      1.1  christos   if (!get_array_bounds (type, &low_bound, &high_bound))
     72      1.1  christos     return 0;
     73      1.1  christos 
     74      1.1  christos   /* If this is an empty array, then don't print the lower bound.
     75      1.1  christos      That would be confusing, because we would print the lower bound,
     76      1.1  christos      followed by... nothing!  */
     77      1.1  christos   if (low_bound > high_bound)
     78      1.1  christos     return 0;
     79      1.1  christos 
     80      1.1  christos   index_type = TYPE_INDEX_TYPE (type);
     81  1.1.1.2  christos 
     82      1.1  christos   while (TYPE_CODE (index_type) == TYPE_CODE_RANGE)
     83      1.1  christos     {
     84      1.1  christos       /* We need to know what the base type is, in order to do the
     85      1.1  christos          appropriate check below.  Otherwise, if this is a subrange
     86      1.1  christos          of an enumerated type, where the underlying value of the
     87      1.1  christos          first element is typically 0, we might test the low bound
     88      1.1  christos          against the wrong value.  */
     89      1.1  christos       index_type = TYPE_TARGET_TYPE (index_type);
     90      1.1  christos     }
     91  1.1.1.6  christos 
     92      1.1  christos   /* Don't print the lower bound if it's the default one.  */
     93      1.1  christos   switch (TYPE_CODE (index_type))
     94      1.1  christos     {
     95  1.1.1.6  christos     case TYPE_CODE_BOOL:
     96      1.1  christos     case TYPE_CODE_CHAR:
     97      1.1  christos       if (low_bound == 0)
     98      1.1  christos 	return 0;
     99      1.1  christos       break;
    100      1.1  christos     case TYPE_CODE_ENUM:
    101      1.1  christos       if (low_bound == TYPE_FIELD_ENUMVAL (index_type, 0))
    102      1.1  christos 	return 0;
    103      1.1  christos       break;
    104      1.1  christos     case TYPE_CODE_UNDEF:
    105      1.1  christos       index_type = NULL;
    106      1.1  christos       /* FALL THROUGH */
    107      1.1  christos     default:
    108      1.1  christos       if (low_bound == 1)
    109      1.1  christos 	return 0;
    110      1.1  christos       break;
    111      1.1  christos     }
    112      1.1  christos 
    113      1.1  christos   ada_print_scalar (index_type, low_bound, stream);
    114      1.1  christos   fprintf_filtered (stream, " => ");
    115      1.1  christos   return 1;
    116      1.1  christos }
    117      1.1  christos 
    118      1.1  christos /*  Version of val_print_array_elements for GNAT-style packed arrays.
    119      1.1  christos     Prints elements of packed array of type TYPE at bit offset
    120      1.1  christos     BITOFFSET from VALADDR on STREAM.  Formats according to OPTIONS and
    121      1.1  christos     separates with commas.  RECURSE is the recursion (nesting) level.
    122      1.1  christos     TYPE must have been decoded (as by ada_coerce_to_simple_array).  */
    123      1.1  christos 
    124      1.1  christos static void
    125      1.1  christos val_print_packed_array_elements (struct type *type, const gdb_byte *valaddr,
    126      1.1  christos 				 int offset,
    127      1.1  christos 				 int bitoffset, struct ui_file *stream,
    128  1.1.1.5  christos 				 int recurse,
    129      1.1  christos 				 struct value *val,
    130      1.1  christos 				 const struct value_print_options *options)
    131      1.1  christos {
    132      1.1  christos   unsigned int i;
    133      1.1  christos   unsigned int things_printed = 0;
    134      1.1  christos   unsigned len;
    135      1.1  christos   struct type *elttype, *index_type;
    136      1.1  christos   unsigned long bitsize = TYPE_FIELD_BITSIZE (type, 0);
    137      1.1  christos   struct value *mark = value_mark ();
    138      1.1  christos   LONGEST low = 0;
    139      1.1  christos 
    140      1.1  christos   elttype = TYPE_TARGET_TYPE (type);
    141      1.1  christos   index_type = TYPE_INDEX_TYPE (type);
    142      1.1  christos 
    143      1.1  christos   {
    144  1.1.1.6  christos     LONGEST high;
    145      1.1  christos     struct type *base_index_type;
    146      1.1  christos 
    147      1.1  christos     if (get_discrete_bounds (index_type, &low, &high) < 0)
    148      1.1  christos       len = 1;
    149      1.1  christos     else
    150  1.1.1.6  christos       len = high - low + 1;
    151  1.1.1.6  christos 
    152  1.1.1.6  christos     if (TYPE_CODE (index_type) == TYPE_CODE_RANGE)
    153  1.1.1.6  christos         base_index_type = TYPE_TARGET_TYPE (index_type);
    154  1.1.1.6  christos       else
    155  1.1.1.6  christos         base_index_type = index_type;
    156  1.1.1.6  christos 
    157  1.1.1.6  christos     if (TYPE_CODE (base_index_type) == TYPE_CODE_ENUM)
    158  1.1.1.6  christos       {
    159  1.1.1.6  christos         LONGEST low_pos, high_pos;
    160  1.1.1.6  christos 
    161  1.1.1.6  christos         /* Non-contiguous enumerations types can by used as index types
    162  1.1.1.6  christos            so the array length is computed from the positions of the
    163  1.1.1.6  christos            first and last literal in the enumeration type, and not from
    164  1.1.1.6  christos            the values of these literals.  */
    165  1.1.1.6  christos 
    166  1.1.1.6  christos         if (!discrete_position (base_index_type, low, &low_pos)
    167  1.1.1.6  christos           || !discrete_position (base_index_type, high, &high_pos))
    168  1.1.1.6  christos           {
    169  1.1.1.6  christos             warning (_("unable to get positions in array, use bounds instead"));
    170  1.1.1.6  christos             low_pos = low;
    171  1.1.1.6  christos             high_pos = high;
    172  1.1.1.6  christos           }
    173  1.1.1.6  christos 
    174  1.1.1.6  christos         /* The array length should normally be HIGH_POS - LOW_POS + 1.
    175  1.1.1.6  christos            But in Ada we allow LOW_POS to be greater than HIGH_POS for
    176  1.1.1.6  christos            empty arrays.  In that situation, the array length is just zero,
    177  1.1.1.6  christos            not negative!  */
    178  1.1.1.6  christos 
    179  1.1.1.6  christos         if (low_pos > high_pos)
    180  1.1.1.6  christos           len = 0;
    181  1.1.1.6  christos         else
    182  1.1.1.6  christos           len = high_pos - low_pos + 1;
    183      1.1  christos       }
    184      1.1  christos   }
    185      1.1  christos 
    186      1.1  christos   i = 0;
    187      1.1  christos   annotate_array_section_begin (i, elttype);
    188      1.1  christos 
    189      1.1  christos   while (i < len && things_printed < options->print_max)
    190      1.1  christos     {
    191      1.1  christos       struct value *v0, *v1;
    192      1.1  christos       int i0;
    193      1.1  christos 
    194      1.1  christos       if (i != 0)
    195      1.1  christos 	{
    196      1.1  christos 	  if (options->prettyformat_arrays)
    197      1.1  christos 	    {
    198      1.1  christos 	      fprintf_filtered (stream, ",\n");
    199      1.1  christos 	      print_spaces_filtered (2 + 2 * recurse, stream);
    200      1.1  christos 	    }
    201      1.1  christos 	  else
    202      1.1  christos 	    {
    203      1.1  christos 	      fprintf_filtered (stream, ", ");
    204      1.1  christos 	    }
    205      1.1  christos 	}
    206      1.1  christos       wrap_here (n_spaces (2 + 2 * recurse));
    207      1.1  christos       maybe_print_array_index (index_type, i + low, stream, options);
    208      1.1  christos 
    209      1.1  christos       i0 = i;
    210      1.1  christos       v0 = ada_value_primitive_packed_val (NULL, valaddr + offset,
    211      1.1  christos 					   (i0 * bitsize) / HOST_CHAR_BIT,
    212      1.1  christos 					   (i0 * bitsize) % HOST_CHAR_BIT,
    213      1.1  christos 					   bitsize, elttype);
    214      1.1  christos       while (1)
    215      1.1  christos 	{
    216      1.1  christos 	  i += 1;
    217      1.1  christos 	  if (i >= len)
    218      1.1  christos 	    break;
    219      1.1  christos 	  v1 = ada_value_primitive_packed_val (NULL, valaddr + offset,
    220      1.1  christos 					       (i * bitsize) / HOST_CHAR_BIT,
    221      1.1  christos 					       (i * bitsize) % HOST_CHAR_BIT,
    222  1.1.1.3  christos 					       bitsize, elttype);
    223  1.1.1.3  christos 	  if (TYPE_LENGTH (check_typedef (value_type (v0)))
    224  1.1.1.3  christos 	      != TYPE_LENGTH (check_typedef (value_type (v1))))
    225  1.1.1.2  christos 	    break;
    226  1.1.1.2  christos 	  if (!value_contents_eq (v0, value_embedded_offset (v0),
    227  1.1.1.3  christos 				  v1, value_embedded_offset (v1),
    228      1.1  christos 				  TYPE_LENGTH (check_typedef (value_type (v0)))))
    229      1.1  christos 	    break;
    230      1.1  christos 	}
    231      1.1  christos 
    232      1.1  christos       if (i - i0 > options->repeat_count_threshold)
    233      1.1  christos 	{
    234      1.1  christos 	  struct value_print_options opts = *options;
    235      1.1  christos 
    236  1.1.1.5  christos 	  opts.deref_ref = 0;
    237      1.1  christos 	  val_print (elttype,
    238      1.1  christos 		     value_embedded_offset (v0), 0, stream,
    239      1.1  christos 		     recurse + 1, v0, &opts, current_language);
    240      1.1  christos 	  annotate_elt_rep (i - i0);
    241      1.1  christos 	  fprintf_filtered (stream, _(" <repeats %u times>"), i - i0);
    242      1.1  christos 	  annotate_elt_rep_end ();
    243      1.1  christos 
    244      1.1  christos 	}
    245      1.1  christos       else
    246      1.1  christos 	{
    247      1.1  christos 	  int j;
    248      1.1  christos 	  struct value_print_options opts = *options;
    249      1.1  christos 
    250      1.1  christos 	  opts.deref_ref = 0;
    251      1.1  christos 	  for (j = i0; j < i; j += 1)
    252      1.1  christos 	    {
    253      1.1  christos 	      if (j > i0)
    254      1.1  christos 		{
    255      1.1  christos 		  if (options->prettyformat_arrays)
    256      1.1  christos 		    {
    257      1.1  christos 		      fprintf_filtered (stream, ",\n");
    258      1.1  christos 		      print_spaces_filtered (2 + 2 * recurse, stream);
    259      1.1  christos 		    }
    260      1.1  christos 		  else
    261      1.1  christos 		    {
    262      1.1  christos 		      fprintf_filtered (stream, ", ");
    263      1.1  christos 		    }
    264      1.1  christos 		  wrap_here (n_spaces (2 + 2 * recurse));
    265      1.1  christos 		  maybe_print_array_index (index_type, j + low,
    266      1.1  christos 					   stream, options);
    267  1.1.1.5  christos 		}
    268      1.1  christos 	      val_print (elttype,
    269      1.1  christos 			 value_embedded_offset (v0), 0, stream,
    270      1.1  christos 			 recurse + 1, v0, &opts, current_language);
    271      1.1  christos 	      annotate_elt ();
    272      1.1  christos 	    }
    273      1.1  christos 	}
    274      1.1  christos       things_printed += i - i0;
    275      1.1  christos     }
    276      1.1  christos   annotate_array_section_end ();
    277      1.1  christos   if (i < len)
    278      1.1  christos     {
    279      1.1  christos       fprintf_filtered (stream, "...");
    280      1.1  christos     }
    281      1.1  christos 
    282      1.1  christos   value_free_to_mark (mark);
    283      1.1  christos }
    284      1.1  christos 
    285      1.1  christos static struct type *
    286      1.1  christos printable_val_type (struct type *type, const gdb_byte *valaddr)
    287      1.1  christos {
    288      1.1  christos   return ada_to_fixed_type (ada_aligned_type (type), valaddr, 0, NULL, 1);
    289      1.1  christos }
    290      1.1  christos 
    291      1.1  christos /* Print the character C on STREAM as part of the contents of a literal
    292      1.1  christos    string whose delimiter is QUOTER.  TYPE_LEN is the length in bytes
    293      1.1  christos    of the character.  */
    294      1.1  christos 
    295      1.1  christos void
    296      1.1  christos ada_emit_char (int c, struct type *type, struct ui_file *stream,
    297      1.1  christos 	       int quoter, int type_len)
    298      1.1  christos {
    299      1.1  christos   /* If this character fits in the normal ASCII range, and is
    300      1.1  christos      a printable character, then print the character as if it was
    301      1.1  christos      an ASCII character, even if this is a wide character.
    302      1.1  christos      The UCHAR_MAX check is necessary because the isascii function
    303      1.1  christos      requires that its argument have a value of an unsigned char,
    304      1.1  christos      or EOF (EOF is obviously not printable).  */
    305      1.1  christos   if (c <= UCHAR_MAX && isascii (c) && isprint (c))
    306      1.1  christos     {
    307      1.1  christos       if (c == quoter && c == '"')
    308      1.1  christos 	fprintf_filtered (stream, "\"\"");
    309      1.1  christos       else
    310      1.1  christos 	fprintf_filtered (stream, "%c", c);
    311      1.1  christos     }
    312      1.1  christos   else
    313      1.1  christos     fprintf_filtered (stream, "[\"%0*x\"]", type_len * 2, c);
    314      1.1  christos }
    315      1.1  christos 
    316      1.1  christos /* Character #I of STRING, given that TYPE_LEN is the size in bytes
    317      1.1  christos    of a character.  */
    318      1.1  christos 
    319      1.1  christos static int
    320      1.1  christos char_at (const gdb_byte *string, int i, int type_len,
    321      1.1  christos 	 enum bfd_endian byte_order)
    322      1.1  christos {
    323      1.1  christos   if (type_len == 1)
    324      1.1  christos     return string[i];
    325      1.1  christos   else
    326      1.1  christos     return (int) extract_unsigned_integer (string + type_len * i,
    327      1.1  christos                                            type_len, byte_order);
    328      1.1  christos }
    329      1.1  christos 
    330      1.1  christos /* Print a floating-point value of type TYPE, pointed to in GDB by
    331      1.1  christos    VALADDR, on STREAM.  Use Ada formatting conventions: there must be
    332      1.1  christos    a decimal point, and at least one digit before and after the
    333      1.1  christos    point.  We use the GNAT format for NaNs and infinities.  */
    334      1.1  christos 
    335      1.1  christos static void
    336      1.1  christos ada_print_floating (const gdb_byte *valaddr, struct type *type,
    337      1.1  christos 		    struct ui_file *stream)
    338  1.1.1.5  christos {
    339  1.1.1.5  christos   string_file tmp_stream;
    340  1.1.1.5  christos 
    341  1.1.1.5  christos   print_floating (valaddr, type, &tmp_stream);
    342  1.1.1.5  christos 
    343  1.1.1.5  christos   std::string &s = tmp_stream.string ();
    344      1.1  christos   size_t skip_count = 0;
    345      1.1  christos 
    346      1.1  christos   /* Modify for Ada rules.  */
    347  1.1.1.5  christos 
    348  1.1.1.5  christos   size_t pos = s.find ("inf");
    349  1.1.1.5  christos   if (pos == std::string::npos)
    350  1.1.1.5  christos     pos = s.find ("Inf");
    351  1.1.1.5  christos   if (pos == std::string::npos)
    352  1.1.1.5  christos     pos = s.find ("INF");
    353  1.1.1.5  christos   if (pos != std::string::npos)
    354  1.1.1.5  christos     s.replace (pos, 3, "Inf");
    355  1.1.1.5  christos 
    356  1.1.1.5  christos   if (pos == std::string::npos)
    357  1.1.1.5  christos     {
    358  1.1.1.5  christos       pos = s.find ("nan");
    359  1.1.1.5  christos       if (pos == std::string::npos)
    360  1.1.1.5  christos 	pos = s.find ("NaN");
    361  1.1.1.5  christos       if (pos == std::string::npos)
    362  1.1.1.5  christos 	pos = s.find ("Nan");
    363  1.1.1.5  christos       if (pos != std::string::npos)
    364  1.1.1.5  christos 	{
    365  1.1.1.5  christos 	  s[pos] = s[pos + 2] = 'N';
    366  1.1.1.5  christos 	  if (s[0] == '-')
    367      1.1  christos 	    skip_count = 1;
    368      1.1  christos 	}
    369      1.1  christos     }
    370  1.1.1.5  christos 
    371  1.1.1.5  christos   if (pos == std::string::npos
    372  1.1.1.5  christos       && s.find ('.') == std::string::npos)
    373  1.1.1.5  christos     {
    374  1.1.1.5  christos       pos = s.find ('e');
    375  1.1.1.5  christos       if (pos == std::string::npos)
    376      1.1  christos 	fprintf_filtered (stream, "%s.0", s.c_str ());
    377  1.1.1.5  christos       else
    378      1.1  christos 	fprintf_filtered (stream, "%.*s.0%s", (int) pos, s.c_str (), &s[pos]);
    379      1.1  christos     }
    380  1.1.1.5  christos   else
    381      1.1  christos     fprintf_filtered (stream, "%s", &s[skip_count]);
    382      1.1  christos }
    383      1.1  christos 
    384      1.1  christos void
    385      1.1  christos ada_printchar (int c, struct type *type, struct ui_file *stream)
    386      1.1  christos {
    387      1.1  christos   fputs_filtered ("'", stream);
    388      1.1  christos   ada_emit_char (c, type, stream, '\'', TYPE_LENGTH (type));
    389      1.1  christos   fputs_filtered ("'", stream);
    390      1.1  christos }
    391      1.1  christos 
    392      1.1  christos /* [From print_type_scalar in typeprint.c].   Print VAL on STREAM in a
    393      1.1  christos    form appropriate for TYPE, if non-NULL.  If TYPE is NULL, print VAL
    394      1.1  christos    like a default signed integer.  */
    395      1.1  christos 
    396      1.1  christos void
    397      1.1  christos ada_print_scalar (struct type *type, LONGEST val, struct ui_file *stream)
    398      1.1  christos {
    399      1.1  christos   unsigned int i;
    400      1.1  christos   unsigned len;
    401      1.1  christos 
    402      1.1  christos   if (!type)
    403      1.1  christos     {
    404      1.1  christos       print_longest (stream, 'd', 0, val);
    405      1.1  christos       return;
    406      1.1  christos     }
    407      1.1  christos 
    408      1.1  christos   type = ada_check_typedef (type);
    409      1.1  christos 
    410      1.1  christos   switch (TYPE_CODE (type))
    411      1.1  christos     {
    412      1.1  christos 
    413      1.1  christos     case TYPE_CODE_ENUM:
    414      1.1  christos       len = TYPE_NFIELDS (type);
    415      1.1  christos       for (i = 0; i < len; i++)
    416      1.1  christos 	{
    417      1.1  christos 	  if (TYPE_FIELD_ENUMVAL (type, i) == val)
    418      1.1  christos 	    {
    419      1.1  christos 	      break;
    420      1.1  christos 	    }
    421      1.1  christos 	}
    422      1.1  christos       if (i < len)
    423      1.1  christos 	{
    424      1.1  christos 	  fputs_filtered (ada_enum_name (TYPE_FIELD_NAME (type, i)), stream);
    425      1.1  christos 	}
    426      1.1  christos       else
    427      1.1  christos 	{
    428      1.1  christos 	  print_longest (stream, 'd', 0, val);
    429      1.1  christos 	}
    430      1.1  christos       break;
    431      1.1  christos 
    432      1.1  christos     case TYPE_CODE_INT:
    433      1.1  christos       print_longest (stream, TYPE_UNSIGNED (type) ? 'u' : 'd', 0, val);
    434      1.1  christos       break;
    435      1.1  christos 
    436      1.1  christos     case TYPE_CODE_CHAR:
    437      1.1  christos       LA_PRINT_CHAR (val, type, stream);
    438      1.1  christos       break;
    439      1.1  christos 
    440      1.1  christos     case TYPE_CODE_BOOL:
    441      1.1  christos       fprintf_filtered (stream, val ? "true" : "false");
    442      1.1  christos       break;
    443      1.1  christos 
    444      1.1  christos     case TYPE_CODE_RANGE:
    445      1.1  christos       ada_print_scalar (TYPE_TARGET_TYPE (type), val, stream);
    446      1.1  christos       return;
    447      1.1  christos 
    448      1.1  christos     case TYPE_CODE_UNDEF:
    449      1.1  christos     case TYPE_CODE_PTR:
    450      1.1  christos     case TYPE_CODE_ARRAY:
    451      1.1  christos     case TYPE_CODE_STRUCT:
    452      1.1  christos     case TYPE_CODE_UNION:
    453      1.1  christos     case TYPE_CODE_FUNC:
    454      1.1  christos     case TYPE_CODE_FLT:
    455      1.1  christos     case TYPE_CODE_VOID:
    456      1.1  christos     case TYPE_CODE_SET:
    457      1.1  christos     case TYPE_CODE_STRING:
    458      1.1  christos     case TYPE_CODE_ERROR:
    459      1.1  christos     case TYPE_CODE_MEMBERPTR:
    460      1.1  christos     case TYPE_CODE_METHODPTR:
    461      1.1  christos     case TYPE_CODE_METHOD:
    462      1.1  christos     case TYPE_CODE_REF:
    463      1.1  christos       warning (_("internal error: unhandled type in ada_print_scalar"));
    464      1.1  christos       break;
    465      1.1  christos 
    466      1.1  christos     default:
    467      1.1  christos       error (_("Invalid type code in symbol table."));
    468      1.1  christos     }
    469      1.1  christos   gdb_flush (stream);
    470      1.1  christos }
    471      1.1  christos 
    472      1.1  christos /* Print the character string STRING, printing at most LENGTH characters.
    473      1.1  christos    Printing stops early if the number hits print_max; repeat counts
    474      1.1  christos    are printed as appropriate.  Print ellipses at the end if we
    475      1.1  christos    had to stop before printing LENGTH characters, or if FORCE_ELLIPSES.
    476      1.1  christos    TYPE_LEN is the length (1 or 2) of the character type.  */
    477      1.1  christos 
    478      1.1  christos static void
    479      1.1  christos printstr (struct ui_file *stream, struct type *elttype, const gdb_byte *string,
    480      1.1  christos 	  unsigned int length, int force_ellipses, int type_len,
    481      1.1  christos 	  const struct value_print_options *options)
    482      1.1  christos {
    483      1.1  christos   enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (elttype));
    484      1.1  christos   unsigned int i;
    485      1.1  christos   unsigned int things_printed = 0;
    486      1.1  christos   int in_quotes = 0;
    487      1.1  christos   int need_comma = 0;
    488      1.1  christos 
    489      1.1  christos   if (length == 0)
    490      1.1  christos     {
    491      1.1  christos       fputs_filtered ("\"\"", stream);
    492      1.1  christos       return;
    493      1.1  christos     }
    494      1.1  christos 
    495      1.1  christos   for (i = 0; i < length && things_printed < options->print_max; i += 1)
    496      1.1  christos     {
    497      1.1  christos       /* Position of the character we are examining
    498      1.1  christos          to see whether it is repeated.  */
    499      1.1  christos       unsigned int rep1;
    500      1.1  christos       /* Number of repetitions we have detected so far.  */
    501      1.1  christos       unsigned int reps;
    502      1.1  christos 
    503      1.1  christos       QUIT;
    504      1.1  christos 
    505      1.1  christos       if (need_comma)
    506      1.1  christos 	{
    507      1.1  christos 	  fputs_filtered (", ", stream);
    508      1.1  christos 	  need_comma = 0;
    509      1.1  christos 	}
    510      1.1  christos 
    511      1.1  christos       rep1 = i + 1;
    512      1.1  christos       reps = 1;
    513      1.1  christos       while (rep1 < length
    514      1.1  christos 	     && char_at (string, rep1, type_len, byte_order)
    515      1.1  christos 		== char_at (string, i, type_len, byte_order))
    516      1.1  christos 	{
    517      1.1  christos 	  rep1 += 1;
    518      1.1  christos 	  reps += 1;
    519      1.1  christos 	}
    520      1.1  christos 
    521      1.1  christos       if (reps > options->repeat_count_threshold)
    522      1.1  christos 	{
    523      1.1  christos 	  if (in_quotes)
    524      1.1  christos 	    {
    525      1.1  christos 	      fputs_filtered ("\", ", stream);
    526      1.1  christos 	      in_quotes = 0;
    527      1.1  christos 	    }
    528      1.1  christos 	  fputs_filtered ("'", stream);
    529      1.1  christos 	  ada_emit_char (char_at (string, i, type_len, byte_order),
    530      1.1  christos 			 elttype, stream, '\'', type_len);
    531      1.1  christos 	  fputs_filtered ("'", stream);
    532      1.1  christos 	  fprintf_filtered (stream, _(" <repeats %u times>"), reps);
    533      1.1  christos 	  i = rep1 - 1;
    534      1.1  christos 	  things_printed += options->repeat_count_threshold;
    535      1.1  christos 	  need_comma = 1;
    536      1.1  christos 	}
    537      1.1  christos       else
    538      1.1  christos 	{
    539      1.1  christos 	  if (!in_quotes)
    540      1.1  christos 	    {
    541      1.1  christos 	      fputs_filtered ("\"", stream);
    542      1.1  christos 	      in_quotes = 1;
    543      1.1  christos 	    }
    544      1.1  christos 	  ada_emit_char (char_at (string, i, type_len, byte_order),
    545      1.1  christos 			 elttype, stream, '"', type_len);
    546      1.1  christos 	  things_printed += 1;
    547      1.1  christos 	}
    548      1.1  christos     }
    549      1.1  christos 
    550      1.1  christos   /* Terminate the quotes if necessary.  */
    551      1.1  christos   if (in_quotes)
    552      1.1  christos     fputs_filtered ("\"", stream);
    553      1.1  christos 
    554      1.1  christos   if (force_ellipses || i < length)
    555      1.1  christos     fputs_filtered ("...", stream);
    556      1.1  christos }
    557      1.1  christos 
    558      1.1  christos void
    559      1.1  christos ada_printstr (struct ui_file *stream, struct type *type,
    560      1.1  christos 	      const gdb_byte *string, unsigned int length,
    561      1.1  christos 	      const char *encoding, int force_ellipses,
    562      1.1  christos 	      const struct value_print_options *options)
    563      1.1  christos {
    564      1.1  christos   printstr (stream, type, string, length, force_ellipses, TYPE_LENGTH (type),
    565      1.1  christos 	    options);
    566      1.1  christos }
    567      1.1  christos 
    568      1.1  christos static int
    569      1.1  christos print_variant_part (struct type *type, int field_num,
    570      1.1  christos 		    const gdb_byte *valaddr, int offset,
    571  1.1.1.5  christos 		    struct ui_file *stream, int recurse,
    572      1.1  christos 		    struct value *val,
    573      1.1  christos 		    const struct value_print_options *options,
    574      1.1  christos 		    int comma_needed,
    575      1.1  christos 		    struct type *outer_type, int outer_offset,
    576      1.1  christos 		    const struct language_defn *language)
    577      1.1  christos {
    578      1.1  christos   struct type *var_type = TYPE_FIELD_TYPE (type, field_num);
    579      1.1  christos   int which = ada_which_variant_applies (var_type, outer_type,
    580      1.1  christos 					 valaddr + outer_offset);
    581      1.1  christos 
    582      1.1  christos   if (which < 0)
    583      1.1  christos     return 0;
    584      1.1  christos   else
    585      1.1  christos     return print_field_values
    586      1.1  christos       (TYPE_FIELD_TYPE (var_type, which),
    587      1.1  christos        valaddr,
    588      1.1  christos        offset + TYPE_FIELD_BITPOS (type, field_num) / HOST_CHAR_BIT
    589      1.1  christos        + TYPE_FIELD_BITPOS (var_type, which) / HOST_CHAR_BIT,
    590      1.1  christos        stream, recurse, val, options,
    591      1.1  christos        comma_needed, outer_type, outer_offset, language);
    592      1.1  christos }
    593      1.1  christos 
    594      1.1  christos /* Print out fields of value at VALADDR + OFFSET having structure type TYPE.
    595      1.1  christos 
    596      1.1  christos    TYPE, VALADDR, OFFSET, STREAM, RECURSE, and OPTIONS have the same
    597      1.1  christos    meanings as in ada_print_value and ada_val_print.
    598      1.1  christos 
    599      1.1  christos    OUTER_TYPE and OUTER_OFFSET give type and address of enclosing
    600      1.1  christos    record (used to get discriminant values when printing variant
    601      1.1  christos    parts).
    602      1.1  christos 
    603      1.1  christos    COMMA_NEEDED is 1 if fields have been printed at the current recursion
    604      1.1  christos    level, so that a comma is needed before any field printed by this
    605      1.1  christos    call.
    606      1.1  christos 
    607      1.1  christos    Returns 1 if COMMA_NEEDED or any fields were printed.  */
    608      1.1  christos 
    609      1.1  christos static int
    610      1.1  christos print_field_values (struct type *type, const gdb_byte *valaddr,
    611  1.1.1.5  christos 		    int offset, struct ui_file *stream, int recurse,
    612      1.1  christos 		    struct value *val,
    613      1.1  christos 		    const struct value_print_options *options,
    614      1.1  christos 		    int comma_needed,
    615      1.1  christos 		    struct type *outer_type, int outer_offset,
    616      1.1  christos 		    const struct language_defn *language)
    617      1.1  christos {
    618      1.1  christos   int i, len;
    619      1.1  christos 
    620      1.1  christos   len = TYPE_NFIELDS (type);
    621      1.1  christos 
    622      1.1  christos   for (i = 0; i < len; i += 1)
    623      1.1  christos     {
    624      1.1  christos       if (ada_is_ignored_field (type, i))
    625      1.1  christos 	continue;
    626      1.1  christos 
    627      1.1  christos       if (ada_is_wrapper_field (type, i))
    628      1.1  christos 	{
    629      1.1  christos 	  comma_needed =
    630      1.1  christos 	    print_field_values (TYPE_FIELD_TYPE (type, i),
    631      1.1  christos 				valaddr,
    632      1.1  christos 				(offset
    633      1.1  christos 				 + TYPE_FIELD_BITPOS (type, i) / HOST_CHAR_BIT),
    634      1.1  christos 				stream, recurse, val, options,
    635      1.1  christos 				comma_needed, type, offset, language);
    636      1.1  christos 	  continue;
    637      1.1  christos 	}
    638      1.1  christos       else if (ada_is_variant_part (type, i))
    639      1.1  christos 	{
    640      1.1  christos 	  comma_needed =
    641      1.1  christos 	    print_variant_part (type, i, valaddr,
    642      1.1  christos 				offset, stream, recurse, val,
    643      1.1  christos 				options, comma_needed,
    644      1.1  christos 				outer_type, outer_offset, language);
    645      1.1  christos 	  continue;
    646      1.1  christos 	}
    647      1.1  christos 
    648      1.1  christos       if (comma_needed)
    649      1.1  christos 	fprintf_filtered (stream, ", ");
    650      1.1  christos       comma_needed = 1;
    651      1.1  christos 
    652      1.1  christos       if (options->prettyformat)
    653      1.1  christos 	{
    654      1.1  christos 	  fprintf_filtered (stream, "\n");
    655      1.1  christos 	  print_spaces_filtered (2 + 2 * recurse, stream);
    656      1.1  christos 	}
    657      1.1  christos       else
    658      1.1  christos 	{
    659      1.1  christos 	  wrap_here (n_spaces (2 + 2 * recurse));
    660      1.1  christos 	}
    661      1.1  christos 
    662      1.1  christos       annotate_field_begin (TYPE_FIELD_TYPE (type, i));
    663      1.1  christos       fprintf_filtered (stream, "%.*s",
    664      1.1  christos 			ada_name_prefix_len (TYPE_FIELD_NAME (type, i)),
    665      1.1  christos 			TYPE_FIELD_NAME (type, i));
    666      1.1  christos       annotate_field_name_end ();
    667      1.1  christos       fputs_filtered (" => ", stream);
    668      1.1  christos       annotate_field_value ();
    669      1.1  christos 
    670      1.1  christos       if (TYPE_FIELD_PACKED (type, i))
    671      1.1  christos 	{
    672      1.1  christos 	  /* Bitfields require special handling, especially due to byte
    673      1.1  christos 	     order problems.  */
    674      1.1  christos 	  if (HAVE_CPLUS_STRUCT (type) && TYPE_FIELD_IGNORE (type, i))
    675      1.1  christos 	    {
    676      1.1  christos 	      fputs_filtered (_("<optimized out or zero length>"), stream);
    677      1.1  christos 	    }
    678      1.1  christos 	  else
    679  1.1.1.5  christos 	    {
    680      1.1  christos 	      struct value *v;
    681      1.1  christos 	      int bit_pos = TYPE_FIELD_BITPOS (type, i);
    682      1.1  christos 	      int bit_size = TYPE_FIELD_BITSIZE (type, i);
    683      1.1  christos 	      struct value_print_options opts;
    684      1.1  christos 
    685      1.1  christos 	      adjust_type_signedness (TYPE_FIELD_TYPE (type, i));
    686      1.1  christos 	      v = ada_value_primitive_packed_val
    687      1.1  christos 		    (NULL, valaddr,
    688      1.1  christos 		     offset + bit_pos / HOST_CHAR_BIT,
    689      1.1  christos 		     bit_pos % HOST_CHAR_BIT,
    690      1.1  christos 		     bit_size, TYPE_FIELD_TYPE (type, i));
    691      1.1  christos 	      opts = *options;
    692      1.1  christos 	      opts.deref_ref = 0;
    693      1.1  christos 	      val_print (TYPE_FIELD_TYPE (type, i),
    694      1.1  christos 			 value_embedded_offset (v), 0,
    695      1.1  christos 			 stream, recurse + 1, v,
    696      1.1  christos 			 &opts, language);
    697      1.1  christos 	    }
    698      1.1  christos 	}
    699      1.1  christos       else
    700      1.1  christos 	{
    701      1.1  christos 	  struct value_print_options opts = *options;
    702      1.1  christos 
    703  1.1.1.5  christos 	  opts.deref_ref = 0;
    704      1.1  christos 	  val_print (TYPE_FIELD_TYPE (type, i),
    705      1.1  christos 		     (offset + TYPE_FIELD_BITPOS (type, i) / HOST_CHAR_BIT),
    706      1.1  christos 		     0, stream, recurse + 1, val, &opts, language);
    707      1.1  christos 	}
    708      1.1  christos       annotate_field_end ();
    709      1.1  christos     }
    710      1.1  christos 
    711      1.1  christos   return comma_needed;
    712      1.1  christos }
    713      1.1  christos 
    714      1.1  christos /* Implement Ada val_print'ing for the case where TYPE is
    715      1.1  christos    a TYPE_CODE_ARRAY of characters.  */
    716      1.1  christos 
    717      1.1  christos static void
    718      1.1  christos ada_val_print_string (struct type *type, const gdb_byte *valaddr,
    719      1.1  christos 		      int offset, int offset_aligned, CORE_ADDR address,
    720  1.1.1.5  christos 		      struct ui_file *stream, int recurse,
    721      1.1  christos 		      struct value *original_value,
    722      1.1  christos 		      const struct value_print_options *options)
    723      1.1  christos {
    724      1.1  christos   enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (type));
    725      1.1  christos   struct type *elttype = TYPE_TARGET_TYPE (type);
    726      1.1  christos   unsigned int eltlen;
    727      1.1  christos   unsigned int len;
    728      1.1  christos 
    729      1.1  christos   /* We know that ELTTYPE cannot possibly be null, because we assume
    730      1.1  christos      that we're called only when TYPE is a string-like type.
    731      1.1  christos      Similarly, the size of ELTTYPE should also be non-null, since
    732      1.1  christos      it's a character-like type.  */
    733      1.1  christos   gdb_assert (elttype != NULL);
    734      1.1  christos   gdb_assert (TYPE_LENGTH (elttype) != 0);
    735      1.1  christos 
    736      1.1  christos   eltlen = TYPE_LENGTH (elttype);
    737      1.1  christos   len = TYPE_LENGTH (type) / eltlen;
    738      1.1  christos 
    739      1.1  christos   if (options->prettyformat_arrays)
    740      1.1  christos     print_spaces_filtered (2 + 2 * recurse, stream);
    741      1.1  christos 
    742      1.1  christos   /* If requested, look for the first null char and only print
    743      1.1  christos      elements up to it.  */
    744      1.1  christos   if (options->stop_print_at_null)
    745      1.1  christos     {
    746      1.1  christos       int temp_len;
    747      1.1  christos 
    748      1.1  christos       /* Look for a NULL char.  */
    749      1.1  christos       for (temp_len = 0;
    750      1.1  christos 	   (temp_len < len
    751      1.1  christos 	    && temp_len < options->print_max
    752      1.1  christos 	    && char_at (valaddr + offset_aligned,
    753      1.1  christos 			temp_len, eltlen, byte_order) != 0);
    754      1.1  christos 	   temp_len += 1);
    755      1.1  christos       len = temp_len;
    756      1.1  christos     }
    757      1.1  christos 
    758      1.1  christos   printstr (stream, elttype, valaddr + offset_aligned, len, 0,
    759      1.1  christos 	    eltlen, options);
    760      1.1  christos }
    761      1.1  christos 
    762      1.1  christos /* Implement Ada val_print-ing for GNAT arrays (Eg. fat pointers,
    763      1.1  christos    thin pointers, etc).  */
    764      1.1  christos 
    765      1.1  christos static void
    766      1.1  christos ada_val_print_gnat_array (struct type *type, const gdb_byte *valaddr,
    767      1.1  christos 			  int offset, CORE_ADDR address,
    768  1.1.1.5  christos 			  struct ui_file *stream, int recurse,
    769      1.1  christos 			  struct value *original_value,
    770      1.1  christos 			  const struct value_print_options *options,
    771      1.1  christos 			  const struct language_defn *language)
    772      1.1  christos {
    773      1.1  christos   struct value *mark = value_mark ();
    774      1.1  christos   struct value *val;
    775      1.1  christos 
    776      1.1  christos   val = value_from_contents_and_address (type, valaddr + offset, address);
    777      1.1  christos   /* If this is a reference, coerce it now.  This helps taking care
    778      1.1  christos      of the case where ADDRESS is meaningless because original_value
    779      1.1  christos      was not an lval.  */
    780      1.1  christos   val = coerce_ref (val);
    781      1.1  christos   if (TYPE_CODE (type) == TYPE_CODE_TYPEDEF)  /* array access type.  */
    782      1.1  christos     val = ada_coerce_to_simple_array_ptr (val);
    783      1.1  christos   else
    784      1.1  christos     val = ada_coerce_to_simple_array (val);
    785      1.1  christos   if (val == NULL)
    786      1.1  christos     {
    787      1.1  christos       gdb_assert (TYPE_CODE (type) == TYPE_CODE_TYPEDEF);
    788      1.1  christos       fprintf_filtered (stream, "0x0");
    789      1.1  christos     }
    790  1.1.1.5  christos   else
    791      1.1  christos     val_print (value_type (val),
    792      1.1  christos 	       value_embedded_offset (val), value_address (val),
    793      1.1  christos 	       stream, recurse, val, options, language);
    794      1.1  christos   value_free_to_mark (mark);
    795      1.1  christos }
    796      1.1  christos 
    797      1.1  christos /* Implement Ada val_print'ing for the case where TYPE is
    798      1.1  christos    a TYPE_CODE_PTR.  */
    799      1.1  christos 
    800      1.1  christos static void
    801      1.1  christos ada_val_print_ptr (struct type *type, const gdb_byte *valaddr,
    802      1.1  christos 		   int offset, int offset_aligned, CORE_ADDR address,
    803  1.1.1.5  christos 		   struct ui_file *stream, int recurse,
    804      1.1  christos 		   struct value *original_value,
    805      1.1  christos 		   const struct value_print_options *options,
    806      1.1  christos 		   const struct language_defn *language)
    807  1.1.1.5  christos {
    808      1.1  christos   val_print (type, offset, address, stream, recurse,
    809      1.1  christos 	     original_value, options, language_def (language_c));
    810      1.1  christos 
    811      1.1  christos   if (ada_is_tag_type (type))
    812      1.1  christos     {
    813      1.1  christos       struct value *val =
    814      1.1  christos 	value_from_contents_and_address (type,
    815      1.1  christos 					 valaddr + offset_aligned,
    816      1.1  christos 					 address + offset_aligned);
    817      1.1  christos       const char *name = ada_tag_name (val);
    818      1.1  christos 
    819      1.1  christos       if (name != NULL)
    820      1.1  christos 	fprintf_filtered (stream, " (%s)", name);
    821      1.1  christos     }
    822      1.1  christos }
    823      1.1  christos 
    824      1.1  christos /* Implement Ada val_print'ing for the case where TYPE is
    825      1.1  christos    a TYPE_CODE_INT or TYPE_CODE_RANGE.  */
    826      1.1  christos 
    827      1.1  christos static void
    828      1.1  christos ada_val_print_num (struct type *type, const gdb_byte *valaddr,
    829      1.1  christos 		   int offset, int offset_aligned, CORE_ADDR address,
    830  1.1.1.5  christos 		   struct ui_file *stream, int recurse,
    831      1.1  christos 		   struct value *original_value,
    832      1.1  christos 		   const struct value_print_options *options,
    833      1.1  christos 		   const struct language_defn *language)
    834      1.1  christos {
    835      1.1  christos   if (ada_is_fixed_point_type (type))
    836  1.1.1.6  christos     {
    837  1.1.1.6  christos       struct value *scale = ada_scaling_factor (type);
    838  1.1.1.6  christos       struct value *v = value_from_contents (type, valaddr + offset_aligned);
    839  1.1.1.6  christos       v = value_cast (value_type (scale), v);
    840  1.1.1.6  christos       v = value_binop (v, scale, BINOP_MUL);
    841  1.1.1.6  christos 
    842  1.1.1.6  christos       const char *fmt = TYPE_LENGTH (type) < 4 ? "%.11g" : "%.17g";
    843  1.1.1.6  christos       std::string str
    844  1.1.1.6  christos 	= target_float_to_string (value_contents (v), value_type (v), fmt);
    845      1.1  christos       fputs_filtered (str.c_str (), stream);
    846      1.1  christos       return;
    847      1.1  christos     }
    848      1.1  christos   else if (TYPE_CODE (type) == TYPE_CODE_RANGE)
    849      1.1  christos     {
    850      1.1  christos       struct type *target_type = TYPE_TARGET_TYPE (type);
    851      1.1  christos 
    852      1.1  christos       if (TYPE_LENGTH (type) != TYPE_LENGTH (target_type))
    853      1.1  christos 	{
    854      1.1  christos 	  /* Obscure case of range type that has different length from
    855      1.1  christos 	     its base type.  Perform a conversion, or we will get a
    856      1.1  christos 	     nonsense value.  Actually, we could use the same
    857      1.1  christos 	     code regardless of lengths; I'm just avoiding a cast.  */
    858      1.1  christos 	  struct value *v1
    859      1.1  christos 	    = value_from_contents_and_address (type, valaddr + offset, 0);
    860      1.1  christos 	  struct value *v = value_cast (target_type, v1);
    861  1.1.1.5  christos 
    862      1.1  christos 	  val_print (target_type,
    863      1.1  christos 		     value_embedded_offset (v), 0, stream,
    864      1.1  christos 		     recurse + 1, v, options, language);
    865      1.1  christos 	}
    866  1.1.1.5  christos       else
    867      1.1  christos 	val_print (TYPE_TARGET_TYPE (type), offset,
    868      1.1  christos 		   address, stream, recurse, original_value,
    869      1.1  christos 		   options, language);
    870      1.1  christos       return;
    871      1.1  christos     }
    872      1.1  christos   else
    873      1.1  christos     {
    874      1.1  christos       int format = (options->format ? options->format
    875      1.1  christos 		    : options->output_format);
    876      1.1  christos 
    877      1.1  christos       if (format)
    878      1.1  christos 	{
    879      1.1  christos 	  struct value_print_options opts = *options;
    880      1.1  christos 
    881  1.1.1.5  christos 	  opts.format = format;
    882      1.1  christos 	  val_print_scalar_formatted (type, offset_aligned,
    883      1.1  christos 				      original_value, &opts, 0, stream);
    884      1.1  christos 	}
    885      1.1  christos       else if (ada_is_system_address_type (type))
    886      1.1  christos 	{
    887      1.1  christos 	  /* FIXME: We want to print System.Address variables using
    888      1.1  christos 	     the same format as for any access type.  But for some
    889      1.1  christos 	     reason GNAT encodes the System.Address type as an int,
    890      1.1  christos 	     so we have to work-around this deficiency by handling
    891      1.1  christos 	     System.Address values as a special case.  */
    892      1.1  christos 
    893      1.1  christos 	  struct gdbarch *gdbarch = get_type_arch (type);
    894      1.1  christos 	  struct type *ptr_type = builtin_type (gdbarch)->builtin_data_ptr;
    895      1.1  christos 	  CORE_ADDR addr = extract_typed_address (valaddr + offset_aligned,
    896      1.1  christos 						  ptr_type);
    897      1.1  christos 
    898      1.1  christos 	  fprintf_filtered (stream, "(");
    899      1.1  christos 	  type_print (type, "", stream, -1);
    900      1.1  christos 	  fprintf_filtered (stream, ") ");
    901      1.1  christos 	  fputs_filtered (paddress (gdbarch, addr), stream);
    902      1.1  christos 	}
    903      1.1  christos       else
    904  1.1.1.6  christos 	{
    905  1.1.1.6  christos 	  val_print_scalar_formatted (type, offset_aligned,
    906      1.1  christos 				      original_value, options, 0, stream);
    907      1.1  christos 	  if (ada_is_character_type (type))
    908      1.1  christos 	    {
    909      1.1  christos 	      LONGEST c;
    910      1.1  christos 
    911      1.1  christos 	      fputs_filtered (" ", stream);
    912      1.1  christos 	      c = unpack_long (type, valaddr + offset_aligned);
    913      1.1  christos 	      ada_printchar (c, type, stream);
    914      1.1  christos 	    }
    915      1.1  christos 	}
    916      1.1  christos       return;
    917      1.1  christos     }
    918      1.1  christos }
    919      1.1  christos 
    920      1.1  christos /* Implement Ada val_print'ing for the case where TYPE is
    921      1.1  christos    a TYPE_CODE_ENUM.  */
    922      1.1  christos 
    923      1.1  christos static void
    924      1.1  christos ada_val_print_enum (struct type *type, const gdb_byte *valaddr,
    925      1.1  christos 		    int offset, int offset_aligned, CORE_ADDR address,
    926  1.1.1.5  christos 		    struct ui_file *stream, int recurse,
    927      1.1  christos 		    struct value *original_value,
    928      1.1  christos 		    const struct value_print_options *options,
    929      1.1  christos 		    const struct language_defn *language)
    930      1.1  christos {
    931      1.1  christos   int i;
    932      1.1  christos   unsigned int len;
    933      1.1  christos   LONGEST val;
    934      1.1  christos 
    935      1.1  christos   if (options->format)
    936  1.1.1.5  christos     {
    937      1.1  christos       val_print_scalar_formatted (type, offset_aligned,
    938      1.1  christos 				  original_value, options, 0, stream);
    939      1.1  christos       return;
    940      1.1  christos     }
    941      1.1  christos 
    942      1.1  christos   len = TYPE_NFIELDS (type);
    943      1.1  christos   val = unpack_long (type, valaddr + offset_aligned);
    944      1.1  christos   for (i = 0; i < len; i++)
    945      1.1  christos     {
    946      1.1  christos       QUIT;
    947      1.1  christos       if (val == TYPE_FIELD_ENUMVAL (type, i))
    948      1.1  christos 	break;
    949      1.1  christos     }
    950      1.1  christos 
    951      1.1  christos   if (i < len)
    952      1.1  christos     {
    953      1.1  christos       const char *name = ada_enum_name (TYPE_FIELD_NAME (type, i));
    954      1.1  christos 
    955      1.1  christos       if (name[0] == '\'')
    956      1.1  christos 	fprintf_filtered (stream, "%ld %s", (long) val, name);
    957      1.1  christos       else
    958      1.1  christos 	fputs_filtered (name, stream);
    959      1.1  christos     }
    960      1.1  christos   else
    961      1.1  christos     print_longest (stream, 'd', 0, val);
    962      1.1  christos }
    963      1.1  christos 
    964      1.1  christos /* Implement Ada val_print'ing for the case where TYPE is
    965      1.1  christos    a TYPE_CODE_FLT.  */
    966      1.1  christos 
    967      1.1  christos static void
    968      1.1  christos ada_val_print_flt (struct type *type, const gdb_byte *valaddr,
    969      1.1  christos 		   int offset, int offset_aligned, CORE_ADDR address,
    970  1.1.1.5  christos 		   struct ui_file *stream, int recurse,
    971      1.1  christos 		   struct value *original_value,
    972      1.1  christos 		   const struct value_print_options *options,
    973      1.1  christos 		   const struct language_defn *language)
    974      1.1  christos {
    975      1.1  christos   if (options->format)
    976  1.1.1.5  christos     {
    977      1.1  christos       val_print (type, offset, address, stream, recurse,
    978      1.1  christos 		 original_value, options, language_def (language_c));
    979      1.1  christos       return;
    980      1.1  christos     }
    981      1.1  christos 
    982      1.1  christos   ada_print_floating (valaddr + offset, type, stream);
    983      1.1  christos }
    984      1.1  christos 
    985      1.1  christos /* Implement Ada val_print'ing for the case where TYPE is
    986      1.1  christos    a TYPE_CODE_STRUCT or TYPE_CODE_UNION.  */
    987      1.1  christos 
    988      1.1  christos static void
    989      1.1  christos ada_val_print_struct_union
    990      1.1  christos   (struct type *type, const gdb_byte *valaddr, int offset,
    991  1.1.1.5  christos    int offset_aligned, CORE_ADDR address, struct ui_file *stream,
    992      1.1  christos    int recurse, struct value *original_value,
    993      1.1  christos    const struct value_print_options *options,
    994      1.1  christos    const struct language_defn *language)
    995      1.1  christos {
    996      1.1  christos   if (ada_is_bogus_array_descriptor (type))
    997      1.1  christos     {
    998      1.1  christos       fprintf_filtered (stream, "(...?)");
    999      1.1  christos       return;
   1000      1.1  christos     }
   1001      1.1  christos 
   1002      1.1  christos   fprintf_filtered (stream, "(");
   1003      1.1  christos 
   1004      1.1  christos   if (print_field_values (type, valaddr, offset_aligned,
   1005      1.1  christos 			  stream, recurse, original_value, options,
   1006      1.1  christos 			  0, type, offset_aligned, language) != 0
   1007      1.1  christos       && options->prettyformat)
   1008      1.1  christos     {
   1009      1.1  christos       fprintf_filtered (stream, "\n");
   1010      1.1  christos       print_spaces_filtered (2 * recurse, stream);
   1011      1.1  christos     }
   1012      1.1  christos 
   1013      1.1  christos   fprintf_filtered (stream, ")");
   1014      1.1  christos }
   1015      1.1  christos 
   1016      1.1  christos /* Implement Ada val_print'ing for the case where TYPE is
   1017      1.1  christos    a TYPE_CODE_ARRAY.  */
   1018      1.1  christos 
   1019      1.1  christos static void
   1020      1.1  christos ada_val_print_array (struct type *type, const gdb_byte *valaddr,
   1021      1.1  christos 		     int offset, int offset_aligned, CORE_ADDR address,
   1022  1.1.1.5  christos 		     struct ui_file *stream, int recurse,
   1023      1.1  christos 		     struct value *original_value,
   1024      1.1  christos 		     const struct value_print_options *options)
   1025      1.1  christos {
   1026      1.1  christos   /* For an array of characters, print with string syntax.  */
   1027      1.1  christos   if (ada_is_string_type (type)
   1028      1.1  christos       && (options->format == 0 || options->format == 's'))
   1029      1.1  christos     {
   1030      1.1  christos       ada_val_print_string (type, valaddr, offset, offset_aligned,
   1031      1.1  christos 			    address, stream, recurse, original_value,
   1032      1.1  christos 			    options);
   1033      1.1  christos       return;
   1034      1.1  christos     }
   1035      1.1  christos 
   1036      1.1  christos   fprintf_filtered (stream, "(");
   1037      1.1  christos   print_optional_low_bound (stream, type, options);
   1038      1.1  christos   if (TYPE_FIELD_BITSIZE (type, 0) > 0)
   1039      1.1  christos     val_print_packed_array_elements (type, valaddr, offset_aligned,
   1040      1.1  christos 				     0, stream, recurse,
   1041      1.1  christos 				     original_value, options);
   1042  1.1.1.5  christos   else
   1043      1.1  christos     val_print_array_elements (type, offset_aligned, address,
   1044      1.1  christos 			      stream, recurse, original_value,
   1045      1.1  christos 			      options, 0);
   1046      1.1  christos   fprintf_filtered (stream, ")");
   1047      1.1  christos }
   1048      1.1  christos 
   1049      1.1  christos /* Implement Ada val_print'ing for the case where TYPE is
   1050      1.1  christos    a TYPE_CODE_REF.  */
   1051      1.1  christos 
   1052      1.1  christos static void
   1053      1.1  christos ada_val_print_ref (struct type *type, const gdb_byte *valaddr,
   1054      1.1  christos 		   int offset, int offset_aligned, CORE_ADDR address,
   1055  1.1.1.5  christos 		   struct ui_file *stream, int recurse,
   1056      1.1  christos 		   struct value *original_value,
   1057      1.1  christos 		   const struct value_print_options *options,
   1058      1.1  christos 		   const struct language_defn *language)
   1059      1.1  christos {
   1060      1.1  christos   /* For references, the debugger is expected to print the value as
   1061      1.1  christos      an address if DEREF_REF is null.  But printing an address in place
   1062      1.1  christos      of the object value would be confusing to an Ada programmer.
   1063      1.1  christos      So, for Ada values, we print the actual dereferenced value
   1064      1.1  christos      regardless.  */
   1065      1.1  christos   struct type *elttype = check_typedef (TYPE_TARGET_TYPE (type));
   1066      1.1  christos   struct value *deref_val;
   1067      1.1  christos   CORE_ADDR deref_val_int;
   1068      1.1  christos 
   1069      1.1  christos   if (TYPE_CODE (elttype) == TYPE_CODE_UNDEF)
   1070      1.1  christos     {
   1071      1.1  christos       fputs_filtered ("<ref to undefined type>", stream);
   1072      1.1  christos       return;
   1073      1.1  christos     }
   1074      1.1  christos 
   1075      1.1  christos   deref_val = coerce_ref_if_computed (original_value);
   1076      1.1  christos   if (deref_val)
   1077      1.1  christos     {
   1078      1.1  christos       if (ada_is_tagged_type (value_type (deref_val), 1))
   1079      1.1  christos 	deref_val = ada_tag_value_at_base_address (deref_val);
   1080      1.1  christos 
   1081      1.1  christos       common_val_print (deref_val, stream, recurse + 1, options,
   1082      1.1  christos 			language);
   1083      1.1  christos       return;
   1084      1.1  christos     }
   1085      1.1  christos 
   1086      1.1  christos   deref_val_int = unpack_pointer (type, valaddr + offset_aligned);
   1087      1.1  christos   if (deref_val_int == 0)
   1088      1.1  christos     {
   1089      1.1  christos       fputs_filtered ("(null)", stream);
   1090      1.1  christos       return;
   1091      1.1  christos     }
   1092      1.1  christos 
   1093      1.1  christos   deref_val
   1094      1.1  christos     = ada_value_ind (value_from_pointer (lookup_pointer_type (elttype),
   1095      1.1  christos 					 deref_val_int));
   1096      1.1  christos   if (ada_is_tagged_type (value_type (deref_val), 1))
   1097      1.1  christos     deref_val = ada_tag_value_at_base_address (deref_val);
   1098  1.1.1.2  christos 
   1099  1.1.1.2  christos   /* Make sure that the object does not have an unreasonable size
   1100  1.1.1.2  christos      before trying to print it.  This can happen for instance with
   1101  1.1.1.2  christos      references to dynamic objects whose contents is uninitialized
   1102  1.1.1.2  christos      (Eg: an array whose bounds are not set yet).  */
   1103  1.1.1.2  christos   ada_ensure_varsize_limit (value_type (deref_val));
   1104  1.1.1.5  christos 
   1105  1.1.1.5  christos   if (value_lazy (deref_val))
   1106  1.1.1.5  christos     value_fetch_lazy (deref_val);
   1107      1.1  christos 
   1108      1.1  christos   val_print (value_type (deref_val),
   1109      1.1  christos 	     value_embedded_offset (deref_val),
   1110      1.1  christos 	     value_address (deref_val), stream, recurse + 1,
   1111      1.1  christos 	     deref_val, options, language);
   1112      1.1  christos }
   1113      1.1  christos 
   1114      1.1  christos /* See the comment on ada_val_print.  This function differs in that it
   1115      1.1  christos    does not catch evaluation errors (leaving that to ada_val_print).  */
   1116      1.1  christos 
   1117  1.1.1.5  christos static void
   1118      1.1  christos ada_val_print_1 (struct type *type,
   1119      1.1  christos 		 int offset, CORE_ADDR address,
   1120  1.1.1.5  christos 		 struct ui_file *stream, int recurse,
   1121      1.1  christos 		 struct value *original_value,
   1122      1.1  christos 		 const struct value_print_options *options,
   1123      1.1  christos 		 const struct language_defn *language)
   1124      1.1  christos {
   1125  1.1.1.5  christos   int offset_aligned;
   1126      1.1  christos   const gdb_byte *valaddr = value_contents_for_printing (original_value);
   1127      1.1  christos 
   1128      1.1  christos   type = ada_check_typedef (type);
   1129      1.1  christos 
   1130      1.1  christos   if (ada_is_array_descriptor_type (type)
   1131      1.1  christos       || (ada_is_constrained_packed_array_type (type)
   1132      1.1  christos 	  && TYPE_CODE (type) != TYPE_CODE_PTR))
   1133      1.1  christos     {
   1134      1.1  christos       ada_val_print_gnat_array (type, valaddr, offset, address,
   1135      1.1  christos 				stream, recurse, original_value,
   1136      1.1  christos 				options, language);
   1137      1.1  christos       return;
   1138      1.1  christos     }
   1139      1.1  christos 
   1140      1.1  christos   offset_aligned = offset + ada_aligned_value_addr (type, valaddr) - valaddr;
   1141  1.1.1.3  christos   type = printable_val_type (type, valaddr + offset_aligned);
   1142  1.1.1.3  christos   type = resolve_dynamic_type (type, valaddr + offset_aligned,
   1143      1.1  christos 			       address + offset_aligned);
   1144      1.1  christos 
   1145      1.1  christos   switch (TYPE_CODE (type))
   1146      1.1  christos     {
   1147  1.1.1.5  christos     default:
   1148      1.1  christos       val_print (type, offset, address, stream, recurse,
   1149      1.1  christos 		 original_value, options, language_def (language_c));
   1150      1.1  christos       break;
   1151      1.1  christos 
   1152      1.1  christos     case TYPE_CODE_PTR:
   1153      1.1  christos       ada_val_print_ptr (type, valaddr, offset, offset_aligned,
   1154      1.1  christos 			 address, stream, recurse, original_value,
   1155      1.1  christos 			 options, language);
   1156      1.1  christos       break;
   1157      1.1  christos 
   1158      1.1  christos     case TYPE_CODE_INT:
   1159      1.1  christos     case TYPE_CODE_RANGE:
   1160      1.1  christos       ada_val_print_num (type, valaddr, offset, offset_aligned,
   1161      1.1  christos 			 address, stream, recurse, original_value,
   1162      1.1  christos 			 options, language);
   1163      1.1  christos       break;
   1164      1.1  christos 
   1165      1.1  christos     case TYPE_CODE_ENUM:
   1166      1.1  christos       ada_val_print_enum (type, valaddr, offset, offset_aligned,
   1167      1.1  christos 			  address, stream, recurse, original_value,
   1168      1.1  christos 			  options, language);
   1169      1.1  christos       break;
   1170      1.1  christos 
   1171      1.1  christos     case TYPE_CODE_FLT:
   1172      1.1  christos       ada_val_print_flt (type, valaddr, offset, offset_aligned,
   1173      1.1  christos 			 address, stream, recurse, original_value,
   1174      1.1  christos 			 options, language);
   1175      1.1  christos       break;
   1176      1.1  christos 
   1177      1.1  christos     case TYPE_CODE_UNION:
   1178      1.1  christos     case TYPE_CODE_STRUCT:
   1179      1.1  christos       ada_val_print_struct_union (type, valaddr, offset, offset_aligned,
   1180      1.1  christos 				  address, stream, recurse,
   1181      1.1  christos 				  original_value, options, language);
   1182      1.1  christos       break;
   1183      1.1  christos 
   1184      1.1  christos     case TYPE_CODE_ARRAY:
   1185      1.1  christos       ada_val_print_array (type, valaddr, offset, offset_aligned,
   1186      1.1  christos 			   address, stream, recurse, original_value,
   1187      1.1  christos 			   options);
   1188      1.1  christos       return;
   1189      1.1  christos 
   1190      1.1  christos     case TYPE_CODE_REF:
   1191      1.1  christos       ada_val_print_ref (type, valaddr, offset, offset_aligned,
   1192      1.1  christos 			 address, stream, recurse, original_value,
   1193      1.1  christos 			 options, language);
   1194      1.1  christos       break;
   1195      1.1  christos     }
   1196      1.1  christos }
   1197      1.1  christos 
   1198      1.1  christos /* See val_print for a description of the various parameters of this
   1199      1.1  christos    function; they are identical.  */
   1200      1.1  christos 
   1201  1.1.1.5  christos void
   1202      1.1  christos ada_val_print (struct type *type,
   1203      1.1  christos 	       int embedded_offset, CORE_ADDR address,
   1204  1.1.1.5  christos 	       struct ui_file *stream, int recurse,
   1205      1.1  christos 	       struct value *val,
   1206      1.1  christos 	       const struct value_print_options *options)
   1207  1.1.1.3  christos {
   1208      1.1  christos   TRY
   1209  1.1.1.5  christos     {
   1210      1.1  christos       ada_val_print_1 (type, embedded_offset, address,
   1211      1.1  christos 		       stream, recurse, val, options,
   1212      1.1  christos 		       current_language);
   1213  1.1.1.6  christos     }
   1214  1.1.1.3  christos   CATCH (except, RETURN_MASK_ERROR)
   1215  1.1.1.6  christos     {
   1216  1.1.1.6  christos       fprintf_filtered (stream, _("<error reading variable: %s>"),
   1217  1.1.1.3  christos 			except.message);
   1218  1.1.1.3  christos     }
   1219      1.1  christos   END_CATCH
   1220      1.1  christos }
   1221      1.1  christos 
   1222      1.1  christos void
   1223      1.1  christos ada_value_print (struct value *val0, struct ui_file *stream,
   1224      1.1  christos 		 const struct value_print_options *options)
   1225      1.1  christos {
   1226      1.1  christos   struct value *val = ada_to_fixed_value (val0);
   1227  1.1.1.6  christos   CORE_ADDR address = value_address (val);
   1228      1.1  christos   struct type *type = ada_check_typedef (value_type (val));
   1229      1.1  christos   struct value_print_options opts;
   1230      1.1  christos 
   1231      1.1  christos   /* If it is a pointer, indicate what it points to.  */
   1232      1.1  christos   if (TYPE_CODE (type) == TYPE_CODE_PTR)
   1233      1.1  christos     {
   1234      1.1  christos       /* Hack:  don't print (char *) for char strings.  Their
   1235      1.1  christos          type is indicated by the quoted string anyway.  */
   1236      1.1  christos       if (TYPE_LENGTH (TYPE_TARGET_TYPE (type)) != sizeof (char)
   1237      1.1  christos 	  || TYPE_CODE (TYPE_TARGET_TYPE (type)) != TYPE_CODE_INT
   1238      1.1  christos 	  || TYPE_UNSIGNED (TYPE_TARGET_TYPE (type)))
   1239      1.1  christos 	{
   1240      1.1  christos 	  fprintf_filtered (stream, "(");
   1241      1.1  christos 	  type_print (type, "", stream, -1);
   1242      1.1  christos 	  fprintf_filtered (stream, ") ");
   1243      1.1  christos 	}
   1244      1.1  christos     }
   1245      1.1  christos   else if (ada_is_array_descriptor_type (type))
   1246      1.1  christos     {
   1247      1.1  christos       /* We do not print the type description unless TYPE is an array
   1248      1.1  christos 	 access type (this is encoded by the compiler as a typedef to
   1249      1.1  christos 	 a fat pointer - hence the check against TYPE_CODE_TYPEDEF).  */
   1250      1.1  christos       if (TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
   1251      1.1  christos         {
   1252      1.1  christos 	  fprintf_filtered (stream, "(");
   1253      1.1  christos 	  type_print (type, "", stream, -1);
   1254      1.1  christos 	  fprintf_filtered (stream, ") ");
   1255      1.1  christos 	}
   1256      1.1  christos     }
   1257      1.1  christos   else if (ada_is_bogus_array_descriptor (type))
   1258      1.1  christos     {
   1259      1.1  christos       fprintf_filtered (stream, "(");
   1260      1.1  christos       type_print (type, "", stream, -1);
   1261      1.1  christos       fprintf_filtered (stream, ") (...?)");
   1262      1.1  christos       return;
   1263      1.1  christos     }
   1264      1.1  christos 
   1265      1.1  christos   opts = *options;
   1266  1.1.1.5  christos   opts.deref_ref = 1;
   1267      1.1  christos   val_print (type,
   1268      1.1  christos 	     value_embedded_offset (val), address,
   1269      1.1  christos 	     stream, 0, val, &opts, current_language);
   1270                    }
   1271