Home | History | Annotate | Line # | Download | only in gdb
c-valprint.c revision 1.6
      1  1.1  christos /* Support for printing C values for GDB, the GNU debugger.
      2  1.1  christos 
      3  1.6  christos    Copyright (C) 1986-2016 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.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.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.6  christos 
    150  1.6  christos   if (TYPE_CODE (elttype) == 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.6  christos 	  fputs_filtered (" <", stream);
    191  1.6  christos 	  fputs_filtered (MSYMBOL_PRINT_NAME (msymbol.minsym), 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 	  struct block *block = NULL;
    202  1.6  christos 	  struct field_of_this_result is_this_fld;
    203  1.6  christos 
    204  1.6  christos 	  if (want_space)
    205  1.6  christos 	    fputs_filtered (" ", stream);
    206  1.6  christos 
    207  1.6  christos 	  if (msymbol.minsym != NULL)
    208  1.6  christos 	    wsym = lookup_symbol (MSYMBOL_LINKAGE_NAME(msymbol.minsym), block,
    209  1.6  christos 				  VAR_DOMAIN, &is_this_fld).symbol;
    210  1.6  christos 
    211  1.6  christos 	  if (wsym)
    212  1.6  christos 	    {
    213  1.6  christos 	      wtype = SYMBOL_TYPE (wsym);
    214  1.6  christos 	    }
    215  1.6  christos 	  else
    216  1.6  christos 	    {
    217  1.6  christos 	      wtype = unresolved_elttype;
    218  1.6  christos 	    }
    219  1.6  christos 	  vt_val = value_at (wtype, vt_address);
    220  1.6  christos 	  common_val_print (vt_val, stream, recurse + 1, options,
    221  1.6  christos 			    current_language);
    222  1.1  christos 	  if (options->prettyformat)
    223  1.6  christos 	    {
    224  1.1  christos 	      fprintf_filtered (stream, "\n");
    225  1.1  christos 	      print_spaces_filtered (2 + 2 * recurse, stream);
    226  1.6  christos 	    }
    227  1.6  christos 	}
    228  1.6  christos     }
    229  1.6  christos }
    230  1.6  christos 
    231  1.6  christos /* c_val_print helper for TYPE_CODE_ARRAY.  */
    232  1.6  christos 
    233  1.6  christos static void
    234  1.6  christos c_val_print_array (struct type *type, const gdb_byte *valaddr,
    235  1.6  christos 		   int embedded_offset, CORE_ADDR address,
    236  1.6  christos 		   struct ui_file *stream, int recurse,
    237  1.6  christos 		   const struct value *original_value,
    238  1.6  christos 		   const struct value_print_options *options)
    239  1.6  christos {
    240  1.6  christos   struct type *unresolved_elttype = TYPE_TARGET_TYPE (type);
    241  1.6  christos   struct type *elttype = check_typedef (unresolved_elttype);
    242  1.6  christos   struct gdbarch *arch = get_type_arch (type);
    243  1.1  christos   int unit_size = gdbarch_addressable_memory_unit_size (arch);
    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.6  christos       int eltlen, len;
    249  1.6  christos       struct gdbarch *gdbarch = get_type_arch (type);
    250  1.6  christos       enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
    251  1.6  christos       unsigned int i = 0;	/* Number of characters printed.  */
    252  1.6  christos 
    253  1.6  christos       if (!get_array_bounds (type, &low_bound, &high_bound))
    254  1.6  christos 	error (_("Could not determine the array high bound"));
    255  1.6  christos 
    256  1.6  christos       eltlen = TYPE_LENGTH (elttype);
    257  1.6  christos       len = high_bound - low_bound + 1;
    258  1.6  christos       if (options->prettyformat_arrays)
    259  1.6  christos 	{
    260  1.6  christos 	  print_spaces_filtered (2 + 2 * recurse, stream);
    261  1.6  christos 	}
    262  1.6  christos 
    263  1.6  christos       /* Print arrays of textual chars with a string syntax, as
    264  1.6  christos 	 long as the entire array is valid.  */
    265  1.6  christos       if (c_textual_element_type (unresolved_elttype,
    266  1.6  christos 				  options->format)
    267  1.6  christos 	  && value_bytes_available (original_value, embedded_offset,
    268  1.6  christos 				    TYPE_LENGTH (type))
    269  1.6  christos 	  && !value_bits_any_optimized_out (original_value,
    270  1.6  christos 					    TARGET_CHAR_BIT * embedded_offset,
    271  1.6  christos 					    TARGET_CHAR_BIT * TYPE_LENGTH (type)))
    272  1.6  christos 	{
    273  1.6  christos 	  int force_ellipses = 0;
    274  1.6  christos 
    275  1.6  christos 	  /* If requested, look for the first null char and only
    276  1.6  christos 	     print elements up to it.  */
    277  1.1  christos 	  if (options->stop_print_at_null)
    278  1.6  christos 	    {
    279  1.1  christos 	      unsigned int temp_len;
    280  1.6  christos 
    281  1.6  christos 	      for (temp_len = 0;
    282  1.6  christos 		   (temp_len < len
    283  1.6  christos 		    && temp_len < options->print_max
    284  1.6  christos 		    && extract_unsigned_integer (valaddr
    285  1.6  christos 						 + embedded_offset * unit_size
    286  1.6  christos 						 + temp_len * eltlen,
    287  1.6  christos 						 eltlen, byte_order) != 0);
    288  1.6  christos 		   ++temp_len)
    289  1.6  christos 		;
    290  1.6  christos 
    291  1.6  christos 	      /* Force LA_PRINT_STRING to print ellipses if
    292  1.6  christos 		 we've printed the maximum characters and
    293  1.6  christos 		 the next character is not \000.  */
    294  1.1  christos 	      if (temp_len == options->print_max && temp_len < len)
    295  1.6  christos 		{
    296  1.6  christos 		  ULONGEST val
    297  1.6  christos 		    = extract_unsigned_integer (valaddr
    298  1.6  christos 						+ embedded_offset * unit_size
    299  1.6  christos 						+ temp_len * eltlen,
    300  1.6  christos 						eltlen, byte_order);
    301  1.6  christos 		  if (val != 0)
    302  1.6  christos 		    force_ellipses = 1;
    303  1.1  christos 		}
    304  1.6  christos 
    305  1.6  christos 	      len = temp_len;
    306  1.1  christos 	    }
    307  1.6  christos 
    308  1.6  christos 	  LA_PRINT_STRING (stream, unresolved_elttype,
    309  1.6  christos 			   valaddr + embedded_offset * unit_size, len,
    310  1.6  christos 			   NULL, force_ellipses, options);
    311  1.6  christos 	  i = len;
    312  1.6  christos 	}
    313  1.6  christos       else
    314  1.6  christos 	{
    315  1.6  christos 	  fprintf_filtered (stream, "{");
    316  1.6  christos 	  /* If this is a virtual function table, print the 0th
    317  1.6  christos 	     entry specially, and the rest of the members
    318  1.6  christos 	     normally.  */
    319  1.6  christos 	  if (cp_is_vtbl_ptr_type (elttype))
    320  1.6  christos 	    {
    321  1.6  christos 	      i = 1;
    322  1.6  christos 	      fprintf_filtered (stream, _("%d vtable entries"),
    323  1.1  christos 				len - 1);
    324  1.1  christos 	    }
    325  1.1  christos 	  else
    326  1.6  christos 	    {
    327  1.1  christos 	      i = 0;
    328  1.6  christos 	    }
    329  1.6  christos 	  val_print_array_elements (type, valaddr, embedded_offset,
    330  1.6  christos 				    address, stream,
    331  1.6  christos 				    recurse, original_value, options, i);
    332  1.1  christos 	  fprintf_filtered (stream, "}");
    333  1.6  christos 	}
    334  1.6  christos     }
    335  1.6  christos   else
    336  1.6  christos     {
    337  1.6  christos       /* Array of unspecified length: treat like pointer to first elt.  */
    338  1.6  christos       print_unpacked_pointer (type, elttype, unresolved_elttype, valaddr,
    339  1.6  christos 			      embedded_offset, address + embedded_offset,
    340  1.6  christos 			      stream, recurse, options);
    341  1.6  christos     }
    342  1.6  christos }
    343  1.6  christos 
    344  1.6  christos /* c_val_print helper for TYPE_CODE_PTR.  */
    345  1.6  christos 
    346  1.6  christos static void
    347  1.6  christos c_val_print_ptr (struct type *type, const gdb_byte *valaddr,
    348  1.6  christos 		 int embedded_offset, struct ui_file *stream, int recurse,
    349  1.6  christos 		 const struct value *original_value,
    350  1.6  christos 		 const struct value_print_options *options)
    351  1.6  christos {
    352  1.6  christos   struct gdbarch *arch = get_type_arch (type);
    353  1.6  christos   int unit_size = gdbarch_addressable_memory_unit_size (arch);
    354  1.6  christos 
    355  1.6  christos   if (options->format && options->format != 's')
    356  1.6  christos     {
    357  1.6  christos       val_print_scalar_formatted (type, valaddr, embedded_offset,
    358  1.6  christos 				  original_value, options, 0, stream);
    359  1.6  christos     }
    360  1.6  christos   else if (options->vtblprint && cp_is_vtbl_ptr_type (type))
    361  1.6  christos     {
    362  1.6  christos       /* Print the unmangled name if desired.  */
    363  1.6  christos       /* Print vtable entry - we only get here if we ARE using
    364  1.6  christos 	 -fvtable_thunks.  (Otherwise, look under
    365  1.6  christos 	 TYPE_CODE_STRUCT.)  */
    366  1.6  christos       CORE_ADDR addr
    367  1.6  christos 	= extract_typed_address (valaddr + embedded_offset, type);
    368  1.6  christos       struct gdbarch *gdbarch = get_type_arch (type);
    369  1.6  christos 
    370  1.6  christos       print_function_pointer_address (options, gdbarch, addr, stream);
    371  1.6  christos     }
    372  1.6  christos   else
    373  1.6  christos     {
    374  1.6  christos       struct type *unresolved_elttype = TYPE_TARGET_TYPE (type);
    375  1.6  christos       struct type *elttype = check_typedef (unresolved_elttype);
    376  1.6  christos       CORE_ADDR addr = unpack_pointer (type,
    377  1.6  christos 				       valaddr + embedded_offset * unit_size);
    378  1.6  christos 
    379  1.6  christos       print_unpacked_pointer (type, elttype, unresolved_elttype, valaddr,
    380  1.6  christos 			      embedded_offset, addr, stream, recurse, options);
    381  1.6  christos     }
    382  1.6  christos }
    383  1.6  christos 
    384  1.6  christos /* c_val_print helper for TYPE_CODE_STRUCT.  */
    385  1.6  christos 
    386  1.6  christos static void
    387  1.6  christos c_val_print_struct (struct type *type, const gdb_byte *valaddr,
    388  1.6  christos 		    int embedded_offset, CORE_ADDR address,
    389  1.6  christos 		    struct ui_file *stream, int recurse,
    390  1.6  christos 		    const struct value *original_value,
    391  1.6  christos 		    const struct value_print_options *options)
    392  1.6  christos {
    393  1.6  christos   if (options->vtblprint && cp_is_vtbl_ptr_type (type))
    394  1.6  christos     {
    395  1.6  christos       /* Print the unmangled name if desired.  */
    396  1.6  christos       /* Print vtable entry - we only get here if NOT using
    397  1.6  christos 	 -fvtable_thunks.  (Otherwise, look under
    398  1.6  christos 	 TYPE_CODE_PTR.)  */
    399  1.6  christos       struct gdbarch *gdbarch = get_type_arch (type);
    400  1.6  christos       int offset = (embedded_offset
    401  1.6  christos 		    + TYPE_FIELD_BITPOS (type,
    402  1.6  christos 					 VTBL_FNADDR_OFFSET) / 8);
    403  1.6  christos       struct type *field_type = TYPE_FIELD_TYPE (type, VTBL_FNADDR_OFFSET);
    404  1.6  christos       CORE_ADDR addr = extract_typed_address (valaddr + offset, field_type);
    405  1.6  christos 
    406  1.6  christos       print_function_pointer_address (options, gdbarch, addr, stream);
    407  1.6  christos     }
    408  1.6  christos   else
    409  1.6  christos     cp_print_value_fields_rtti (type, valaddr,
    410  1.6  christos 				embedded_offset, address,
    411  1.6  christos 				stream, recurse,
    412  1.6  christos 				original_value, options,
    413  1.6  christos 				NULL, 0);
    414  1.6  christos }
    415  1.6  christos 
    416  1.6  christos /* c_val_print helper for TYPE_CODE_UNION.  */
    417  1.6  christos 
    418  1.6  christos static void
    419  1.6  christos c_val_print_union (struct type *type, const gdb_byte *valaddr,
    420  1.6  christos 		   int embedded_offset, CORE_ADDR address,
    421  1.6  christos 		   struct ui_file *stream, int recurse,
    422  1.6  christos 		   const struct value *original_value,
    423  1.6  christos 		   const struct value_print_options *options)
    424  1.6  christos {
    425  1.6  christos   if (recurse && !options->unionprint)
    426  1.6  christos     {
    427  1.6  christos       fprintf_filtered (stream, "{...}");
    428  1.6  christos      }
    429  1.6  christos   else
    430  1.6  christos     {
    431  1.6  christos       c_val_print_struct (type, valaddr, embedded_offset, address, stream,
    432  1.6  christos 			  recurse, original_value, options);
    433  1.6  christos     }
    434  1.6  christos }
    435  1.6  christos 
    436  1.1  christos /* c_val_print helper for TYPE_CODE_INT.  */
    437  1.6  christos 
    438  1.6  christos static void
    439  1.6  christos c_val_print_int (struct type *type, struct type *unresolved_type,
    440  1.6  christos 		 const gdb_byte *valaddr, int embedded_offset,
    441  1.6  christos 		 struct ui_file *stream, const struct value *original_value,
    442  1.6  christos 		 const struct value_print_options *options)
    443  1.6  christos {
    444  1.6  christos   struct gdbarch *arch = get_type_arch (type);
    445  1.1  christos   int unit_size = gdbarch_addressable_memory_unit_size (arch);
    446  1.6  christos 
    447  1.6  christos   if (options->format || options->output_format)
    448  1.6  christos     {
    449  1.1  christos       struct value_print_options opts = *options;
    450  1.6  christos 
    451  1.6  christos       opts.format = (options->format ? options->format
    452  1.6  christos 		     : options->output_format);
    453  1.6  christos       val_print_scalar_formatted (type, valaddr, embedded_offset,
    454  1.6  christos 				  original_value, &opts, 0, stream);
    455  1.6  christos     }
    456  1.6  christos   else
    457  1.6  christos     {
    458  1.6  christos       val_print_type_code_int (type, valaddr + embedded_offset * unit_size,
    459  1.6  christos 			       stream);
    460  1.6  christos       /* C and C++ has no single byte int type, char is used
    461  1.6  christos 	 instead.  Since we don't know whether the value is really
    462  1.6  christos 	 intended to be used as an integer or a character, print
    463  1.6  christos 	 the character equivalent as well.  */
    464  1.6  christos       if (c_textual_element_type (unresolved_type, options->format))
    465  1.6  christos 	{
    466  1.6  christos 	  fputs_filtered (" ", stream);
    467  1.6  christos 	  LA_PRINT_CHAR (unpack_long (type,
    468  1.6  christos 				      valaddr + embedded_offset * unit_size),
    469  1.1  christos 			 unresolved_type, stream);
    470  1.6  christos 	}
    471  1.6  christos     }
    472  1.1  christos }
    473  1.6  christos 
    474  1.1  christos /* c_val_print helper for TYPE_CODE_MEMBERPTR.  */
    475  1.6  christos 
    476  1.6  christos static void
    477  1.6  christos c_val_print_memberptr (struct type *type, const gdb_byte *valaddr,
    478  1.6  christos 		       int embedded_offset, CORE_ADDR address,
    479  1.6  christos 		       struct ui_file *stream, int recurse,
    480  1.6  christos 		       const struct value *original_value,
    481  1.6  christos 		       const struct value_print_options *options)
    482  1.6  christos {
    483  1.6  christos   if (!options->format)
    484  1.6  christos     {
    485  1.6  christos       cp_print_class_member (valaddr + embedded_offset, type, stream, "&");
    486  1.6  christos     }
    487  1.6  christos   else
    488  1.6  christos     {
    489  1.6  christos       generic_val_print (type, valaddr, embedded_offset, address, stream,
    490  1.6  christos 			 recurse, original_value, options, &c_decorations);
    491  1.6  christos     }
    492  1.1  christos }
    493  1.6  christos 
    494  1.6  christos /* See val_print for a description of the various parameters of this
    495  1.1  christos    function; they are identical.  */
    496  1.6  christos 
    497  1.6  christos void
    498  1.6  christos c_val_print (struct type *type, const gdb_byte *valaddr,
    499  1.6  christos 	     int embedded_offset, CORE_ADDR address,
    500  1.6  christos 	     struct ui_file *stream, int recurse,
    501  1.6  christos 	     const struct value *original_value,
    502  1.6  christos 	     const struct value_print_options *options)
    503  1.6  christos {
    504  1.1  christos   struct type *unresolved_type = type;
    505  1.6  christos 
    506  1.6  christos   type = check_typedef (type);
    507  1.6  christos   switch (TYPE_CODE (type))
    508  1.6  christos     {
    509  1.6  christos     case TYPE_CODE_ARRAY:
    510  1.6  christos       c_val_print_array (type, valaddr, embedded_offset, address, stream,
    511  1.6  christos 			 recurse, original_value, options);
    512  1.1  christos       break;
    513  1.6  christos 
    514  1.6  christos     case TYPE_CODE_METHODPTR:
    515  1.6  christos       cplus_print_method_ptr (valaddr + embedded_offset, type, stream);
    516  1.1  christos       break;
    517  1.6  christos 
    518  1.6  christos     case TYPE_CODE_PTR:
    519  1.6  christos       c_val_print_ptr (type, valaddr, embedded_offset, stream, recurse,
    520  1.1  christos 		       original_value, options);
    521  1.1  christos       break;
    522  1.1  christos 
    523  1.6  christos     case TYPE_CODE_UNION:
    524  1.6  christos       c_val_print_union (type, valaddr, embedded_offset, address, stream,
    525  1.6  christos 			 recurse, original_value, options);
    526  1.6  christos       break;
    527  1.1  christos 
    528  1.6  christos     case TYPE_CODE_STRUCT:
    529  1.6  christos       c_val_print_struct (type, valaddr, embedded_offset, address, stream,
    530  1.1  christos 			  recurse, original_value, options);
    531  1.1  christos       break;
    532  1.1  christos 
    533  1.6  christos     case TYPE_CODE_INT:
    534  1.6  christos       c_val_print_int (type, unresolved_type, valaddr, embedded_offset, stream,
    535  1.1  christos 		       original_value, options);
    536  1.1  christos       break;
    537  1.1  christos 
    538  1.6  christos     case TYPE_CODE_MEMBERPTR:
    539  1.6  christos       c_val_print_memberptr (type, valaddr, embedded_offset, address, stream,
    540  1.6  christos 			     recurse, original_value, options);
    541  1.1  christos       break;
    542  1.1  christos 
    543  1.1  christos     case TYPE_CODE_REF:
    544  1.1  christos     case TYPE_CODE_ENUM:
    545  1.1  christos     case TYPE_CODE_FLAGS:
    546  1.1  christos     case TYPE_CODE_FUNC:
    547  1.1  christos     case TYPE_CODE_METHOD:
    548  1.1  christos     case TYPE_CODE_BOOL:
    549  1.1  christos     case TYPE_CODE_RANGE:
    550  1.1  christos     case TYPE_CODE_FLT:
    551  1.1  christos     case TYPE_CODE_DECFLOAT:
    552  1.1  christos     case TYPE_CODE_VOID:
    553  1.1  christos     case TYPE_CODE_ERROR:
    554  1.1  christos     case TYPE_CODE_UNDEF:
    555  1.1  christos     case TYPE_CODE_COMPLEX:
    556  1.1  christos     case TYPE_CODE_CHAR:
    557  1.1  christos     default:
    558  1.1  christos       generic_val_print (type, valaddr, embedded_offset, address,
    559  1.1  christos 			 stream, recurse, original_value, options,
    560  1.1  christos 			 &c_decorations);
    561  1.1  christos       break;
    562  1.1  christos     }
    563  1.1  christos   gdb_flush (stream);
    564  1.1  christos }
    565  1.1  christos 
    566  1.1  christos void
    568  1.1  christos c_value_print (struct value *val, struct ui_file *stream,
    569  1.1  christos 	       const struct value_print_options *options)
    570  1.6  christos {
    571  1.6  christos   struct type *type, *real_type, *val_type;
    572  1.1  christos   int full, using_enc;
    573  1.1  christos   LONGEST top;
    574  1.1  christos   struct value_print_options opts = *options;
    575  1.1  christos 
    576  1.1  christos   opts.deref_ref = 1;
    577  1.1  christos 
    578  1.1  christos   /* If it is a pointer, indicate what it points to.
    579  1.1  christos 
    580  1.1  christos      Print type also if it is a reference.
    581  1.1  christos 
    582  1.1  christos      C++: if it is a member pointer, we will take care
    583  1.1  christos      of that when we print it.  */
    584  1.1  christos 
    585  1.1  christos   /* Preserve the original type before stripping typedefs.  We prefer
    586  1.1  christos      to pass down the original type when possible, but for local
    587  1.1  christos      checks it is better to look past the typedefs.  */
    588  1.1  christos   val_type = value_type (val);
    589  1.1  christos   type = check_typedef (val_type);
    590  1.1  christos 
    591  1.1  christos   if (TYPE_CODE (type) == TYPE_CODE_PTR
    592  1.1  christos       || TYPE_CODE (type) == TYPE_CODE_REF)
    593  1.1  christos     {
    594  1.1  christos       /* Hack:  remove (char *) for char strings.  Their
    595  1.1  christos          type is indicated by the quoted string anyway.
    596  1.1  christos          (Don't use c_textual_element_type here; quoted strings
    597  1.1  christos          are always exactly (char *), (wchar_t *), or the like.  */
    598  1.1  christos       if (TYPE_CODE (val_type) == TYPE_CODE_PTR
    599  1.1  christos 	  && TYPE_NAME (val_type) == NULL
    600  1.1  christos 	  && TYPE_NAME (TYPE_TARGET_TYPE (val_type)) != NULL
    601  1.1  christos 	  && (strcmp (TYPE_NAME (TYPE_TARGET_TYPE (val_type)),
    602  1.1  christos 		      "char") == 0
    603  1.1  christos 	      || textual_name (TYPE_NAME (TYPE_TARGET_TYPE (val_type)))))
    604  1.1  christos 	{
    605  1.1  christos 	  /* Print nothing.  */
    606  1.3  christos 	}
    607  1.1  christos       else if (options->objectprint
    608  1.1  christos 	       && (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_STRUCT))
    609  1.1  christos 	{
    610  1.1  christos 	  int is_ref = TYPE_CODE (type) == TYPE_CODE_REF;
    611  1.1  christos 
    612  1.1  christos 	  if (is_ref)
    613  1.1  christos 	    val = value_addr (val);
    614  1.1  christos 
    615  1.1  christos 	  /* Pointer to class, check real type of object.  */
    616  1.1  christos 	  fprintf_filtered (stream, "(");
    617  1.6  christos 
    618  1.1  christos 	  if (value_entirely_available (val))
    619  1.1  christos 	    {
    620  1.1  christos 	      real_type = value_rtti_indirect_type (val, &full, &top,
    621  1.1  christos 						    &using_enc);
    622  1.1  christos 	      if (real_type)
    623  1.1  christos 		{
    624  1.1  christos 		  /* RTTI entry found.  */
    625  1.1  christos 		  type = real_type;
    626  1.1  christos 
    627  1.1  christos 		  /* Need to adjust pointer value.  */
    628  1.1  christos 		  val = value_from_pointer (real_type,
    629  1.1  christos 					    value_as_address (val) - top);
    630  1.1  christos 
    631  1.1  christos 		  /* Note: When we look up RTTI entries, we don't get
    632  1.1  christos 		     any information on const or volatile
    633  1.1  christos 		     attributes.  */
    634  1.6  christos 		}
    635  1.6  christos 	    }
    636  1.6  christos 
    637  1.6  christos 	  if (is_ref)
    638  1.6  christos 	    {
    639  1.6  christos 	      val = value_ref (value_ind (val));
    640  1.6  christos 	      type = value_type (val);
    641  1.6  christos 	    }
    642  1.1  christos 
    643  1.1  christos 	  type_print (type, "", stream, -1);
    644  1.1  christos 	  fprintf_filtered (stream, ") ");
    645  1.1  christos 	  val_type = type;
    646  1.1  christos 	}
    647  1.1  christos       else
    648  1.1  christos 	{
    649  1.1  christos 	  /* normal case */
    650  1.1  christos 	  fprintf_filtered (stream, "(");
    651  1.1  christos 	  type_print (value_type (val), "", stream, -1);
    652  1.1  christos 	  fprintf_filtered (stream, ") ");
    653  1.1  christos 	}
    654  1.1  christos     }
    655  1.1  christos 
    656  1.1  christos   if (!value_initialized (val))
    657  1.3  christos     fprintf_filtered (stream, " [uninitialized] ");
    658  1.1  christos 
    659  1.1  christos   if (options->objectprint && (TYPE_CODE (type) == TYPE_CODE_STRUCT))
    660  1.1  christos     {
    661  1.1  christos       /* Attempt to determine real type of object.  */
    662  1.1  christos       real_type = value_rtti_type (val, &full, &top, &using_enc);
    663  1.1  christos       if (real_type)
    664  1.1  christos 	{
    665  1.1  christos 	  /* We have RTTI information, so use it.  */
    666  1.1  christos 	  val = value_full_object (val, real_type,
    667  1.1  christos 				   full, top, using_enc);
    668  1.1  christos 	  fprintf_filtered (stream, "(%s%s) ",
    669  1.1  christos 			    TYPE_NAME (real_type),
    670  1.1  christos 			    full ? "" : _(" [incomplete object]"));
    671  1.1  christos 	  /* Print out object: enclosing type is same as real_type if
    672  1.1  christos 	     full.  */
    673  1.1  christos 	  val_print (value_enclosing_type (val),
    674  1.1  christos 		     value_contents_for_printing (val), 0,
    675  1.1  christos 		     value_address (val), stream, 0,
    676  1.1  christos 		     val, &opts, current_language);
    677  1.1  christos 	  return;
    678  1.1  christos           /* Note: When we look up RTTI entries, we don't get any
    679  1.1  christos              information on const or volatile attributes.  */
    680  1.1  christos 	}
    681  1.1  christos       else if (type != check_typedef (value_enclosing_type (val)))
    682  1.1  christos 	{
    683  1.1  christos 	  /* No RTTI information, so let's do our best.  */
    684  1.1  christos 	  fprintf_filtered (stream, "(%s ?) ",
    685  1.1  christos 			    TYPE_NAME (value_enclosing_type (val)));
    686  1.1  christos 	  val_print (value_enclosing_type (val),
    687  1.1  christos 		     value_contents_for_printing (val), 0,
    688  1.1  christos 		     value_address (val), stream, 0,
    689  1.1  christos 		     val, &opts, current_language);
    690  1.1  christos 	  return;
    691  1.1  christos 	}
    692  1.1  christos       /* Otherwise, we end up at the return outside this "if".  */
    693  1.1  christos     }
    694  1.1  christos 
    695  1.1  christos   val_print (val_type, value_contents_for_printing (val),
    696  1.1  christos 	     value_embedded_offset (val),
    697  1.1  christos 	     value_address (val),
    698  1.1  christos 	     stream, 0,
    699                	     val, &opts, current_language);
    700                }
    701