119370Spst/* Support for printing C values for GDB, the GNU debugger. 219370Spst 3130803Smarcel Copyright 1986, 1988, 1989, 1991, 1992, 1993, 1994, 1995, 1996, 4130803Smarcel 1997, 1998, 1999, 2000, 2001, 2003 Free Software Foundation, Inc. 5130803Smarcel 698944Sobrien This file is part of GDB. 719370Spst 898944Sobrien This program is free software; you can redistribute it and/or modify 998944Sobrien it under the terms of the GNU General Public License as published by 1098944Sobrien the Free Software Foundation; either version 2 of the License, or 1198944Sobrien (at your option) any later version. 1219370Spst 1398944Sobrien This program is distributed in the hope that it will be useful, 1498944Sobrien but WITHOUT ANY WARRANTY; without even the implied warranty of 1598944Sobrien MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1698944Sobrien GNU General Public License for more details. 1719370Spst 1898944Sobrien You should have received a copy of the GNU General Public License 1998944Sobrien along with this program; if not, write to the Free Software 2098944Sobrien Foundation, Inc., 59 Temple Place - Suite 330, 2198944Sobrien Boston, MA 02111-1307, USA. */ 2219370Spst 2319370Spst#include "defs.h" 24130803Smarcel#include "gdb_string.h" 2519370Spst#include "symtab.h" 2619370Spst#include "gdbtypes.h" 2719370Spst#include "expression.h" 2819370Spst#include "value.h" 2919370Spst#include "valprint.h" 3019370Spst#include "language.h" 3119370Spst#include "c-lang.h" 3298944Sobrien#include "cp-abi.h" 33130803Smarcel#include "target.h" 3498944Sobrien 3519370Spst 3698944Sobrien/* Print function pointer with inferior address ADDRESS onto stdio 3798944Sobrien stream STREAM. */ 3898944Sobrien 3998944Sobrienstatic void 4098944Sobrienprint_function_pointer_address (CORE_ADDR address, struct ui_file *stream) 4198944Sobrien{ 42130803Smarcel CORE_ADDR func_addr = gdbarch_convert_from_func_ptr_addr (current_gdbarch, 43130803Smarcel address, 44130803Smarcel ¤t_target); 4598944Sobrien 4698944Sobrien /* If the function pointer is represented by a description, print the 4798944Sobrien address of the description. */ 4898944Sobrien if (addressprint && func_addr != address) 4998944Sobrien { 5098944Sobrien fputs_filtered ("@", stream); 5198944Sobrien print_address_numeric (address, 1, stream); 5298944Sobrien fputs_filtered (": ", stream); 5398944Sobrien } 5498944Sobrien print_address_demangle (func_addr, stream, demangle); 5598944Sobrien} 5698944Sobrien 5798944Sobrien 5819370Spst/* Print data of type TYPE located at VALADDR (within GDB), which came from 5919370Spst the inferior at address ADDRESS, onto stdio stream STREAM according to 6019370Spst FORMAT (a letter or 0 for natural format). The data at VALADDR is in 6119370Spst target byte order. 6219370Spst 6319370Spst If the data are a string pointer, returns the number of string characters 6419370Spst printed. 6519370Spst 6619370Spst If DEREF_REF is nonzero, then dereference references, otherwise just print 6719370Spst them like pointers. 6819370Spst 6919370Spst The PRETTY parameter controls prettyprinting. */ 7019370Spst 7119370Spstint 7298944Sobrienc_val_print (struct type *type, char *valaddr, int embedded_offset, 7398944Sobrien CORE_ADDR address, struct ui_file *stream, int format, 7498944Sobrien int deref_ref, int recurse, enum val_prettyprint pretty) 7519370Spst{ 76130803Smarcel unsigned int i = 0; /* Number of characters printed */ 7719370Spst unsigned len; 7819370Spst struct type *elttype; 7919370Spst unsigned eltlen; 8019370Spst LONGEST val; 8119370Spst CORE_ADDR addr; 8219370Spst 8319370Spst CHECK_TYPEDEF (type); 8419370Spst switch (TYPE_CODE (type)) 8519370Spst { 8619370Spst case TYPE_CODE_ARRAY: 8746283Sdfr elttype = check_typedef (TYPE_TARGET_TYPE (type)); 8819370Spst if (TYPE_LENGTH (type) > 0 && TYPE_LENGTH (TYPE_TARGET_TYPE (type)) > 0) 8919370Spst { 9019370Spst eltlen = TYPE_LENGTH (elttype); 9119370Spst len = TYPE_LENGTH (type) / eltlen; 9219370Spst if (prettyprint_arrays) 9319370Spst { 9419370Spst print_spaces_filtered (2 + 2 * recurse, stream); 9519370Spst } 9619370Spst /* For an array of chars, print with string syntax. */ 9719370Spst if (eltlen == 1 && 9819370Spst ((TYPE_CODE (elttype) == TYPE_CODE_INT) 9919370Spst || ((current_language->la_language == language_m2) 10019370Spst && (TYPE_CODE (elttype) == TYPE_CODE_CHAR))) 10119370Spst && (format == 0 || format == 's')) 10219370Spst { 10319370Spst /* If requested, look for the first null char and only print 10498944Sobrien elements up to it. */ 10519370Spst if (stop_print_at_null) 10619370Spst { 10798944Sobrien unsigned int temp_len; 10898944Sobrien 10919370Spst /* Look for a NULL char. */ 11019370Spst for (temp_len = 0; 11146283Sdfr (valaddr + embedded_offset)[temp_len] 11219370Spst && temp_len < len && temp_len < print_max; 11319370Spst temp_len++); 11419370Spst len = temp_len; 11519370Spst } 11698944Sobrien 11746283Sdfr LA_PRINT_STRING (stream, valaddr + embedded_offset, len, eltlen, 0); 11819370Spst i = len; 11919370Spst } 12019370Spst else 12119370Spst { 12219370Spst fprintf_filtered (stream, "{"); 12319370Spst /* If this is a virtual function table, print the 0th 12498944Sobrien entry specially, and the rest of the members normally. */ 12519370Spst if (cp_is_vtbl_ptr_type (elttype)) 12619370Spst { 12719370Spst i = 1; 12819370Spst fprintf_filtered (stream, "%d vtable entries", len - 1); 12919370Spst } 13019370Spst else 13119370Spst { 13219370Spst i = 0; 13319370Spst } 13446283Sdfr val_print_array_elements (type, valaddr + embedded_offset, address, stream, 13598944Sobrien format, deref_ref, recurse, pretty, i); 13619370Spst fprintf_filtered (stream, "}"); 13719370Spst } 13819370Spst break; 13919370Spst } 14019370Spst /* Array of unspecified length: treat like pointer to first elt. */ 14119370Spst addr = address; 14219370Spst goto print_unpacked_pointer; 14319370Spst 14419370Spst case TYPE_CODE_PTR: 14519370Spst if (format && format != 's') 14619370Spst { 14746283Sdfr print_scalar_formatted (valaddr + embedded_offset, type, format, 0, stream); 14819370Spst break; 14919370Spst } 15098944Sobrien if (vtblprint && cp_is_vtbl_ptr_type (type)) 15119370Spst { 15298944Sobrien /* Print the unmangled name if desired. */ 15319370Spst /* Print vtable entry - we only get here if we ARE using 15419370Spst -fvtable_thunks. (Otherwise, look under TYPE_CODE_STRUCT.) */ 15598944Sobrien CORE_ADDR addr 15698944Sobrien = extract_typed_address (valaddr + embedded_offset, type); 15798944Sobrien print_function_pointer_address (addr, stream); 15819370Spst break; 15919370Spst } 16019370Spst elttype = check_typedef (TYPE_TARGET_TYPE (type)); 16119370Spst if (TYPE_CODE (elttype) == TYPE_CODE_METHOD) 16219370Spst { 16346283Sdfr cp_print_class_method (valaddr + embedded_offset, type, stream); 16419370Spst } 16519370Spst else if (TYPE_CODE (elttype) == TYPE_CODE_MEMBER) 16619370Spst { 16746283Sdfr cp_print_class_member (valaddr + embedded_offset, 16819370Spst TYPE_DOMAIN_TYPE (TYPE_TARGET_TYPE (type)), 16919370Spst stream, "&"); 17019370Spst } 17119370Spst else 17219370Spst { 17346283Sdfr addr = unpack_pointer (type, valaddr + embedded_offset); 17419370Spst print_unpacked_pointer: 17519370Spst 17619370Spst if (TYPE_CODE (elttype) == TYPE_CODE_FUNC) 17719370Spst { 17819370Spst /* Try to print what function it points to. */ 17998944Sobrien print_function_pointer_address (addr, stream); 18019370Spst /* Return value is irrelevant except for string pointers. */ 18119370Spst return (0); 18219370Spst } 18319370Spst 18419370Spst if (addressprint && format != 's') 18519370Spst { 18619370Spst print_address_numeric (addr, 1, stream); 18719370Spst } 18819370Spst 18919370Spst /* For a pointer to char or unsigned char, also print the string 19019370Spst pointed to, unless pointer is null. */ 19146283Sdfr /* FIXME: need to handle wchar_t here... */ 19246283Sdfr 19319370Spst if (TYPE_LENGTH (elttype) == 1 19419370Spst && TYPE_CODE (elttype) == TYPE_CODE_INT 19519370Spst && (format == 0 || format == 's') 19619370Spst && addr != 0) 19719370Spst { 19846283Sdfr i = val_print_string (addr, -1, TYPE_LENGTH (elttype), stream); 19919370Spst } 20098944Sobrien else if (cp_is_vtbl_member (type)) 20198944Sobrien { 20219370Spst /* print vtbl's nicely */ 20346283Sdfr CORE_ADDR vt_address = unpack_pointer (type, valaddr + embedded_offset); 20419370Spst 20519370Spst struct minimal_symbol *msymbol = 20698944Sobrien lookup_minimal_symbol_by_pc (vt_address); 20719370Spst if ((msymbol != NULL) && 20819370Spst (vt_address == SYMBOL_VALUE_ADDRESS (msymbol))) 20919370Spst { 21019370Spst fputs_filtered (" <", stream); 211130803Smarcel fputs_filtered (SYMBOL_PRINT_NAME (msymbol), stream); 21219370Spst fputs_filtered (">", stream); 21319370Spst } 21419370Spst if (vt_address && vtblprint) 21598944Sobrien { 21698944Sobrien struct value *vt_val; 21798944Sobrien struct symbol *wsym = (struct symbol *) NULL; 21898944Sobrien struct type *wtype; 21998944Sobrien struct block *block = (struct block *) NULL; 22019370Spst int is_this_fld; 22119370Spst 22219370Spst if (msymbol != NULL) 223130803Smarcel wsym = lookup_symbol (DEPRECATED_SYMBOL_NAME (msymbol), block, 224130803Smarcel VAR_DOMAIN, &is_this_fld, NULL); 22598944Sobrien 22619370Spst if (wsym) 22719370Spst { 22898944Sobrien wtype = SYMBOL_TYPE (wsym); 22919370Spst } 23019370Spst else 23119370Spst { 23298944Sobrien wtype = TYPE_TARGET_TYPE (type); 23319370Spst } 23446283Sdfr vt_val = value_at (wtype, vt_address, NULL); 235242936Semaste common_val_print (vt_val, stream, format, 236242936Semaste deref_ref, recurse + 1, pretty); 23719370Spst if (pretty) 23819370Spst { 23919370Spst fprintf_filtered (stream, "\n"); 24019370Spst print_spaces_filtered (2 + 2 * recurse, stream); 24119370Spst } 24298944Sobrien } 24398944Sobrien } 24419370Spst 24519370Spst /* Return number of characters printed, including the terminating 24619370Spst '\0' if we reached the end. val_print_string takes care including 24719370Spst the terminating '\0' if necessary. */ 24819370Spst return i; 24919370Spst } 25019370Spst break; 25119370Spst 25219370Spst case TYPE_CODE_MEMBER: 25319370Spst error ("not implemented: member type in c_val_print"); 25419370Spst break; 25519370Spst 25619370Spst case TYPE_CODE_REF: 25719370Spst elttype = check_typedef (TYPE_TARGET_TYPE (type)); 25819370Spst if (TYPE_CODE (elttype) == TYPE_CODE_MEMBER) 25998944Sobrien { 26046283Sdfr cp_print_class_member (valaddr + embedded_offset, 26119370Spst TYPE_DOMAIN_TYPE (elttype), 26219370Spst stream, ""); 26319370Spst break; 26419370Spst } 26519370Spst if (addressprint) 26698944Sobrien { 26798944Sobrien CORE_ADDR addr 26898944Sobrien = extract_typed_address (valaddr + embedded_offset, type); 26919370Spst fprintf_filtered (stream, "@"); 27098944Sobrien print_address_numeric (addr, 1, stream); 27119370Spst if (deref_ref) 27219370Spst fputs_filtered (": ", stream); 27398944Sobrien } 27419370Spst /* De-reference the reference. */ 27519370Spst if (deref_ref) 27619370Spst { 27719370Spst if (TYPE_CODE (elttype) != TYPE_CODE_UNDEF) 27819370Spst { 27998944Sobrien struct value *deref_val = 28098944Sobrien value_at 28198944Sobrien (TYPE_TARGET_TYPE (type), 28298944Sobrien unpack_pointer (lookup_pointer_type (builtin_type_void), 28398944Sobrien valaddr + embedded_offset), 28498944Sobrien NULL); 285242936Semaste common_val_print (deref_val, stream, format, deref_ref, 286242936Semaste recurse, pretty); 28719370Spst } 28819370Spst else 28919370Spst fputs_filtered ("???", stream); 29019370Spst } 29119370Spst break; 29219370Spst 29319370Spst case TYPE_CODE_UNION: 29419370Spst if (recurse && !unionprint) 29519370Spst { 29619370Spst fprintf_filtered (stream, "{...}"); 29719370Spst break; 29819370Spst } 29919370Spst /* Fall through. */ 30019370Spst case TYPE_CODE_STRUCT: 30198944Sobrien /*FIXME: Abstract this away */ 30298944Sobrien if (vtblprint && cp_is_vtbl_ptr_type (type)) 30319370Spst { 30498944Sobrien /* Print the unmangled name if desired. */ 30519370Spst /* Print vtable entry - we only get here if NOT using 30619370Spst -fvtable_thunks. (Otherwise, look under TYPE_CODE_PTR.) */ 30798944Sobrien int offset = (embedded_offset + 30898944Sobrien TYPE_FIELD_BITPOS (type, VTBL_FNADDR_OFFSET) / 8); 30998944Sobrien struct type *field_type = TYPE_FIELD_TYPE (type, VTBL_FNADDR_OFFSET); 31098944Sobrien CORE_ADDR addr 31198944Sobrien = extract_typed_address (valaddr + offset, field_type); 31298944Sobrien 31398944Sobrien print_function_pointer_address (addr, stream); 31419370Spst } 31519370Spst else 31646283Sdfr cp_print_value_fields (type, type, valaddr, embedded_offset, address, stream, format, 31719370Spst recurse, pretty, NULL, 0); 31819370Spst break; 31919370Spst 32019370Spst case TYPE_CODE_ENUM: 32119370Spst if (format) 32219370Spst { 32346283Sdfr print_scalar_formatted (valaddr + embedded_offset, type, format, 0, stream); 32419370Spst break; 32519370Spst } 32619370Spst len = TYPE_NFIELDS (type); 32746283Sdfr val = unpack_long (type, valaddr + embedded_offset); 32819370Spst for (i = 0; i < len; i++) 32919370Spst { 33019370Spst QUIT; 33119370Spst if (val == TYPE_FIELD_BITPOS (type, i)) 33219370Spst { 33319370Spst break; 33419370Spst } 33519370Spst } 33619370Spst if (i < len) 33719370Spst { 33819370Spst fputs_filtered (TYPE_FIELD_NAME (type, i), stream); 33919370Spst } 34019370Spst else 34119370Spst { 34219370Spst print_longest (stream, 'd', 0, val); 34319370Spst } 34419370Spst break; 34519370Spst 34619370Spst case TYPE_CODE_FUNC: 34719370Spst if (format) 34819370Spst { 34946283Sdfr print_scalar_formatted (valaddr + embedded_offset, type, format, 0, stream); 35019370Spst break; 35119370Spst } 35219370Spst /* FIXME, we should consider, at least for ANSI C language, eliminating 35398944Sobrien the distinction made between FUNCs and POINTERs to FUNCs. */ 35419370Spst fprintf_filtered (stream, "{"); 35519370Spst type_print (type, "", stream, -1); 35619370Spst fprintf_filtered (stream, "} "); 35719370Spst /* Try to print what function it points to, and its address. */ 35819370Spst print_address_demangle (address, stream, demangle); 35919370Spst break; 36019370Spst 36119370Spst case TYPE_CODE_BOOL: 36219370Spst format = format ? format : output_format; 36319370Spst if (format) 36446283Sdfr print_scalar_formatted (valaddr + embedded_offset, type, format, 0, stream); 36519370Spst else 36619370Spst { 36746283Sdfr val = unpack_long (type, valaddr + embedded_offset); 36819370Spst if (val == 0) 36919370Spst fputs_filtered ("false", stream); 37019370Spst else if (val == 1) 37119370Spst fputs_filtered ("true", stream); 37219370Spst else 37319370Spst print_longest (stream, 'd', 0, val); 37419370Spst } 37519370Spst break; 37619370Spst 37719370Spst case TYPE_CODE_RANGE: 37819370Spst /* FIXME: create_range_type does not set the unsigned bit in a 37998944Sobrien range type (I think it probably should copy it from the target 38098944Sobrien type), so we won't print values which are too large to 38198944Sobrien fit in a signed integer correctly. */ 38219370Spst /* FIXME: Doesn't handle ranges of enums correctly. (Can't just 38398944Sobrien print with the target type, though, because the size of our type 38498944Sobrien and the target type might differ). */ 38519370Spst /* FALLTHROUGH */ 38619370Spst 38719370Spst case TYPE_CODE_INT: 38819370Spst format = format ? format : output_format; 38919370Spst if (format) 39019370Spst { 39146283Sdfr print_scalar_formatted (valaddr + embedded_offset, type, format, 0, stream); 39219370Spst } 39319370Spst else 39419370Spst { 39546283Sdfr val_print_type_code_int (type, valaddr + embedded_offset, stream); 39619370Spst /* C and C++ has no single byte int type, char is used instead. 39719370Spst Since we don't know whether the value is really intended to 39819370Spst be used as an integer or a character, print the character 39919370Spst equivalent as well. */ 40019370Spst if (TYPE_LENGTH (type) == 1) 40119370Spst { 40219370Spst fputs_filtered (" ", stream); 40346283Sdfr LA_PRINT_CHAR ((unsigned char) unpack_long (type, valaddr + embedded_offset), 40419370Spst stream); 40519370Spst } 40619370Spst } 40719370Spst break; 40819370Spst 40919370Spst case TYPE_CODE_CHAR: 41019370Spst format = format ? format : output_format; 41119370Spst if (format) 41219370Spst { 41346283Sdfr print_scalar_formatted (valaddr + embedded_offset, type, format, 0, stream); 41419370Spst } 41519370Spst else 41619370Spst { 41798944Sobrien val = unpack_long (type, valaddr + embedded_offset); 41898944Sobrien if (TYPE_UNSIGNED (type)) 41998944Sobrien fprintf_filtered (stream, "%u", (unsigned int) val); 42098944Sobrien else 42198944Sobrien fprintf_filtered (stream, "%d", (int) val); 42219370Spst fputs_filtered (" ", stream); 42398944Sobrien LA_PRINT_CHAR ((unsigned char) val, stream); 42419370Spst } 42519370Spst break; 42619370Spst 42719370Spst case TYPE_CODE_FLT: 42819370Spst if (format) 42919370Spst { 43046283Sdfr print_scalar_formatted (valaddr + embedded_offset, type, format, 0, stream); 43119370Spst } 43219370Spst else 43319370Spst { 43446283Sdfr print_floating (valaddr + embedded_offset, type, stream); 43519370Spst } 43619370Spst break; 43719370Spst 43846283Sdfr case TYPE_CODE_METHOD: 43998944Sobrien { 44098944Sobrien struct value *v = value_at (type, address, NULL); 44198944Sobrien cp_print_class_method (VALUE_CONTENTS (value_addr (v)), 44298944Sobrien lookup_pointer_type (type), stream); 44398944Sobrien break; 44498944Sobrien } 44546283Sdfr 44619370Spst case TYPE_CODE_VOID: 44719370Spst fprintf_filtered (stream, "void"); 44819370Spst break; 44919370Spst 45019370Spst case TYPE_CODE_ERROR: 45119370Spst fprintf_filtered (stream, "<error type>"); 45219370Spst break; 45319370Spst 45419370Spst case TYPE_CODE_UNDEF: 45519370Spst /* This happens (without TYPE_FLAG_STUB set) on systems which don't use 45698944Sobrien dbx xrefs (NO_DBX_XREFS in gcc) if a file has a "struct foo *bar" 45798944Sobrien and no complete type for struct foo in that file. */ 45819370Spst fprintf_filtered (stream, "<incomplete type>"); 45919370Spst break; 46019370Spst 46198944Sobrien case TYPE_CODE_COMPLEX: 46298944Sobrien if (format) 46398944Sobrien print_scalar_formatted (valaddr + embedded_offset, 46498944Sobrien TYPE_TARGET_TYPE (type), 46598944Sobrien format, 0, stream); 46698944Sobrien else 46798944Sobrien print_floating (valaddr + embedded_offset, TYPE_TARGET_TYPE (type), 46898944Sobrien stream); 46998944Sobrien fprintf_filtered (stream, " + "); 47098944Sobrien if (format) 47198944Sobrien print_scalar_formatted (valaddr + embedded_offset 47298944Sobrien + TYPE_LENGTH (TYPE_TARGET_TYPE (type)), 47398944Sobrien TYPE_TARGET_TYPE (type), 47498944Sobrien format, 0, stream); 47598944Sobrien else 47698944Sobrien print_floating (valaddr + embedded_offset 47798944Sobrien + TYPE_LENGTH (TYPE_TARGET_TYPE (type)), 47898944Sobrien TYPE_TARGET_TYPE (type), 47998944Sobrien stream); 48098944Sobrien fprintf_filtered (stream, " * I"); 48198944Sobrien break; 48298944Sobrien 48319370Spst default: 48419370Spst error ("Invalid C/C++ type code %d in symbol table.", TYPE_CODE (type)); 48519370Spst } 48619370Spst gdb_flush (stream); 48719370Spst return (0); 48819370Spst} 48919370Spst 49019370Spstint 49198944Sobrienc_value_print (struct value *val, struct ui_file *stream, int format, 49298944Sobrien enum val_prettyprint pretty) 49319370Spst{ 49419370Spst struct type *type = VALUE_TYPE (val); 49598944Sobrien struct type *real_type; 49646283Sdfr int full, top, using_enc; 49798944Sobrien 49819370Spst /* If it is a pointer, indicate what it points to. 49919370Spst 50019370Spst Print type also if it is a reference. 50119370Spst 50219370Spst C++: if it is a member pointer, we will take care 50319370Spst of that when we print it. */ 50419370Spst if (TYPE_CODE (type) == TYPE_CODE_PTR || 50519370Spst TYPE_CODE (type) == TYPE_CODE_REF) 50619370Spst { 50719370Spst /* Hack: remove (char *) for char strings. Their 50898944Sobrien type is indicated by the quoted string anyway. */ 50919370Spst if (TYPE_CODE (type) == TYPE_CODE_PTR && 51019370Spst TYPE_NAME (type) == NULL && 51119370Spst TYPE_NAME (TYPE_TARGET_TYPE (type)) != NULL && 512130803Smarcel strcmp (TYPE_NAME (TYPE_TARGET_TYPE (type)), "char") == 0) 51319370Spst { 51419370Spst /* Print nothing */ 51519370Spst } 51646283Sdfr else if (objectprint && (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_CLASS)) 51798944Sobrien { 51898944Sobrien 51998944Sobrien if (TYPE_CODE(type) == TYPE_CODE_REF) 52098944Sobrien { 52198944Sobrien /* Copy value, change to pointer, so we don't get an 52298944Sobrien * error about a non-pointer type in value_rtti_target_type 52398944Sobrien */ 52498944Sobrien struct value *temparg; 52598944Sobrien temparg=value_copy(val); 52698944Sobrien VALUE_TYPE (temparg) = lookup_pointer_type(TYPE_TARGET_TYPE(type)); 52798944Sobrien val=temparg; 52898944Sobrien } 52998944Sobrien /* Pointer to class, check real type of object */ 53046283Sdfr fprintf_filtered (stream, "("); 53198944Sobrien real_type = value_rtti_target_type (val, &full, &top, &using_enc); 53298944Sobrien if (real_type) 53398944Sobrien { 53498944Sobrien /* RTTI entry found */ 53598944Sobrien if (TYPE_CODE (type) == TYPE_CODE_PTR) 53698944Sobrien { 53798944Sobrien /* create a pointer type pointing to the real type */ 53898944Sobrien type = lookup_pointer_type (real_type); 53998944Sobrien } 54098944Sobrien else 54198944Sobrien { 54298944Sobrien /* create a reference type referencing the real type */ 54398944Sobrien type = lookup_reference_type (real_type); 54498944Sobrien } 54598944Sobrien /* JYG: Need to adjust pointer value. */ 54698944Sobrien val->aligner.contents[0] -= top; 54798944Sobrien 54898944Sobrien /* Note: When we look up RTTI entries, we don't get any 54998944Sobrien information on const or volatile attributes */ 55046283Sdfr } 55198944Sobrien type_print (type, "", stream, -1); 55246283Sdfr fprintf_filtered (stream, ") "); 55398944Sobrien } 55419370Spst else 55519370Spst { 55698944Sobrien /* normal case */ 55719370Spst fprintf_filtered (stream, "("); 55819370Spst type_print (type, "", stream, -1); 55919370Spst fprintf_filtered (stream, ") "); 56019370Spst } 56119370Spst } 56246283Sdfr if (objectprint && (TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_CLASS)) 56346283Sdfr { 56446283Sdfr /* Attempt to determine real type of object */ 56546283Sdfr real_type = value_rtti_type (val, &full, &top, &using_enc); 56698944Sobrien if (real_type) 56798944Sobrien { 56898944Sobrien /* We have RTTI information, so use it */ 56998944Sobrien val = value_full_object (val, real_type, full, top, using_enc); 57098944Sobrien fprintf_filtered (stream, "(%s%s) ", 57198944Sobrien TYPE_NAME (real_type), 57298944Sobrien full ? "" : " [incomplete object]"); 57398944Sobrien /* Print out object: enclosing type is same as real_type if full */ 57498944Sobrien return val_print (VALUE_ENCLOSING_TYPE (val), VALUE_CONTENTS_ALL (val), 0, 57598944Sobrien VALUE_ADDRESS (val), stream, format, 1, 0, pretty); 57698944Sobrien /* Note: When we look up RTTI entries, we don't get any information on 57798944Sobrien const or volatile attributes */ 57898944Sobrien } 57946283Sdfr else if (type != VALUE_ENCLOSING_TYPE (val)) 58098944Sobrien { 58198944Sobrien /* No RTTI information, so let's do our best */ 58298944Sobrien fprintf_filtered (stream, "(%s ?) ", 58398944Sobrien TYPE_NAME (VALUE_ENCLOSING_TYPE (val))); 58498944Sobrien return val_print (VALUE_ENCLOSING_TYPE (val), VALUE_CONTENTS_ALL (val), 0, 58598944Sobrien VALUE_ADDRESS (val), stream, format, 1, 0, pretty); 58698944Sobrien } 58746283Sdfr /* Otherwise, we end up at the return outside this "if" */ 58846283Sdfr } 58998944Sobrien 590130803Smarcel return val_print (type, VALUE_CONTENTS_ALL (val), 591130803Smarcel VALUE_EMBEDDED_OFFSET (val), 592130803Smarcel VALUE_ADDRESS (val) + VALUE_OFFSET (val), 59346283Sdfr stream, format, 1, 0, pretty); 59419370Spst} 595