Home | History | Annotate | Line # | Download | only in gdb
c-valprint.c revision 1.9
      1  1.1  christos /* Support for printing C values for GDB, the GNU debugger.
      2  1.1  christos 
      3  1.9  christos    Copyright (C) 1986-2020 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 "symtab.h"
     22  1.1  christos #include "gdbtypes.h"
     23  1.1  christos #include "expression.h"
     24  1.1  christos #include "value.h"
     25  1.1  christos #include "valprint.h"
     26  1.1  christos #include "language.h"
     27  1.1  christos #include "c-lang.h"
     28  1.1  christos #include "cp-abi.h"
     29  1.1  christos #include "target.h"
     30  1.3  christos #include "objfiles.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.9  christos   /* TYPE_CODE_CHAR is always textual.  */
     70  1.1  christos   if (true_type->code () == TYPE_CODE_CHAR)
     71  1.1  christos     return 1;
     72  1.1  christos 
     73  1.9  christos   /* Any other character-like types must be integral.  */
     74  1.1  christos   if (true_type->code () != 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.9  christos       /* Check the name of the type.  */
     82  1.1  christos       if (iter_type->name () && textual_name (iter_type->name ()))
     83  1.1  christos 	return 1;
     84  1.9  christos 
     85  1.1  christos       if (iter_type->code () != 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.9  christos 	 character support.  */
    101  1.1  christos       if (true_type->code () == 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.9  christos 	 being used as data.  */
    110  1.1  christos       if (true_type->code () == 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.9  christos   " + ",
    125  1.1  christos   "i",
    126  1.1  christos   "true",
    127  1.6  christos   "false",
    128  1.6  christos   "void",
    129  1.6  christos   "{",
    130  1.1  christos   "}"
    131  1.1  christos };
    132  1.6  christos 
    133  1.1  christos /* Print a pointer based on the type of its target.
    134  1.6  christos 
    135  1.6  christos    Arguments to this functions are roughly the same as those in c_val_print.
    136  1.6  christos    A difference is that ADDRESS is the address to print, with embedded_offset
    137  1.6  christos    already added.  UNRESOLVED_ELTTYPE and ELTTYPE represent the pointed type,
    138  1.6  christos    respectively before and after check_typedef.  */
    139  1.6  christos 
    140  1.6  christos static void
    141  1.6  christos print_unpacked_pointer (struct type *type, struct type *elttype,
    142  1.6  christos 			struct type *unresolved_elttype,
    143  1.6  christos 			const gdb_byte *valaddr, int embedded_offset,
    144  1.6  christos 			CORE_ADDR address, struct ui_file *stream, int recurse,
    145  1.1  christos 			const struct value_print_options *options)
    146  1.6  christos {
    147  1.1  christos   int want_space = 0;
    148  1.1  christos   struct gdbarch *gdbarch = get_type_arch (type);
    149  1.9  christos 
    150  1.6  christos   if (elttype->code () == TYPE_CODE_FUNC)
    151  1.6  christos     {
    152  1.6  christos       /* Try to print what function it points to.  */
    153  1.6  christos       print_function_pointer_address (options, gdbarch, address, stream);
    154  1.6  christos       return;
    155  1.6  christos     }
    156  1.6  christos 
    157  1.6  christos   if (options->symbol_print)
    158  1.6  christos     want_space = print_address_demangle (options, gdbarch, address, stream,
    159  1.6  christos 					 demangle);
    160  1.6  christos   else if (options->addressprint)
    161  1.6  christos     {
    162  1.6  christos       fputs_filtered (paddress (gdbarch, address), stream);
    163  1.6  christos       want_space = 1;
    164  1.6  christos     }
    165  1.6  christos 
    166  1.6  christos   /* For a pointer to a textual type, also print the string
    167  1.6  christos      pointed to, unless pointer is null.  */
    168  1.6  christos 
    169  1.6  christos   if (c_textual_element_type (unresolved_elttype, options->format)
    170  1.6  christos       && address != 0)
    171  1.6  christos     {
    172  1.6  christos       if (want_space)
    173  1.6  christos 	fputs_filtered (" ", stream);
    174  1.6  christos       val_print_string (unresolved_elttype, NULL, address, -1, stream, options);
    175  1.6  christos     }
    176  1.1  christos   else if (cp_is_vtbl_member (type))
    177  1.6  christos     {
    178  1.6  christos       /* Print vtbl's nicely.  */
    179  1.6  christos       CORE_ADDR vt_address = unpack_pointer (type, valaddr + embedded_offset);
    180  1.6  christos       struct bound_minimal_symbol msymbol =
    181  1.6  christos 	lookup_minimal_symbol_by_pc (vt_address);
    182  1.6  christos 
    183  1.6  christos       /* If 'symbol_print' is set, we did the work above.  */
    184  1.6  christos       if (!options->symbol_print
    185  1.6  christos 	  && (msymbol.minsym != NULL)
    186  1.6  christos 	  && (vt_address == BMSYMBOL_VALUE_ADDRESS (msymbol)))
    187  1.6  christos 	{
    188  1.6  christos 	  if (want_space)
    189  1.6  christos 	    fputs_filtered (" ", stream);
    190  1.9  christos 	  fputs_filtered (" <", stream);
    191  1.6  christos 	  fputs_filtered (msymbol.minsym->print_name (), stream);
    192  1.6  christos 	  fputs_filtered (">", stream);
    193  1.6  christos 	  want_space = 1;
    194  1.6  christos 	}
    195  1.6  christos 
    196  1.6  christos       if (vt_address && options->vtblprint)
    197  1.6  christos 	{
    198  1.6  christos 	  struct value *vt_val;
    199  1.6  christos 	  struct symbol *wsym = NULL;
    200  1.6  christos 	  struct type *wtype;
    201  1.6  christos 
    202  1.6  christos 	  if (want_space)
    203  1.6  christos 	    fputs_filtered (" ", stream);
    204  1.6  christos 
    205  1.8  christos 	  if (msymbol.minsym != NULL)
    206  1.9  christos 	    {
    207  1.9  christos 	      const char *search_name = msymbol.minsym->search_name ();
    208  1.8  christos 	      wsym = lookup_symbol_search_name (search_name, NULL,
    209  1.8  christos 						VAR_DOMAIN).symbol;
    210  1.6  christos 	    }
    211  1.6  christos 
    212  1.6  christos 	  if (wsym)
    213  1.6  christos 	    {
    214  1.6  christos 	      wtype = SYMBOL_TYPE (wsym);
    215  1.6  christos 	    }
    216  1.6  christos 	  else
    217  1.6  christos 	    {
    218  1.6  christos 	      wtype = unresolved_elttype;
    219  1.6  christos 	    }
    220  1.6  christos 	  vt_val = value_at (wtype, vt_address);
    221  1.6  christos 	  common_val_print (vt_val, stream, recurse + 1, options,
    222  1.6  christos 			    current_language);
    223  1.1  christos 	  if (options->prettyformat)
    224  1.6  christos 	    {
    225  1.1  christos 	      fprintf_filtered (stream, "\n");
    226  1.1  christos 	      print_spaces_filtered (2 + 2 * recurse, stream);
    227  1.6  christos 	    }
    228  1.6  christos 	}
    229  1.6  christos     }
    230  1.6  christos }
    231  1.9  christos 
    232  1.6  christos /* c_value_print helper for TYPE_CODE_ARRAY.  */
    233  1.6  christos 
    234  1.9  christos static void
    235  1.9  christos c_value_print_array (struct value *val,
    236  1.9  christos 		     struct ui_file *stream, int recurse,
    237  1.9  christos 		     const struct value_print_options *options)
    238  1.9  christos {
    239  1.9  christos   struct type *type = check_typedef (value_type (val));
    240  1.9  christos   CORE_ADDR address = value_address (val);
    241  1.6  christos   const gdb_byte *valaddr = value_contents_for_printing (val);
    242  1.6  christos   struct type *unresolved_elttype = TYPE_TARGET_TYPE (type);
    243  1.1  christos   struct type *elttype = check_typedef (unresolved_elttype);
    244  1.6  christos 
    245  1.6  christos   if (TYPE_LENGTH (type) > 0 && TYPE_LENGTH (unresolved_elttype) > 0)
    246  1.6  christos     {
    247  1.6  christos       LONGEST low_bound, high_bound;
    248  1.9  christos       int eltlen, len;
    249  1.6  christos       enum bfd_endian byte_order = type_byte_order (type);
    250  1.6  christos 
    251  1.6  christos       if (!get_array_bounds (type, &low_bound, &high_bound))
    252  1.6  christos 	error (_("Could not determine the array high bound"));
    253  1.6  christos 
    254  1.6  christos       eltlen = TYPE_LENGTH (elttype);
    255  1.6  christos       len = high_bound - low_bound + 1;
    256  1.6  christos 
    257  1.6  christos       /* Print arrays of textual chars with a string syntax, as
    258  1.6  christos 	 long as the entire array is valid.  */
    259  1.6  christos       if (c_textual_element_type (unresolved_elttype,
    260  1.9  christos 				  options->format)
    261  1.9  christos 	  && value_bytes_available (val, 0, TYPE_LENGTH (type))
    262  1.6  christos 	  && !value_bits_any_optimized_out (val, 0,
    263  1.6  christos 					    TARGET_CHAR_BIT * TYPE_LENGTH (type)))
    264  1.6  christos 	{
    265  1.6  christos 	  int force_ellipses = 0;
    266  1.6  christos 
    267  1.6  christos 	  /* If requested, look for the first null char and only
    268  1.6  christos 	     print elements up to it.  */
    269  1.1  christos 	  if (options->stop_print_at_null)
    270  1.6  christos 	    {
    271  1.1  christos 	      unsigned int temp_len;
    272  1.6  christos 
    273  1.6  christos 	      for (temp_len = 0;
    274  1.6  christos 		   (temp_len < len
    275  1.9  christos 		    && temp_len < options->print_max
    276  1.6  christos 		    && extract_unsigned_integer (valaddr + temp_len * eltlen,
    277  1.6  christos 						 eltlen, byte_order) != 0);
    278  1.6  christos 		   ++temp_len)
    279  1.6  christos 		;
    280  1.6  christos 
    281  1.6  christos 	      /* Force LA_PRINT_STRING to print ellipses if
    282  1.6  christos 		 we've printed the maximum characters and
    283  1.6  christos 		 the next character is not \000.  */
    284  1.1  christos 	      if (temp_len == options->print_max && temp_len < len)
    285  1.9  christos 		{
    286  1.9  christos 		  ULONGEST ival
    287  1.6  christos 		    = extract_unsigned_integer (valaddr + temp_len * eltlen,
    288  1.9  christos 						eltlen, byte_order);
    289  1.6  christos 		  if (ival != 0)
    290  1.6  christos 		    force_ellipses = 1;
    291  1.1  christos 		}
    292  1.6  christos 
    293  1.6  christos 	      len = temp_len;
    294  1.1  christos 	    }
    295  1.9  christos 
    296  1.6  christos 	  LA_PRINT_STRING (stream, unresolved_elttype, valaddr, len,
    297  1.6  christos 			   NULL, force_ellipses, options);
    298  1.6  christos 	}
    299  1.6  christos       else
    300  1.9  christos 	{
    301  1.6  christos 	  unsigned int i = 0;
    302  1.6  christos 	  fprintf_filtered (stream, "{");
    303  1.6  christos 	  /* If this is a virtual function table, print the 0th
    304  1.6  christos 	     entry specially, and the rest of the members
    305  1.6  christos 	     normally.  */
    306  1.6  christos 	  if (cp_is_vtbl_ptr_type (elttype))
    307  1.6  christos 	    {
    308  1.6  christos 	      i = 1;
    309  1.6  christos 	      fprintf_filtered (stream, _("%d vtable entries"),
    310  1.1  christos 				len - 1);
    311  1.9  christos 	    }
    312  1.6  christos 	  value_print_array_elements (val, stream, recurse, options, i);
    313  1.1  christos 	  fprintf_filtered (stream, "}");
    314  1.6  christos 	}
    315  1.6  christos     }
    316  1.6  christos   else
    317  1.6  christos     {
    318  1.6  christos       /* Array of unspecified length: treat like pointer to first elt.  */
    319  1.9  christos       print_unpacked_pointer (type, elttype, unresolved_elttype, valaddr,
    320  1.6  christos 			      0, address, stream, recurse, options);
    321  1.6  christos     }
    322  1.6  christos }
    323  1.9  christos 
    324  1.6  christos /* c_value_print_inner helper for TYPE_CODE_PTR.  */
    325  1.6  christos 
    326  1.9  christos static void
    327  1.9  christos c_value_print_ptr (struct value *val, struct ui_file *stream, int recurse,
    328  1.6  christos 		   const struct value_print_options *options)
    329  1.6  christos {
    330  1.6  christos   if (options->format && options->format != 's')
    331  1.9  christos     {
    332  1.9  christos       value_print_scalar_formatted (val, options, 0, stream);
    333  1.6  christos       return;
    334  1.9  christos     }
    335  1.9  christos 
    336  1.9  christos   struct type *type = check_typedef (value_type (val));
    337  1.9  christos   struct gdbarch *arch = get_type_arch (type);
    338  1.9  christos   const gdb_byte *valaddr = value_contents_for_printing (val);
    339  1.9  christos 
    340  1.6  christos   if (options->vtblprint && cp_is_vtbl_ptr_type (type))
    341  1.6  christos     {
    342  1.6  christos       /* Print the unmangled name if desired.  */
    343  1.6  christos       /* Print vtable entry - we only get here if we ARE using
    344  1.6  christos 	 -fvtable_thunks.  (Otherwise, look under
    345  1.9  christos 	 TYPE_CODE_STRUCT.)  */
    346  1.6  christos       CORE_ADDR addr = extract_typed_address (valaddr, type);
    347  1.9  christos 
    348  1.6  christos       print_function_pointer_address (options, arch, addr, stream);
    349  1.6  christos     }
    350  1.6  christos   else
    351  1.6  christos     {
    352  1.6  christos       struct type *unresolved_elttype = TYPE_TARGET_TYPE (type);
    353  1.9  christos       struct type *elttype = check_typedef (unresolved_elttype);
    354  1.6  christos       CORE_ADDR addr = unpack_pointer (type, valaddr);
    355  1.6  christos 
    356  1.9  christos       print_unpacked_pointer (type, elttype, unresolved_elttype, valaddr,
    357  1.6  christos 			      0, addr, stream, recurse, options);
    358  1.6  christos     }
    359  1.6  christos }
    360  1.9  christos 
    361  1.6  christos /* c_value_print helper for TYPE_CODE_STRUCT and TYPE_CODE_UNION.  */
    362  1.6  christos 
    363  1.9  christos static void
    364  1.9  christos c_value_print_struct (struct value *val, struct ui_file *stream, int recurse,
    365  1.6  christos 		      const struct value_print_options *options)
    366  1.9  christos {
    367  1.9  christos   struct type *type = check_typedef (value_type (val));
    368  1.9  christos 
    369  1.9  christos   if (type->code () == TYPE_CODE_UNION && recurse && !options->unionprint)
    370  1.9  christos     fprintf_filtered (stream, "{...}");
    371  1.6  christos   else if (options->vtblprint && cp_is_vtbl_ptr_type (type))
    372  1.6  christos     {
    373  1.6  christos       /* Print the unmangled name if desired.  */
    374  1.6  christos       /* Print vtable entry - we only get here if NOT using
    375  1.6  christos 	 -fvtable_thunks.  (Otherwise, look under
    376  1.6  christos 	 TYPE_CODE_PTR.)  */
    377  1.9  christos       struct gdbarch *gdbarch = get_type_arch (type);
    378  1.9  christos       int offset = TYPE_FIELD_BITPOS (type, VTBL_FNADDR_OFFSET) / 8;
    379  1.9  christos       struct type *field_type = type->field (VTBL_FNADDR_OFFSET).type ();
    380  1.6  christos       const gdb_byte *valaddr = value_contents_for_printing (val);
    381  1.6  christos       CORE_ADDR addr = extract_typed_address (valaddr + offset, field_type);
    382  1.6  christos 
    383  1.6  christos       print_function_pointer_address (options, gdbarch, addr, stream);
    384  1.6  christos     }
    385  1.9  christos   else
    386  1.6  christos     cp_print_value_fields (val, stream, recurse, options, NULL, 0);
    387  1.6  christos }
    388  1.9  christos 
    389  1.6  christos /* c_value_print helper for TYPE_CODE_INT.  */
    390  1.6  christos 
    391  1.9  christos static void
    392  1.6  christos c_value_print_int (struct value *val, struct ui_file *stream,
    393  1.6  christos 		   const struct value_print_options *options)
    394  1.6  christos {
    395  1.6  christos   if (options->format || options->output_format)
    396  1.6  christos     {
    397  1.1  christos       struct value_print_options opts = *options;
    398  1.6  christos 
    399  1.6  christos       opts.format = (options->format ? options->format
    400  1.9  christos 		     : options->output_format);
    401  1.6  christos       value_print_scalar_formatted (val, &opts, 0, stream);
    402  1.6  christos     }
    403  1.6  christos   else
    404  1.9  christos     {
    405  1.6  christos       value_print_scalar_formatted (val, options, 0, stream);
    406  1.6  christos       /* C and C++ has no single byte int type, char is used
    407  1.6  christos 	 instead.  Since we don't know whether the value is really
    408  1.6  christos 	 intended to be used as an integer or a character, print
    409  1.9  christos 	 the character equivalent as well.  */
    410  1.9  christos       struct type *type = value_type (val);
    411  1.9  christos       const gdb_byte *valaddr = value_contents_for_printing (val);
    412  1.6  christos       if (c_textual_element_type (type, options->format))
    413  1.6  christos 	{
    414  1.9  christos 	  fputs_filtered (" ", stream);
    415  1.1  christos 	  LA_PRINT_CHAR (unpack_long (type, valaddr), type, stream);
    416  1.6  christos 	}
    417  1.6  christos     }
    418  1.1  christos }
    419  1.9  christos 
    420  1.1  christos /* c_value_print helper for TYPE_CODE_MEMBERPTR.  */
    421  1.6  christos 
    422  1.9  christos static void
    423  1.9  christos c_value_print_memberptr (struct value *val, struct ui_file *stream,
    424  1.9  christos 			 int recurse,
    425  1.6  christos 			 const struct value_print_options *options)
    426  1.6  christos {
    427  1.6  christos   if (!options->format)
    428  1.9  christos     {
    429  1.9  christos       struct type *type = check_typedef (value_type (val));
    430  1.9  christos       const gdb_byte *valaddr = value_contents_for_printing (val);
    431  1.6  christos       cp_print_class_member (valaddr, type, stream, "&");
    432  1.6  christos     }
    433  1.9  christos   else
    434  1.6  christos     generic_value_print (val, stream, recurse, options, &c_decorations);
    435  1.1  christos }
    436  1.9  christos 
    437  1.1  christos /* See c-lang.h.  */
    438  1.6  christos 
    439  1.9  christos void
    440  1.9  christos c_value_print_inner (struct value *val, struct ui_file *stream, int recurse,
    441  1.6  christos 		     const struct value_print_options *options)
    442  1.9  christos {
    443  1.9  christos   struct type *type = value_type (val);
    444  1.1  christos   const gdb_byte *valaddr = value_contents_for_printing (val);
    445  1.6  christos 
    446  1.9  christos   type = check_typedef (type);
    447  1.6  christos   switch (type->code ())
    448  1.6  christos     {
    449  1.9  christos     case TYPE_CODE_ARRAY:
    450  1.6  christos       c_value_print_array (val, stream, recurse, options);
    451  1.1  christos       break;
    452  1.6  christos 
    453  1.9  christos     case TYPE_CODE_METHODPTR:
    454  1.6  christos       cplus_print_method_ptr (valaddr, type, stream);
    455  1.1  christos       break;
    456  1.6  christos 
    457  1.9  christos     case TYPE_CODE_PTR:
    458  1.1  christos       c_value_print_ptr (val, stream, recurse, options);
    459  1.1  christos       break;
    460  1.1  christos 
    461  1.1  christos     case TYPE_CODE_UNION:
    462  1.9  christos     case TYPE_CODE_STRUCT:
    463  1.1  christos       c_value_print_struct (val, stream, recurse, options);
    464  1.1  christos       break;
    465  1.1  christos 
    466  1.9  christos     case TYPE_CODE_INT:
    467  1.1  christos       c_value_print_int (val, stream, options);
    468  1.1  christos       break;
    469  1.1  christos 
    470  1.9  christos     case TYPE_CODE_MEMBERPTR:
    471  1.6  christos       c_value_print_memberptr (val, stream, recurse, options);
    472  1.1  christos       break;
    473  1.1  christos 
    474  1.7  christos     case TYPE_CODE_REF:
    475  1.1  christos     case TYPE_CODE_RVALUE_REF:
    476  1.1  christos     case TYPE_CODE_ENUM:
    477  1.1  christos     case TYPE_CODE_FLAGS:
    478  1.1  christos     case TYPE_CODE_FUNC:
    479  1.1  christos     case TYPE_CODE_METHOD:
    480  1.1  christos     case TYPE_CODE_BOOL:
    481  1.1  christos     case TYPE_CODE_RANGE:
    482  1.1  christos     case TYPE_CODE_FLT:
    483  1.1  christos     case TYPE_CODE_DECFLOAT:
    484  1.1  christos     case TYPE_CODE_VOID:
    485  1.1  christos     case TYPE_CODE_ERROR:
    486  1.1  christos     case TYPE_CODE_UNDEF:
    487  1.1  christos     case TYPE_CODE_COMPLEX:
    488  1.1  christos     case TYPE_CODE_CHAR:
    489  1.9  christos     default:
    490  1.1  christos       generic_value_print (val, stream, recurse, options, &c_decorations);
    491  1.1  christos       break;
    492  1.1  christos     }
    493  1.9  christos }
    494  1.1  christos 
    495  1.1  christos 
    496  1.1  christos void
    498  1.1  christos c_value_print (struct value *val, struct ui_file *stream,
    499  1.9  christos 	       const struct value_print_options *options)
    500  1.6  christos {
    501  1.6  christos   struct type *type, *real_type;
    502  1.1  christos   int full, using_enc;
    503  1.1  christos   LONGEST top;
    504  1.1  christos   struct value_print_options opts = *options;
    505  1.1  christos 
    506  1.1  christos   opts.deref_ref = 1;
    507  1.1  christos 
    508  1.1  christos   /* If it is a pointer, indicate what it points to.
    509  1.1  christos 
    510  1.1  christos      Print type also if it is a reference.
    511  1.1  christos 
    512  1.1  christos      C++: if it is a member pointer, we will take care
    513  1.9  christos      of that when we print it.  */
    514  1.1  christos 
    515  1.9  christos   type = check_typedef (value_type (val));
    516  1.1  christos 
    517  1.9  christos   if (type->code () == TYPE_CODE_PTR || TYPE_IS_REFERENCE (type))
    518  1.9  christos     {
    519  1.1  christos       struct type *original_type = value_type (val);
    520  1.1  christos 
    521  1.1  christos       /* Hack:  remove (char *) for char strings.  Their
    522  1.1  christos          type is indicated by the quoted string anyway.
    523  1.9  christos          (Don't use c_textual_element_type here; quoted strings
    524  1.9  christos          are always exactly (char *), (wchar_t *), or the like.  */
    525  1.9  christos       if (original_type->code () == TYPE_CODE_PTR
    526  1.9  christos 	  && original_type->name () == NULL
    527  1.1  christos 	  && TYPE_TARGET_TYPE (original_type)->name () != NULL
    528  1.9  christos 	  && (strcmp (TYPE_TARGET_TYPE (original_type)->name (),
    529  1.1  christos 		      "char") == 0
    530  1.1  christos 	      || textual_name (TYPE_TARGET_TYPE (original_type)->name ())))
    531  1.1  christos 	{
    532  1.1  christos 	  /* Print nothing.  */
    533  1.9  christos 	}
    534  1.1  christos       else if (options->objectprint
    535  1.7  christos 	       && (TYPE_TARGET_TYPE (type)->code () == TYPE_CODE_STRUCT))
    536  1.7  christos 	{
    537  1.1  christos 	  int is_ref = TYPE_IS_REFERENCE (type);
    538  1.1  christos 	  enum type_code refcode = TYPE_CODE_UNDEF;
    539  1.7  christos 
    540  1.7  christos 	  if (is_ref)
    541  1.9  christos 	    {
    542  1.7  christos 	      val = value_addr (val);
    543  1.1  christos 	      refcode = type->code ();
    544  1.1  christos 	    }
    545  1.1  christos 
    546  1.1  christos 	  /* Pointer to class, check real type of object.  */
    547  1.1  christos 	  fprintf_filtered (stream, "(");
    548  1.6  christos 
    549  1.1  christos 	  if (value_entirely_available (val))
    550  1.1  christos 	    {
    551  1.1  christos 	      real_type = value_rtti_indirect_type (val, &full, &top,
    552  1.1  christos 						    &using_enc);
    553  1.1  christos 	      if (real_type)
    554  1.1  christos 		{
    555  1.1  christos 		  /* RTTI entry found.  */
    556  1.1  christos 
    557  1.1  christos 		  /* Need to adjust pointer value.  */
    558  1.1  christos 		  val = value_from_pointer (real_type,
    559  1.1  christos 					    value_as_address (val) - top);
    560  1.1  christos 
    561  1.1  christos 		  /* Note: When we look up RTTI entries, we don't get
    562  1.1  christos 		     any information on const or volatile
    563  1.1  christos 		     attributes.  */
    564  1.6  christos 		}
    565  1.6  christos 	    }
    566  1.9  christos 
    567  1.6  christos 	  if (is_ref)
    568  1.9  christos 	    val = value_ref (value_ind (val), refcode);
    569  1.6  christos 
    570  1.1  christos 	  type = value_type (val);
    571  1.1  christos 	  type_print (type, "", stream, -1);
    572  1.1  christos 	  fprintf_filtered (stream, ") ");
    573  1.1  christos 	}
    574  1.1  christos       else
    575  1.1  christos 	{
    576  1.1  christos 	  /* normal case */
    577  1.1  christos 	  fprintf_filtered (stream, "(");
    578  1.1  christos 	  type_print (value_type (val), "", stream, -1);
    579  1.1  christos 	  fprintf_filtered (stream, ") ");
    580  1.1  christos 	}
    581  1.1  christos     }
    582  1.1  christos 
    583  1.1  christos   if (!value_initialized (val))
    584  1.9  christos     fprintf_filtered (stream, " [uninitialized] ");
    585  1.1  christos 
    586  1.1  christos   if (options->objectprint && (type->code () == TYPE_CODE_STRUCT))
    587  1.1  christos     {
    588  1.1  christos       /* Attempt to determine real type of object.  */
    589  1.1  christos       real_type = value_rtti_type (val, &full, &top, &using_enc);
    590  1.1  christos       if (real_type)
    591  1.1  christos 	{
    592  1.1  christos 	  /* We have RTTI information, so use it.  */
    593  1.9  christos 	  val = value_full_object (val, real_type,
    594  1.9  christos 				   full, top, using_enc);
    595  1.9  christos 	  /* In a destructor we might see a real type that is a
    596  1.9  christos 	     superclass of the object's type.  In this case it is
    597  1.9  christos 	     better to leave the object as-is.  */
    598  1.9  christos 	  if (!(full
    599  1.9  christos 		&& (TYPE_LENGTH (real_type)
    600  1.1  christos 		    < TYPE_LENGTH (value_enclosing_type (val)))))
    601  1.9  christos 	    val = value_cast (real_type, val);
    602  1.1  christos 	  fprintf_filtered (stream, "(%s%s) ",
    603  1.1  christos 			    real_type->name (),
    604  1.1  christos 			    full ? "" : _(" [incomplete object]"));
    605  1.1  christos 	}
    606  1.1  christos       else if (type != check_typedef (value_enclosing_type (val)))
    607  1.1  christos 	{
    608  1.9  christos 	  /* No RTTI information, so let's do our best.  */
    609  1.9  christos 	  fprintf_filtered (stream, "(%s ?) ",
    610  1.1  christos 			    value_enclosing_type (val)->name ());
    611  1.1  christos 	  val = value_cast (value_enclosing_type (val), val);
    612  1.1  christos 	}
    613  1.9  christos     }
    614  1.1  christos 
    615                  common_val_print (val, stream, 0, &opts, current_language);
    616                }
    617