Home | History | Annotate | Line # | Download | only in gdb
c-valprint.c revision 1.1.1.1
      1  1.1  christos /* Support for printing C values for GDB, the GNU debugger.
      2  1.1  christos 
      3  1.1  christos    Copyright (C) 1986-2014 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 <string.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 "valprint.h"
     27  1.1  christos #include "language.h"
     28  1.1  christos #include "c-lang.h"
     29  1.1  christos #include "cp-abi.h"
     30  1.1  christos #include "target.h"
     31  1.1  christos 
     32  1.1  christos 
     34  1.1  christos /* A helper for c_textual_element_type.  This checks the name of the
     35  1.1  christos    typedef.  This is bogus but it isn't apparent that the compiler
     36  1.1  christos    provides us the help we may need.  */
     37  1.1  christos 
     38  1.1  christos static int
     39  1.1  christos textual_name (const char *name)
     40  1.1  christos {
     41  1.1  christos   return (!strcmp (name, "wchar_t")
     42  1.1  christos 	  || !strcmp (name, "char16_t")
     43  1.1  christos 	  || !strcmp (name, "char32_t"));
     44  1.1  christos }
     45  1.1  christos 
     46  1.1  christos /* Apply a heuristic to decide whether an array of TYPE or a pointer
     47  1.1  christos    to TYPE should be printed as a textual string.  Return non-zero if
     48  1.1  christos    it should, or zero if it should be treated as an array of integers
     49  1.1  christos    or pointer to integers.  FORMAT is the current format letter, or 0
     50  1.1  christos    if none.
     51  1.1  christos 
     52  1.1  christos    We guess that "char" is a character.  Explicitly signed and
     53  1.1  christos    unsigned character types are also characters.  Integer data from
     54  1.1  christos    vector types is not.  The user can override this by using the /s
     55  1.1  christos    format letter.  */
     56  1.1  christos 
     57  1.1  christos int
     58  1.1  christos c_textual_element_type (struct type *type, char format)
     59  1.1  christos {
     60  1.1  christos   struct type *true_type, *iter_type;
     61  1.1  christos 
     62  1.1  christos   if (format != 0 && format != 's')
     63  1.1  christos     return 0;
     64  1.1  christos 
     65  1.1  christos   /* We also rely on this for its side effect of setting up all the
     66  1.1  christos      typedef pointers.  */
     67  1.1  christos   true_type = check_typedef (type);
     68  1.1  christos 
     69  1.1  christos   /* TYPE_CODE_CHAR is always textual.  */
     70  1.1  christos   if (TYPE_CODE (true_type) == TYPE_CODE_CHAR)
     71  1.1  christos     return 1;
     72  1.1  christos 
     73  1.1  christos   /* Any other character-like types must be integral.  */
     74  1.1  christos   if (TYPE_CODE (true_type) != TYPE_CODE_INT)
     75  1.1  christos     return 0;
     76  1.1  christos 
     77  1.1  christos   /* We peel typedefs one by one, looking for a match.  */
     78  1.1  christos   iter_type = type;
     79  1.1  christos   while (iter_type)
     80  1.1  christos     {
     81  1.1  christos       /* Check the name of the type.  */
     82  1.1  christos       if (TYPE_NAME (iter_type) && textual_name (TYPE_NAME (iter_type)))
     83  1.1  christos 	return 1;
     84  1.1  christos 
     85  1.1  christos       if (TYPE_CODE (iter_type) != TYPE_CODE_TYPEDEF)
     86  1.1  christos 	break;
     87  1.1  christos 
     88  1.1  christos       /* Peel a single typedef.  If the typedef doesn't have a target
     89  1.1  christos 	 type, we use check_typedef and hope the result is ok -- it
     90  1.1  christos 	 might be for C++, where wchar_t is a built-in type.  */
     91  1.1  christos       if (TYPE_TARGET_TYPE (iter_type))
     92  1.1  christos 	iter_type = TYPE_TARGET_TYPE (iter_type);
     93  1.1  christos       else
     94  1.1  christos 	iter_type = check_typedef (iter_type);
     95  1.1  christos     }
     96  1.1  christos 
     97  1.1  christos   if (format == 's')
     98  1.1  christos     {
     99  1.1  christos       /* Print this as a string if we can manage it.  For now, no wide
    100  1.1  christos 	 character support.  */
    101  1.1  christos       if (TYPE_CODE (true_type) == TYPE_CODE_INT
    102  1.1  christos 	  && TYPE_LENGTH (true_type) == 1)
    103  1.1  christos 	return 1;
    104  1.1  christos     }
    105  1.1  christos   else
    106  1.1  christos     {
    107  1.1  christos       /* If a one-byte TYPE_CODE_INT is missing the not-a-character
    108  1.1  christos 	 flag, then we treat it as text; otherwise, we assume it's
    109  1.1  christos 	 being used as data.  */
    110  1.1  christos       if (TYPE_CODE (true_type) == TYPE_CODE_INT
    111  1.1  christos 	  && TYPE_LENGTH (true_type) == 1
    112  1.1  christos 	  && !TYPE_NOTTEXT (true_type))
    113  1.1  christos 	return 1;
    114  1.1  christos     }
    115  1.1  christos 
    116  1.1  christos   return 0;
    117  1.1  christos }
    118  1.1  christos 
    119  1.1  christos /* Decorations for C.  */
    120  1.1  christos 
    121  1.1  christos static const struct generic_val_print_decorations c_decorations =
    122  1.1  christos {
    123  1.1  christos   "",
    124  1.1  christos   " + ",
    125  1.1  christos   " * I",
    126  1.1  christos   "true",
    127  1.1  christos   "false",
    128  1.1  christos   "void"
    129  1.1  christos };
    130  1.1  christos 
    131  1.1  christos /* See val_print for a description of the various parameters of this
    132  1.1  christos    function; they are identical.  */
    133  1.1  christos 
    134  1.1  christos void
    135  1.1  christos c_val_print (struct type *type, const gdb_byte *valaddr,
    136  1.1  christos 	     int embedded_offset, CORE_ADDR address,
    137  1.1  christos 	     struct ui_file *stream, int recurse,
    138  1.1  christos 	     const struct value *original_value,
    139  1.1  christos 	     const struct value_print_options *options)
    140  1.1  christos {
    141  1.1  christos   struct gdbarch *gdbarch = get_type_arch (type);
    142  1.1  christos   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
    143  1.1  christos   unsigned int i = 0;	/* Number of characters printed.  */
    144  1.1  christos   unsigned len;
    145  1.1  christos   struct type *elttype, *unresolved_elttype;
    146  1.1  christos   struct type *unresolved_type = type;
    147  1.1  christos   unsigned eltlen;
    148  1.1  christos   CORE_ADDR addr;
    149  1.1  christos 
    150  1.1  christos   CHECK_TYPEDEF (type);
    151  1.1  christos   switch (TYPE_CODE (type))
    152  1.1  christos     {
    153  1.1  christos     case TYPE_CODE_ARRAY:
    154  1.1  christos       unresolved_elttype = TYPE_TARGET_TYPE (type);
    155  1.1  christos       elttype = check_typedef (unresolved_elttype);
    156  1.1  christos       if (TYPE_LENGTH (type) > 0 && TYPE_LENGTH (unresolved_elttype) > 0)
    157  1.1  christos 	{
    158  1.1  christos           LONGEST low_bound, high_bound;
    159  1.1  christos 
    160  1.1  christos           if (!get_array_bounds (type, &low_bound, &high_bound))
    161  1.1  christos             error (_("Could not determine the array high bound"));
    162  1.1  christos 
    163  1.1  christos 	  eltlen = TYPE_LENGTH (elttype);
    164  1.1  christos 	  len = high_bound - low_bound + 1;
    165  1.1  christos 	  if (options->prettyformat_arrays)
    166  1.1  christos 	    {
    167  1.1  christos 	      print_spaces_filtered (2 + 2 * recurse, stream);
    168  1.1  christos 	    }
    169  1.1  christos 
    170  1.1  christos 	  /* Print arrays of textual chars with a string syntax, as
    171  1.1  christos 	     long as the entire array is valid.  */
    172  1.1  christos           if (c_textual_element_type (unresolved_elttype,
    173  1.1  christos 				      options->format)
    174  1.1  christos 	      && value_bytes_available (original_value, embedded_offset,
    175  1.1  christos 					TYPE_LENGTH (type))
    176  1.1  christos 	      && value_bits_valid (original_value,
    177  1.1  christos 				   TARGET_CHAR_BIT * embedded_offset,
    178  1.1  christos 				   TARGET_CHAR_BIT * TYPE_LENGTH (type)))
    179  1.1  christos 	    {
    180  1.1  christos 	      int force_ellipses = 0;
    181  1.1  christos 
    182  1.1  christos 	      /* If requested, look for the first null char and only
    183  1.1  christos 	         print elements up to it.  */
    184  1.1  christos 	      if (options->stop_print_at_null)
    185  1.1  christos 		{
    186  1.1  christos 		  unsigned int temp_len;
    187  1.1  christos 
    188  1.1  christos 		  for (temp_len = 0;
    189  1.1  christos 		       (temp_len < len
    190  1.1  christos 			&& temp_len < options->print_max
    191  1.1  christos 			&& extract_unsigned_integer (valaddr + embedded_offset
    192  1.1  christos 						     + temp_len * eltlen,
    193  1.1  christos 						     eltlen, byte_order) != 0);
    194  1.1  christos 		       ++temp_len)
    195  1.1  christos 		    ;
    196  1.1  christos 
    197  1.1  christos 		  /* Force LA_PRINT_STRING to print ellipses if
    198  1.1  christos 		     we've printed the maximum characters and
    199  1.1  christos 		     the next character is not \000.  */
    200  1.1  christos 		  if (temp_len == options->print_max && temp_len < len)
    201  1.1  christos 		    {
    202  1.1  christos 		      ULONGEST val
    203  1.1  christos 			= extract_unsigned_integer (valaddr + embedded_offset
    204  1.1  christos 						    + temp_len * eltlen,
    205  1.1  christos 						    eltlen, byte_order);
    206  1.1  christos 		      if (val != 0)
    207  1.1  christos 			force_ellipses = 1;
    208  1.1  christos 		    }
    209  1.1  christos 
    210  1.1  christos 		  len = temp_len;
    211  1.1  christos 		}
    212  1.1  christos 
    213  1.1  christos 	      LA_PRINT_STRING (stream, unresolved_elttype,
    214  1.1  christos 			       valaddr + embedded_offset, len,
    215  1.1  christos 			       NULL, force_ellipses, options);
    216  1.1  christos 	      i = len;
    217  1.1  christos 	    }
    218  1.1  christos 	  else
    219  1.1  christos 	    {
    220  1.1  christos 	      fprintf_filtered (stream, "{");
    221  1.1  christos 	      /* If this is a virtual function table, print the 0th
    222  1.1  christos 	         entry specially, and the rest of the members
    223  1.1  christos 	         normally.  */
    224  1.1  christos 	      if (cp_is_vtbl_ptr_type (elttype))
    225  1.1  christos 		{
    226  1.1  christos 		  i = 1;
    227  1.1  christos 		  fprintf_filtered (stream, _("%d vtable entries"),
    228  1.1  christos 				    len - 1);
    229  1.1  christos 		}
    230  1.1  christos 	      else
    231  1.1  christos 		{
    232  1.1  christos 		  i = 0;
    233  1.1  christos 		}
    234  1.1  christos 	      val_print_array_elements (type, valaddr, embedded_offset,
    235  1.1  christos 					address, stream,
    236  1.1  christos 					recurse, original_value, options, i);
    237  1.1  christos 	      fprintf_filtered (stream, "}");
    238  1.1  christos 	    }
    239  1.1  christos 	  break;
    240  1.1  christos 	}
    241  1.1  christos       /* Array of unspecified length: treat like pointer to first
    242  1.1  christos 	 elt.  */
    243  1.1  christos       addr = address + embedded_offset;
    244  1.1  christos       goto print_unpacked_pointer;
    245  1.1  christos 
    246  1.1  christos     case TYPE_CODE_METHODPTR:
    247  1.1  christos       cplus_print_method_ptr (valaddr + embedded_offset, type, stream);
    248  1.1  christos       break;
    249  1.1  christos 
    250  1.1  christos     case TYPE_CODE_PTR:
    251  1.1  christos       if (options->format && options->format != 's')
    252  1.1  christos 	{
    253  1.1  christos 	  val_print_scalar_formatted (type, valaddr, embedded_offset,
    254  1.1  christos 				      original_value, options, 0, stream);
    255  1.1  christos 	  break;
    256  1.1  christos 	}
    257  1.1  christos       if (options->vtblprint && cp_is_vtbl_ptr_type (type))
    258  1.1  christos 	{
    259  1.1  christos 	  /* Print the unmangled name if desired.  */
    260  1.1  christos 	  /* Print vtable entry - we only get here if we ARE using
    261  1.1  christos 	     -fvtable_thunks.  (Otherwise, look under
    262  1.1  christos 	     TYPE_CODE_STRUCT.)  */
    263  1.1  christos 	  CORE_ADDR addr
    264  1.1  christos 	    = extract_typed_address (valaddr + embedded_offset, type);
    265  1.1  christos 
    266  1.1  christos 	  print_function_pointer_address (options, gdbarch, addr, stream);
    267  1.1  christos 	  break;
    268  1.1  christos 	}
    269  1.1  christos       unresolved_elttype = TYPE_TARGET_TYPE (type);
    270  1.1  christos       elttype = check_typedef (unresolved_elttype);
    271  1.1  christos 	{
    272  1.1  christos 	  int want_space;
    273  1.1  christos 
    274  1.1  christos 	  addr = unpack_pointer (type, valaddr + embedded_offset);
    275  1.1  christos 	print_unpacked_pointer:
    276  1.1  christos 
    277  1.1  christos 	  want_space = 0;
    278  1.1  christos 
    279  1.1  christos 	  if (TYPE_CODE (elttype) == TYPE_CODE_FUNC)
    280  1.1  christos 	    {
    281  1.1  christos 	      /* Try to print what function it points to.  */
    282  1.1  christos 	      print_function_pointer_address (options, gdbarch, addr, stream);
    283  1.1  christos 	      return;
    284  1.1  christos 	    }
    285  1.1  christos 
    286  1.1  christos 	  if (options->symbol_print)
    287  1.1  christos 	    want_space = print_address_demangle (options, gdbarch, addr,
    288  1.1  christos 						 stream, demangle);
    289  1.1  christos 	  else if (options->addressprint)
    290  1.1  christos 	    {
    291  1.1  christos 	      fputs_filtered (paddress (gdbarch, addr), stream);
    292  1.1  christos 	      want_space = 1;
    293  1.1  christos 	    }
    294  1.1  christos 
    295  1.1  christos 	  /* For a pointer to a textual type, also print the string
    296  1.1  christos 	     pointed to, unless pointer is null.  */
    297  1.1  christos 
    298  1.1  christos 	  if (c_textual_element_type (unresolved_elttype,
    299  1.1  christos 				      options->format)
    300  1.1  christos 	      && addr != 0)
    301  1.1  christos 	    {
    302  1.1  christos 	      if (want_space)
    303  1.1  christos 		fputs_filtered (" ", stream);
    304  1.1  christos 	      i = val_print_string (unresolved_elttype, NULL,
    305  1.1  christos 				    addr, -1,
    306  1.1  christos 				    stream, options);
    307  1.1  christos 	    }
    308  1.1  christos 	  else if (cp_is_vtbl_member (type))
    309  1.1  christos 	    {
    310  1.1  christos 	      /* Print vtbl's nicely.  */
    311  1.1  christos 	      CORE_ADDR vt_address = unpack_pointer (type,
    312  1.1  christos 						     valaddr
    313  1.1  christos 						     + embedded_offset);
    314  1.1  christos 	      struct bound_minimal_symbol msymbol =
    315  1.1  christos 		lookup_minimal_symbol_by_pc (vt_address);
    316  1.1  christos 
    317  1.1  christos 	      /* If 'symbol_print' is set, we did the work above.  */
    318  1.1  christos 	      if (!options->symbol_print
    319  1.1  christos 		  && (msymbol.minsym != NULL)
    320  1.1  christos 		  && (vt_address == SYMBOL_VALUE_ADDRESS (msymbol.minsym)))
    321  1.1  christos 		{
    322  1.1  christos 		  if (want_space)
    323  1.1  christos 		    fputs_filtered (" ", stream);
    324  1.1  christos 		  fputs_filtered (" <", stream);
    325  1.1  christos 		  fputs_filtered (SYMBOL_PRINT_NAME (msymbol.minsym), stream);
    326  1.1  christos 		  fputs_filtered (">", stream);
    327  1.1  christos 		  want_space = 1;
    328  1.1  christos 		}
    329  1.1  christos 
    330  1.1  christos 	      if (vt_address && options->vtblprint)
    331  1.1  christos 		{
    332  1.1  christos 		  struct value *vt_val;
    333  1.1  christos 		  struct symbol *wsym = (struct symbol *) NULL;
    334  1.1  christos 		  struct type *wtype;
    335  1.1  christos 		  struct block *block = (struct block *) NULL;
    336  1.1  christos 		  struct field_of_this_result is_this_fld;
    337  1.1  christos 
    338  1.1  christos 		  if (want_space)
    339  1.1  christos 		    fputs_filtered (" ", stream);
    340  1.1  christos 
    341  1.1  christos 		  if (msymbol.minsym != NULL)
    342  1.1  christos 		    wsym = lookup_symbol (SYMBOL_LINKAGE_NAME (msymbol.minsym),
    343  1.1  christos 					  block, VAR_DOMAIN,
    344  1.1  christos 					  &is_this_fld);
    345  1.1  christos 
    346  1.1  christos 		  if (wsym)
    347  1.1  christos 		    {
    348  1.1  christos 		      wtype = SYMBOL_TYPE (wsym);
    349  1.1  christos 		    }
    350  1.1  christos 		  else
    351  1.1  christos 		    {
    352  1.1  christos 		      wtype = unresolved_elttype;
    353  1.1  christos 		    }
    354  1.1  christos 		  vt_val = value_at (wtype, vt_address);
    355  1.1  christos 		  common_val_print (vt_val, stream, recurse + 1,
    356  1.1  christos 				    options, current_language);
    357  1.1  christos 		  if (options->prettyformat)
    358  1.1  christos 		    {
    359  1.1  christos 		      fprintf_filtered (stream, "\n");
    360  1.1  christos 		      print_spaces_filtered (2 + 2 * recurse, stream);
    361  1.1  christos 		    }
    362  1.1  christos 		}
    363  1.1  christos 	    }
    364  1.1  christos 	  return;
    365  1.1  christos 	}
    366  1.1  christos       break;
    367  1.1  christos 
    368  1.1  christos     case TYPE_CODE_UNION:
    369  1.1  christos       if (recurse && !options->unionprint)
    370  1.1  christos 	{
    371  1.1  christos 	  fprintf_filtered (stream, "{...}");
    372  1.1  christos 	  break;
    373  1.1  christos 	}
    374  1.1  christos       /* Fall through.  */
    375  1.1  christos     case TYPE_CODE_STRUCT:
    376  1.1  christos       /*FIXME: Abstract this away.  */
    377  1.1  christos       if (options->vtblprint && cp_is_vtbl_ptr_type (type))
    378  1.1  christos 	{
    379  1.1  christos 	  /* Print the unmangled name if desired.  */
    380  1.1  christos 	  /* Print vtable entry - we only get here if NOT using
    381  1.1  christos 	     -fvtable_thunks.  (Otherwise, look under
    382  1.1  christos 	     TYPE_CODE_PTR.)  */
    383  1.1  christos 	  int offset = (embedded_offset
    384  1.1  christos 			+ TYPE_FIELD_BITPOS (type,
    385  1.1  christos 					     VTBL_FNADDR_OFFSET) / 8);
    386  1.1  christos 	  struct type *field_type = TYPE_FIELD_TYPE (type,
    387  1.1  christos 						     VTBL_FNADDR_OFFSET);
    388  1.1  christos 	  CORE_ADDR addr
    389  1.1  christos 	    = extract_typed_address (valaddr + offset, field_type);
    390  1.1  christos 
    391  1.1  christos 	  print_function_pointer_address (options, gdbarch, addr, stream);
    392  1.1  christos 	}
    393  1.1  christos       else
    394  1.1  christos 	cp_print_value_fields_rtti (type, valaddr,
    395  1.1  christos 				    embedded_offset, address,
    396  1.1  christos 				    stream, recurse,
    397  1.1  christos 				    original_value, options,
    398  1.1  christos 				    NULL, 0);
    399  1.1  christos       break;
    400  1.1  christos 
    401  1.1  christos     case TYPE_CODE_INT:
    402  1.1  christos       if (options->format || options->output_format)
    403  1.1  christos 	{
    404  1.1  christos 	  struct value_print_options opts = *options;
    405  1.1  christos 
    406  1.1  christos 	  opts.format = (options->format ? options->format
    407  1.1  christos 			 : options->output_format);
    408  1.1  christos 	  val_print_scalar_formatted (type, valaddr, embedded_offset,
    409  1.1  christos 				      original_value, &opts, 0, stream);
    410  1.1  christos 	}
    411  1.1  christos       else
    412  1.1  christos 	{
    413  1.1  christos 	  val_print_type_code_int (type, valaddr + embedded_offset,
    414  1.1  christos 				   stream);
    415  1.1  christos 	  /* C and C++ has no single byte int type, char is used
    416  1.1  christos 	     instead.  Since we don't know whether the value is really
    417  1.1  christos 	     intended to be used as an integer or a character, print
    418  1.1  christos 	     the character equivalent as well.  */
    419  1.1  christos 	  if (c_textual_element_type (unresolved_type, options->format))
    420  1.1  christos 	    {
    421  1.1  christos 	      fputs_filtered (" ", stream);
    422  1.1  christos 	      LA_PRINT_CHAR (unpack_long (type, valaddr + embedded_offset),
    423  1.1  christos 			     unresolved_type, stream);
    424  1.1  christos 	    }
    425  1.1  christos 	}
    426  1.1  christos       break;
    427  1.1  christos 
    428  1.1  christos     case TYPE_CODE_MEMBERPTR:
    429  1.1  christos       if (!options->format)
    430  1.1  christos 	{
    431  1.1  christos 	  cp_print_class_member (valaddr + embedded_offset, type, stream, "&");
    432  1.1  christos 	  break;
    433  1.1  christos 	}
    434  1.1  christos       /* FALLTHROUGH */
    435  1.1  christos 
    436  1.1  christos     case TYPE_CODE_REF:
    437  1.1  christos     case TYPE_CODE_ENUM:
    438  1.1  christos     case TYPE_CODE_FLAGS:
    439  1.1  christos     case TYPE_CODE_FUNC:
    440  1.1  christos     case TYPE_CODE_METHOD:
    441  1.1  christos     case TYPE_CODE_BOOL:
    442  1.1  christos     case TYPE_CODE_RANGE:
    443  1.1  christos     case TYPE_CODE_FLT:
    444  1.1  christos     case TYPE_CODE_DECFLOAT:
    445  1.1  christos     case TYPE_CODE_VOID:
    446  1.1  christos     case TYPE_CODE_ERROR:
    447  1.1  christos     case TYPE_CODE_UNDEF:
    448  1.1  christos     case TYPE_CODE_COMPLEX:
    449  1.1  christos     case TYPE_CODE_CHAR:
    450  1.1  christos     default:
    451  1.1  christos       generic_val_print (type, valaddr, embedded_offset, address,
    452  1.1  christos 			 stream, recurse, original_value, options,
    453  1.1  christos 			 &c_decorations);
    454  1.1  christos       break;
    455  1.1  christos     }
    456  1.1  christos   gdb_flush (stream);
    457  1.1  christos }
    458  1.1  christos 
    459  1.1  christos void
    461  1.1  christos c_value_print (struct value *val, struct ui_file *stream,
    462  1.1  christos 	       const struct value_print_options *options)
    463  1.1  christos {
    464  1.1  christos   struct type *type, *real_type, *val_type;
    465  1.1  christos   int full, top, using_enc;
    466  1.1  christos   struct value_print_options opts = *options;
    467  1.1  christos 
    468  1.1  christos   opts.deref_ref = 1;
    469  1.1  christos 
    470  1.1  christos   /* If it is a pointer, indicate what it points to.
    471  1.1  christos 
    472  1.1  christos      Print type also if it is a reference.
    473  1.1  christos 
    474  1.1  christos      C++: if it is a member pointer, we will take care
    475  1.1  christos      of that when we print it.  */
    476  1.1  christos 
    477  1.1  christos   /* Preserve the original type before stripping typedefs.  We prefer
    478  1.1  christos      to pass down the original type when possible, but for local
    479  1.1  christos      checks it is better to look past the typedefs.  */
    480  1.1  christos   val_type = value_type (val);
    481  1.1  christos   type = check_typedef (val_type);
    482  1.1  christos 
    483  1.1  christos   if (TYPE_CODE (type) == TYPE_CODE_PTR
    484  1.1  christos       || TYPE_CODE (type) == TYPE_CODE_REF)
    485  1.1  christos     {
    486  1.1  christos       /* Hack:  remove (char *) for char strings.  Their
    487  1.1  christos          type is indicated by the quoted string anyway.
    488  1.1  christos          (Don't use c_textual_element_type here; quoted strings
    489  1.1  christos          are always exactly (char *), (wchar_t *), or the like.  */
    490  1.1  christos       if (TYPE_CODE (val_type) == TYPE_CODE_PTR
    491  1.1  christos 	  && TYPE_NAME (val_type) == NULL
    492  1.1  christos 	  && TYPE_NAME (TYPE_TARGET_TYPE (val_type)) != NULL
    493  1.1  christos 	  && (strcmp (TYPE_NAME (TYPE_TARGET_TYPE (val_type)),
    494  1.1  christos 		      "char") == 0
    495  1.1  christos 	      || textual_name (TYPE_NAME (TYPE_TARGET_TYPE (val_type)))))
    496  1.1  christos 	{
    497  1.1  christos 	  /* Print nothing.  */
    498  1.1  christos 	}
    499  1.1  christos       else if (options->objectprint
    500  1.1  christos 	       && (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_CLASS))
    501  1.1  christos 	{
    502  1.1  christos 	  int is_ref = TYPE_CODE (type) == TYPE_CODE_REF;
    503  1.1  christos 
    504  1.1  christos 	  if (is_ref)
    505  1.1  christos 	    val = value_addr (val);
    506  1.1  christos 
    507  1.1  christos 	  /* Pointer to class, check real type of object.  */
    508  1.1  christos 	  fprintf_filtered (stream, "(");
    509  1.1  christos 
    510  1.1  christos 	  if (value_entirely_available (val))
    511  1.1  christos  	    {
    512  1.1  christos 	      real_type = value_rtti_indirect_type (val, &full, &top,
    513  1.1  christos 						    &using_enc);
    514  1.1  christos 	      if (real_type)
    515  1.1  christos 		{
    516  1.1  christos 		  /* RTTI entry found.  */
    517  1.1  christos 		  type = real_type;
    518  1.1  christos 
    519  1.1  christos 		  /* Need to adjust pointer value.  */
    520  1.1  christos 		  val = value_from_pointer (real_type,
    521  1.1  christos 					    value_as_address (val) - top);
    522  1.1  christos 
    523  1.1  christos 		  if (is_ref)
    524  1.1  christos 		    {
    525  1.1  christos 		      val = value_ref (value_ind (val));
    526  1.1  christos 		      type = value_type (val);
    527  1.1  christos 		    }
    528  1.1  christos 
    529  1.1  christos 		  /* Note: When we look up RTTI entries, we don't get
    530  1.1  christos 		     any information on const or volatile
    531  1.1  christos 		     attributes.  */
    532  1.1  christos 		}
    533  1.1  christos 	    }
    534  1.1  christos           type_print (type, "", stream, -1);
    535  1.1  christos 	  fprintf_filtered (stream, ") ");
    536  1.1  christos 	  val_type = type;
    537  1.1  christos 	}
    538  1.1  christos       else
    539  1.1  christos 	{
    540  1.1  christos 	  /* normal case */
    541  1.1  christos 	  fprintf_filtered (stream, "(");
    542  1.1  christos 	  type_print (value_type (val), "", stream, -1);
    543  1.1  christos 	  fprintf_filtered (stream, ") ");
    544  1.1  christos 	}
    545  1.1  christos     }
    546  1.1  christos 
    547  1.1  christos   if (!value_initialized (val))
    548  1.1  christos     fprintf_filtered (stream, " [uninitialized] ");
    549  1.1  christos 
    550  1.1  christos   if (options->objectprint && (TYPE_CODE (type) == TYPE_CODE_CLASS))
    551  1.1  christos     {
    552  1.1  christos       /* Attempt to determine real type of object.  */
    553  1.1  christos       real_type = value_rtti_type (val, &full, &top, &using_enc);
    554  1.1  christos       if (real_type)
    555  1.1  christos 	{
    556  1.1  christos 	  /* We have RTTI information, so use it.  */
    557  1.1  christos 	  val = value_full_object (val, real_type,
    558  1.1  christos 				   full, top, using_enc);
    559  1.1  christos 	  fprintf_filtered (stream, "(%s%s) ",
    560  1.1  christos 			    TYPE_NAME (real_type),
    561  1.1  christos 			    full ? "" : _(" [incomplete object]"));
    562  1.1  christos 	  /* Print out object: enclosing type is same as real_type if
    563  1.1  christos 	     full.  */
    564  1.1  christos 	  val_print (value_enclosing_type (val),
    565  1.1  christos 		     value_contents_for_printing (val), 0,
    566  1.1  christos 		     value_address (val), stream, 0,
    567  1.1  christos 		     val, &opts, current_language);
    568  1.1  christos 	  return;
    569  1.1  christos           /* Note: When we look up RTTI entries, we don't get any
    570  1.1  christos              information on const or volatile attributes.  */
    571  1.1  christos 	}
    572  1.1  christos       else if (type != check_typedef (value_enclosing_type (val)))
    573  1.1  christos 	{
    574  1.1  christos 	  /* No RTTI information, so let's do our best.  */
    575  1.1  christos 	  fprintf_filtered (stream, "(%s ?) ",
    576  1.1  christos 			    TYPE_NAME (value_enclosing_type (val)));
    577  1.1  christos 	  val_print (value_enclosing_type (val),
    578  1.1  christos 		     value_contents_for_printing (val), 0,
    579  1.1  christos 		     value_address (val), stream, 0,
    580  1.1  christos 		     val, &opts, current_language);
    581  1.1  christos 	  return;
    582  1.1  christos 	}
    583  1.1  christos       /* Otherwise, we end up at the return outside this "if".  */
    584  1.1  christos     }
    585  1.1  christos 
    586  1.1  christos   val_print (val_type, value_contents_for_printing (val),
    587  1.1  christos 	     value_embedded_offset (val),
    588  1.1  christos 	     value_address (val),
    589  1.1  christos 	     stream, 0,
    590                	     val, &opts, current_language);
    591                }
    592