15796c8dcSSimon Schubert /* Support for printing Pascal values for GDB, the GNU debugger. 25796c8dcSSimon Schubert 3*cf7f2e2dSJohn Marino Copyright (C) 2000, 2001, 2003, 2005, 2006, 2007, 2008, 2009, 2010 45796c8dcSSimon Schubert Free Software Foundation, Inc. 55796c8dcSSimon Schubert 65796c8dcSSimon Schubert This file is part of GDB. 75796c8dcSSimon Schubert 85796c8dcSSimon Schubert This program is free software; you can redistribute it and/or modify 95796c8dcSSimon Schubert it under the terms of the GNU General Public License as published by 105796c8dcSSimon Schubert the Free Software Foundation; either version 3 of the License, or 115796c8dcSSimon Schubert (at your option) any later version. 125796c8dcSSimon Schubert 135796c8dcSSimon Schubert This program is distributed in the hope that it will be useful, 145796c8dcSSimon Schubert but WITHOUT ANY WARRANTY; without even the implied warranty of 155796c8dcSSimon Schubert MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 165796c8dcSSimon Schubert GNU General Public License for more details. 175796c8dcSSimon Schubert 185796c8dcSSimon Schubert You should have received a copy of the GNU General Public License 195796c8dcSSimon Schubert along with this program. If not, see <http://www.gnu.org/licenses/>. */ 205796c8dcSSimon Schubert 215796c8dcSSimon Schubert /* This file is derived from c-valprint.c */ 225796c8dcSSimon Schubert 235796c8dcSSimon Schubert #include "defs.h" 245796c8dcSSimon Schubert #include "gdb_obstack.h" 255796c8dcSSimon Schubert #include "symtab.h" 265796c8dcSSimon Schubert #include "gdbtypes.h" 275796c8dcSSimon Schubert #include "expression.h" 285796c8dcSSimon Schubert #include "value.h" 295796c8dcSSimon Schubert #include "command.h" 305796c8dcSSimon Schubert #include "gdbcmd.h" 315796c8dcSSimon Schubert #include "gdbcore.h" 325796c8dcSSimon Schubert #include "demangle.h" 335796c8dcSSimon Schubert #include "valprint.h" 345796c8dcSSimon Schubert #include "typeprint.h" 355796c8dcSSimon Schubert #include "language.h" 365796c8dcSSimon Schubert #include "target.h" 375796c8dcSSimon Schubert #include "annotate.h" 385796c8dcSSimon Schubert #include "p-lang.h" 395796c8dcSSimon Schubert #include "cp-abi.h" 405796c8dcSSimon Schubert #include "cp-support.h" 415796c8dcSSimon Schubert 425796c8dcSSimon Schubert 435796c8dcSSimon Schubert 445796c8dcSSimon Schubert 455796c8dcSSimon Schubert /* Print data of type TYPE located at VALADDR (within GDB), which came from 465796c8dcSSimon Schubert the inferior at address ADDRESS, onto stdio stream STREAM according to 475796c8dcSSimon Schubert OPTIONS. The data at VALADDR is in target byte order. 485796c8dcSSimon Schubert 495796c8dcSSimon Schubert If the data are a string pointer, returns the number of string characters 505796c8dcSSimon Schubert printed. */ 515796c8dcSSimon Schubert 525796c8dcSSimon Schubert 535796c8dcSSimon Schubert int 545796c8dcSSimon Schubert pascal_val_print (struct type *type, const gdb_byte *valaddr, 555796c8dcSSimon Schubert int embedded_offset, CORE_ADDR address, 565796c8dcSSimon Schubert struct ui_file *stream, int recurse, 57*cf7f2e2dSJohn Marino const struct value *original_value, 585796c8dcSSimon Schubert const struct value_print_options *options) 595796c8dcSSimon Schubert { 605796c8dcSSimon Schubert struct gdbarch *gdbarch = get_type_arch (type); 615796c8dcSSimon Schubert enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 625796c8dcSSimon Schubert unsigned int i = 0; /* Number of characters printed */ 635796c8dcSSimon Schubert unsigned len; 64*cf7f2e2dSJohn Marino LONGEST low_bound, high_bound; 655796c8dcSSimon Schubert struct type *elttype; 665796c8dcSSimon Schubert unsigned eltlen; 675796c8dcSSimon Schubert int length_pos, length_size, string_pos; 685796c8dcSSimon Schubert struct type *char_type; 695796c8dcSSimon Schubert LONGEST val; 705796c8dcSSimon Schubert CORE_ADDR addr; 715796c8dcSSimon Schubert 725796c8dcSSimon Schubert CHECK_TYPEDEF (type); 735796c8dcSSimon Schubert switch (TYPE_CODE (type)) 745796c8dcSSimon Schubert { 755796c8dcSSimon Schubert case TYPE_CODE_ARRAY: 76*cf7f2e2dSJohn Marino if (get_array_bounds (type, &low_bound, &high_bound)) 775796c8dcSSimon Schubert { 78*cf7f2e2dSJohn Marino len = high_bound - low_bound + 1; 795796c8dcSSimon Schubert elttype = check_typedef (TYPE_TARGET_TYPE (type)); 805796c8dcSSimon Schubert eltlen = TYPE_LENGTH (elttype); 815796c8dcSSimon Schubert if (options->prettyprint_arrays) 825796c8dcSSimon Schubert { 835796c8dcSSimon Schubert print_spaces_filtered (2 + 2 * recurse, stream); 845796c8dcSSimon Schubert } 85*cf7f2e2dSJohn Marino /* If 's' format is used, try to print out as string. 86*cf7f2e2dSJohn Marino If no format is given, print as string if element type 87*cf7f2e2dSJohn Marino is of TYPE_CODE_CHAR and element size is 1,2 or 4. */ 88*cf7f2e2dSJohn Marino if (options->format == 's' 89*cf7f2e2dSJohn Marino || ((eltlen == 1 || eltlen == 2 || eltlen == 4) 90*cf7f2e2dSJohn Marino && TYPE_CODE (elttype) == TYPE_CODE_CHAR 91*cf7f2e2dSJohn Marino && options->format == 0)) 925796c8dcSSimon Schubert { 935796c8dcSSimon Schubert /* If requested, look for the first null char and only print 945796c8dcSSimon Schubert elements up to it. */ 955796c8dcSSimon Schubert if (options->stop_print_at_null) 965796c8dcSSimon Schubert { 975796c8dcSSimon Schubert unsigned int temp_len; 985796c8dcSSimon Schubert 995796c8dcSSimon Schubert /* Look for a NULL char. */ 1005796c8dcSSimon Schubert for (temp_len = 0; 1015796c8dcSSimon Schubert extract_unsigned_integer (valaddr + embedded_offset + 1025796c8dcSSimon Schubert temp_len * eltlen, eltlen, 1035796c8dcSSimon Schubert byte_order) 1045796c8dcSSimon Schubert && temp_len < len && temp_len < options->print_max; 1055796c8dcSSimon Schubert temp_len++); 1065796c8dcSSimon Schubert len = temp_len; 1075796c8dcSSimon Schubert } 1085796c8dcSSimon Schubert 1095796c8dcSSimon Schubert LA_PRINT_STRING (stream, TYPE_TARGET_TYPE (type), 110*cf7f2e2dSJohn Marino valaddr + embedded_offset, len, NULL, 0, 1115796c8dcSSimon Schubert options); 1125796c8dcSSimon Schubert i = len; 1135796c8dcSSimon Schubert } 1145796c8dcSSimon Schubert else 1155796c8dcSSimon Schubert { 1165796c8dcSSimon Schubert fprintf_filtered (stream, "{"); 1175796c8dcSSimon Schubert /* If this is a virtual function table, print the 0th 1185796c8dcSSimon Schubert entry specially, and the rest of the members normally. */ 1195796c8dcSSimon Schubert if (pascal_object_is_vtbl_ptr_type (elttype)) 1205796c8dcSSimon Schubert { 1215796c8dcSSimon Schubert i = 1; 1225796c8dcSSimon Schubert fprintf_filtered (stream, "%d vtable entries", len - 1); 1235796c8dcSSimon Schubert } 1245796c8dcSSimon Schubert else 1255796c8dcSSimon Schubert { 1265796c8dcSSimon Schubert i = 0; 1275796c8dcSSimon Schubert } 1285796c8dcSSimon Schubert val_print_array_elements (type, valaddr + embedded_offset, address, stream, 129*cf7f2e2dSJohn Marino recurse, original_value, options, i); 1305796c8dcSSimon Schubert fprintf_filtered (stream, "}"); 1315796c8dcSSimon Schubert } 1325796c8dcSSimon Schubert break; 1335796c8dcSSimon Schubert } 1345796c8dcSSimon Schubert /* Array of unspecified length: treat like pointer to first elt. */ 1355796c8dcSSimon Schubert addr = address; 1365796c8dcSSimon Schubert goto print_unpacked_pointer; 1375796c8dcSSimon Schubert 1385796c8dcSSimon Schubert case TYPE_CODE_PTR: 1395796c8dcSSimon Schubert if (options->format && options->format != 's') 1405796c8dcSSimon Schubert { 1415796c8dcSSimon Schubert print_scalar_formatted (valaddr + embedded_offset, type, 1425796c8dcSSimon Schubert options, 0, stream); 1435796c8dcSSimon Schubert break; 1445796c8dcSSimon Schubert } 1455796c8dcSSimon Schubert if (options->vtblprint && pascal_object_is_vtbl_ptr_type (type)) 1465796c8dcSSimon Schubert { 1475796c8dcSSimon Schubert /* Print the unmangled name if desired. */ 1485796c8dcSSimon Schubert /* Print vtable entry - we only get here if we ARE using 1495796c8dcSSimon Schubert -fvtable_thunks. (Otherwise, look under TYPE_CODE_STRUCT.) */ 1505796c8dcSSimon Schubert /* Extract the address, assume that it is unsigned. */ 1515796c8dcSSimon Schubert addr = extract_unsigned_integer (valaddr + embedded_offset, 1525796c8dcSSimon Schubert TYPE_LENGTH (type), byte_order); 1535796c8dcSSimon Schubert print_address_demangle (gdbarch, addr, stream, demangle); 1545796c8dcSSimon Schubert break; 1555796c8dcSSimon Schubert } 1565796c8dcSSimon Schubert elttype = check_typedef (TYPE_TARGET_TYPE (type)); 157*cf7f2e2dSJohn Marino 1585796c8dcSSimon Schubert addr = unpack_pointer (type, valaddr + embedded_offset); 1595796c8dcSSimon Schubert print_unpacked_pointer: 1605796c8dcSSimon Schubert elttype = check_typedef (TYPE_TARGET_TYPE (type)); 1615796c8dcSSimon Schubert 1625796c8dcSSimon Schubert if (TYPE_CODE (elttype) == TYPE_CODE_FUNC) 1635796c8dcSSimon Schubert { 1645796c8dcSSimon Schubert /* Try to print what function it points to. */ 1655796c8dcSSimon Schubert print_address_demangle (gdbarch, addr, stream, demangle); 1665796c8dcSSimon Schubert /* Return value is irrelevant except for string pointers. */ 1675796c8dcSSimon Schubert return (0); 1685796c8dcSSimon Schubert } 1695796c8dcSSimon Schubert 1705796c8dcSSimon Schubert if (options->addressprint && options->format != 's') 1715796c8dcSSimon Schubert { 1725796c8dcSSimon Schubert fputs_filtered (paddress (gdbarch, addr), stream); 1735796c8dcSSimon Schubert } 1745796c8dcSSimon Schubert 1755796c8dcSSimon Schubert /* For a pointer to char or unsigned char, also print the string 1765796c8dcSSimon Schubert pointed to, unless pointer is null. */ 1775796c8dcSSimon Schubert if (((TYPE_LENGTH (elttype) == 1 1785796c8dcSSimon Schubert && (TYPE_CODE (elttype) == TYPE_CODE_INT 1795796c8dcSSimon Schubert || TYPE_CODE (elttype) == TYPE_CODE_CHAR)) 1805796c8dcSSimon Schubert || ((TYPE_LENGTH (elttype) == 2 || TYPE_LENGTH (elttype) == 4) 1815796c8dcSSimon Schubert && TYPE_CODE (elttype) == TYPE_CODE_CHAR)) 1825796c8dcSSimon Schubert && (options->format == 0 || options->format == 's') 1835796c8dcSSimon Schubert && addr != 0) 1845796c8dcSSimon Schubert { 1855796c8dcSSimon Schubert /* no wide string yet */ 1865796c8dcSSimon Schubert i = val_print_string (elttype, addr, -1, stream, options); 1875796c8dcSSimon Schubert } 1885796c8dcSSimon Schubert /* also for pointers to pascal strings */ 1895796c8dcSSimon Schubert /* Note: this is Free Pascal specific: 1905796c8dcSSimon Schubert as GDB does not recognize stabs pascal strings 1915796c8dcSSimon Schubert Pascal strings are mapped to records 1925796c8dcSSimon Schubert with lowercase names PM */ 1935796c8dcSSimon Schubert if (is_pascal_string_type (elttype, &length_pos, &length_size, 1945796c8dcSSimon Schubert &string_pos, &char_type, NULL) 1955796c8dcSSimon Schubert && addr != 0) 1965796c8dcSSimon Schubert { 1975796c8dcSSimon Schubert ULONGEST string_length; 1985796c8dcSSimon Schubert void *buffer; 199*cf7f2e2dSJohn Marino 2005796c8dcSSimon Schubert buffer = xmalloc (length_size); 2015796c8dcSSimon Schubert read_memory (addr + length_pos, buffer, length_size); 2025796c8dcSSimon Schubert string_length = extract_unsigned_integer (buffer, length_size, 2035796c8dcSSimon Schubert byte_order); 2045796c8dcSSimon Schubert xfree (buffer); 2055796c8dcSSimon Schubert i = val_print_string (char_type ,addr + string_pos, string_length, stream, options); 2065796c8dcSSimon Schubert } 2075796c8dcSSimon Schubert else if (pascal_object_is_vtbl_member (type)) 2085796c8dcSSimon Schubert { 2095796c8dcSSimon Schubert /* print vtbl's nicely */ 2105796c8dcSSimon Schubert CORE_ADDR vt_address = unpack_pointer (type, valaddr + embedded_offset); 2115796c8dcSSimon Schubert struct minimal_symbol *msymbol = 2125796c8dcSSimon Schubert lookup_minimal_symbol_by_pc (vt_address); 213*cf7f2e2dSJohn Marino 2145796c8dcSSimon Schubert if ((msymbol != NULL) 2155796c8dcSSimon Schubert && (vt_address == SYMBOL_VALUE_ADDRESS (msymbol))) 2165796c8dcSSimon Schubert { 2175796c8dcSSimon Schubert fputs_filtered (" <", stream); 2185796c8dcSSimon Schubert fputs_filtered (SYMBOL_PRINT_NAME (msymbol), stream); 2195796c8dcSSimon Schubert fputs_filtered (">", stream); 2205796c8dcSSimon Schubert } 2215796c8dcSSimon Schubert if (vt_address && options->vtblprint) 2225796c8dcSSimon Schubert { 2235796c8dcSSimon Schubert struct value *vt_val; 2245796c8dcSSimon Schubert struct symbol *wsym = (struct symbol *) NULL; 2255796c8dcSSimon Schubert struct type *wtype; 2265796c8dcSSimon Schubert struct block *block = (struct block *) NULL; 2275796c8dcSSimon Schubert int is_this_fld; 2285796c8dcSSimon Schubert 2295796c8dcSSimon Schubert if (msymbol != NULL) 2305796c8dcSSimon Schubert wsym = lookup_symbol (SYMBOL_LINKAGE_NAME (msymbol), block, 2315796c8dcSSimon Schubert VAR_DOMAIN, &is_this_fld); 2325796c8dcSSimon Schubert 2335796c8dcSSimon Schubert if (wsym) 2345796c8dcSSimon Schubert { 2355796c8dcSSimon Schubert wtype = SYMBOL_TYPE (wsym); 2365796c8dcSSimon Schubert } 2375796c8dcSSimon Schubert else 2385796c8dcSSimon Schubert { 2395796c8dcSSimon Schubert wtype = TYPE_TARGET_TYPE (type); 2405796c8dcSSimon Schubert } 2415796c8dcSSimon Schubert vt_val = value_at (wtype, vt_address); 2425796c8dcSSimon Schubert common_val_print (vt_val, stream, recurse + 1, options, 2435796c8dcSSimon Schubert current_language); 2445796c8dcSSimon Schubert if (options->pretty) 2455796c8dcSSimon Schubert { 2465796c8dcSSimon Schubert fprintf_filtered (stream, "\n"); 2475796c8dcSSimon Schubert print_spaces_filtered (2 + 2 * recurse, stream); 2485796c8dcSSimon Schubert } 2495796c8dcSSimon Schubert } 2505796c8dcSSimon Schubert } 2515796c8dcSSimon Schubert 2525796c8dcSSimon Schubert /* Return number of characters printed, including the terminating 2535796c8dcSSimon Schubert '\0' if we reached the end. val_print_string takes care including 2545796c8dcSSimon Schubert the terminating '\0' if necessary. */ 2555796c8dcSSimon Schubert return i; 256*cf7f2e2dSJohn Marino 2575796c8dcSSimon Schubert break; 2585796c8dcSSimon Schubert 2595796c8dcSSimon Schubert case TYPE_CODE_REF: 2605796c8dcSSimon Schubert elttype = check_typedef (TYPE_TARGET_TYPE (type)); 2615796c8dcSSimon Schubert if (options->addressprint) 2625796c8dcSSimon Schubert { 2635796c8dcSSimon Schubert CORE_ADDR addr 2645796c8dcSSimon Schubert = extract_typed_address (valaddr + embedded_offset, type); 265*cf7f2e2dSJohn Marino 2665796c8dcSSimon Schubert fprintf_filtered (stream, "@"); 2675796c8dcSSimon Schubert fputs_filtered (paddress (gdbarch, addr), stream); 2685796c8dcSSimon Schubert if (options->deref_ref) 2695796c8dcSSimon Schubert fputs_filtered (": ", stream); 2705796c8dcSSimon Schubert } 2715796c8dcSSimon Schubert /* De-reference the reference. */ 2725796c8dcSSimon Schubert if (options->deref_ref) 2735796c8dcSSimon Schubert { 2745796c8dcSSimon Schubert if (TYPE_CODE (elttype) != TYPE_CODE_UNDEF) 2755796c8dcSSimon Schubert { 2765796c8dcSSimon Schubert struct value *deref_val = 2775796c8dcSSimon Schubert value_at 2785796c8dcSSimon Schubert (TYPE_TARGET_TYPE (type), 2795796c8dcSSimon Schubert unpack_pointer (type, valaddr + embedded_offset)); 280*cf7f2e2dSJohn Marino 2815796c8dcSSimon Schubert common_val_print (deref_val, stream, recurse + 1, options, 2825796c8dcSSimon Schubert current_language); 2835796c8dcSSimon Schubert } 2845796c8dcSSimon Schubert else 2855796c8dcSSimon Schubert fputs_filtered ("???", stream); 2865796c8dcSSimon Schubert } 2875796c8dcSSimon Schubert break; 2885796c8dcSSimon Schubert 2895796c8dcSSimon Schubert case TYPE_CODE_UNION: 2905796c8dcSSimon Schubert if (recurse && !options->unionprint) 2915796c8dcSSimon Schubert { 2925796c8dcSSimon Schubert fprintf_filtered (stream, "{...}"); 2935796c8dcSSimon Schubert break; 2945796c8dcSSimon Schubert } 2955796c8dcSSimon Schubert /* Fall through. */ 2965796c8dcSSimon Schubert case TYPE_CODE_STRUCT: 2975796c8dcSSimon Schubert if (options->vtblprint && pascal_object_is_vtbl_ptr_type (type)) 2985796c8dcSSimon Schubert { 2995796c8dcSSimon Schubert /* Print the unmangled name if desired. */ 3005796c8dcSSimon Schubert /* Print vtable entry - we only get here if NOT using 3015796c8dcSSimon Schubert -fvtable_thunks. (Otherwise, look under TYPE_CODE_PTR.) */ 3025796c8dcSSimon Schubert /* Extract the address, assume that it is unsigned. */ 3035796c8dcSSimon Schubert print_address_demangle 3045796c8dcSSimon Schubert (gdbarch, 3055796c8dcSSimon Schubert extract_unsigned_integer (valaddr + embedded_offset + TYPE_FIELD_BITPOS (type, VTBL_FNADDR_OFFSET) / 8, 3065796c8dcSSimon Schubert TYPE_LENGTH (TYPE_FIELD_TYPE (type, VTBL_FNADDR_OFFSET)), byte_order), 3075796c8dcSSimon Schubert stream, demangle); 3085796c8dcSSimon Schubert } 3095796c8dcSSimon Schubert else 3105796c8dcSSimon Schubert { 3115796c8dcSSimon Schubert if (is_pascal_string_type (type, &length_pos, &length_size, 3125796c8dcSSimon Schubert &string_pos, &char_type, NULL)) 3135796c8dcSSimon Schubert { 3145796c8dcSSimon Schubert len = extract_unsigned_integer (valaddr + embedded_offset + length_pos, length_size, byte_order); 315*cf7f2e2dSJohn Marino LA_PRINT_STRING (stream, char_type, 316*cf7f2e2dSJohn Marino valaddr + embedded_offset + string_pos, 317*cf7f2e2dSJohn Marino len, NULL, 0, options); 3185796c8dcSSimon Schubert } 3195796c8dcSSimon Schubert else 3205796c8dcSSimon Schubert pascal_object_print_value_fields (type, valaddr + embedded_offset, address, stream, 321*cf7f2e2dSJohn Marino recurse, original_value, options, NULL, 0); 3225796c8dcSSimon Schubert } 3235796c8dcSSimon Schubert break; 3245796c8dcSSimon Schubert 3255796c8dcSSimon Schubert case TYPE_CODE_ENUM: 3265796c8dcSSimon Schubert if (options->format) 3275796c8dcSSimon Schubert { 3285796c8dcSSimon Schubert print_scalar_formatted (valaddr + embedded_offset, type, 3295796c8dcSSimon Schubert options, 0, stream); 3305796c8dcSSimon Schubert break; 3315796c8dcSSimon Schubert } 3325796c8dcSSimon Schubert len = TYPE_NFIELDS (type); 3335796c8dcSSimon Schubert val = unpack_long (type, valaddr + embedded_offset); 3345796c8dcSSimon Schubert for (i = 0; i < len; i++) 3355796c8dcSSimon Schubert { 3365796c8dcSSimon Schubert QUIT; 3375796c8dcSSimon Schubert if (val == TYPE_FIELD_BITPOS (type, i)) 3385796c8dcSSimon Schubert { 3395796c8dcSSimon Schubert break; 3405796c8dcSSimon Schubert } 3415796c8dcSSimon Schubert } 3425796c8dcSSimon Schubert if (i < len) 3435796c8dcSSimon Schubert { 3445796c8dcSSimon Schubert fputs_filtered (TYPE_FIELD_NAME (type, i), stream); 3455796c8dcSSimon Schubert } 3465796c8dcSSimon Schubert else 3475796c8dcSSimon Schubert { 3485796c8dcSSimon Schubert print_longest (stream, 'd', 0, val); 3495796c8dcSSimon Schubert } 3505796c8dcSSimon Schubert break; 3515796c8dcSSimon Schubert 3525796c8dcSSimon Schubert case TYPE_CODE_FLAGS: 3535796c8dcSSimon Schubert if (options->format) 3545796c8dcSSimon Schubert print_scalar_formatted (valaddr + embedded_offset, type, 3555796c8dcSSimon Schubert options, 0, stream); 3565796c8dcSSimon Schubert else 3575796c8dcSSimon Schubert val_print_type_code_flags (type, valaddr + embedded_offset, stream); 3585796c8dcSSimon Schubert break; 3595796c8dcSSimon Schubert 3605796c8dcSSimon Schubert case TYPE_CODE_FUNC: 3615796c8dcSSimon Schubert if (options->format) 3625796c8dcSSimon Schubert { 3635796c8dcSSimon Schubert print_scalar_formatted (valaddr + embedded_offset, type, 3645796c8dcSSimon Schubert options, 0, stream); 3655796c8dcSSimon Schubert break; 3665796c8dcSSimon Schubert } 3675796c8dcSSimon Schubert /* FIXME, we should consider, at least for ANSI C language, eliminating 3685796c8dcSSimon Schubert the distinction made between FUNCs and POINTERs to FUNCs. */ 3695796c8dcSSimon Schubert fprintf_filtered (stream, "{"); 3705796c8dcSSimon Schubert type_print (type, "", stream, -1); 3715796c8dcSSimon Schubert fprintf_filtered (stream, "} "); 3725796c8dcSSimon Schubert /* Try to print what function it points to, and its address. */ 3735796c8dcSSimon Schubert print_address_demangle (gdbarch, address, stream, demangle); 3745796c8dcSSimon Schubert break; 3755796c8dcSSimon Schubert 3765796c8dcSSimon Schubert case TYPE_CODE_BOOL: 3775796c8dcSSimon Schubert if (options->format || options->output_format) 3785796c8dcSSimon Schubert { 3795796c8dcSSimon Schubert struct value_print_options opts = *options; 380*cf7f2e2dSJohn Marino 3815796c8dcSSimon Schubert opts.format = (options->format ? options->format 3825796c8dcSSimon Schubert : options->output_format); 3835796c8dcSSimon Schubert print_scalar_formatted (valaddr + embedded_offset, type, 3845796c8dcSSimon Schubert &opts, 0, stream); 3855796c8dcSSimon Schubert } 3865796c8dcSSimon Schubert else 3875796c8dcSSimon Schubert { 3885796c8dcSSimon Schubert val = unpack_long (type, valaddr + embedded_offset); 3895796c8dcSSimon Schubert if (val == 0) 3905796c8dcSSimon Schubert fputs_filtered ("false", stream); 3915796c8dcSSimon Schubert else if (val == 1) 3925796c8dcSSimon Schubert fputs_filtered ("true", stream); 3935796c8dcSSimon Schubert else 3945796c8dcSSimon Schubert { 3955796c8dcSSimon Schubert fputs_filtered ("true (", stream); 3965796c8dcSSimon Schubert fprintf_filtered (stream, "%ld)", (long int) val); 3975796c8dcSSimon Schubert } 3985796c8dcSSimon Schubert } 3995796c8dcSSimon Schubert break; 4005796c8dcSSimon Schubert 4015796c8dcSSimon Schubert case TYPE_CODE_RANGE: 4025796c8dcSSimon Schubert /* FIXME: create_range_type does not set the unsigned bit in a 4035796c8dcSSimon Schubert range type (I think it probably should copy it from the target 4045796c8dcSSimon Schubert type), so we won't print values which are too large to 4055796c8dcSSimon Schubert fit in a signed integer correctly. */ 4065796c8dcSSimon Schubert /* FIXME: Doesn't handle ranges of enums correctly. (Can't just 4075796c8dcSSimon Schubert print with the target type, though, because the size of our type 4085796c8dcSSimon Schubert and the target type might differ). */ 4095796c8dcSSimon Schubert /* FALLTHROUGH */ 4105796c8dcSSimon Schubert 4115796c8dcSSimon Schubert case TYPE_CODE_INT: 4125796c8dcSSimon Schubert if (options->format || options->output_format) 4135796c8dcSSimon Schubert { 4145796c8dcSSimon Schubert struct value_print_options opts = *options; 415*cf7f2e2dSJohn Marino 4165796c8dcSSimon Schubert opts.format = (options->format ? options->format 4175796c8dcSSimon Schubert : options->output_format); 4185796c8dcSSimon Schubert print_scalar_formatted (valaddr + embedded_offset, type, 4195796c8dcSSimon Schubert &opts, 0, stream); 4205796c8dcSSimon Schubert } 4215796c8dcSSimon Schubert else 4225796c8dcSSimon Schubert { 4235796c8dcSSimon Schubert val_print_type_code_int (type, valaddr + embedded_offset, stream); 4245796c8dcSSimon Schubert } 4255796c8dcSSimon Schubert break; 4265796c8dcSSimon Schubert 4275796c8dcSSimon Schubert case TYPE_CODE_CHAR: 4285796c8dcSSimon Schubert if (options->format || options->output_format) 4295796c8dcSSimon Schubert { 4305796c8dcSSimon Schubert struct value_print_options opts = *options; 431*cf7f2e2dSJohn Marino 4325796c8dcSSimon Schubert opts.format = (options->format ? options->format 4335796c8dcSSimon Schubert : options->output_format); 4345796c8dcSSimon Schubert print_scalar_formatted (valaddr + embedded_offset, type, 4355796c8dcSSimon Schubert &opts, 0, stream); 4365796c8dcSSimon Schubert } 4375796c8dcSSimon Schubert else 4385796c8dcSSimon Schubert { 4395796c8dcSSimon Schubert val = unpack_long (type, valaddr + embedded_offset); 4405796c8dcSSimon Schubert if (TYPE_UNSIGNED (type)) 4415796c8dcSSimon Schubert fprintf_filtered (stream, "%u", (unsigned int) val); 4425796c8dcSSimon Schubert else 4435796c8dcSSimon Schubert fprintf_filtered (stream, "%d", (int) val); 4445796c8dcSSimon Schubert fputs_filtered (" ", stream); 4455796c8dcSSimon Schubert LA_PRINT_CHAR ((unsigned char) val, type, stream); 4465796c8dcSSimon Schubert } 4475796c8dcSSimon Schubert break; 4485796c8dcSSimon Schubert 4495796c8dcSSimon Schubert case TYPE_CODE_FLT: 4505796c8dcSSimon Schubert if (options->format) 4515796c8dcSSimon Schubert { 4525796c8dcSSimon Schubert print_scalar_formatted (valaddr + embedded_offset, type, 4535796c8dcSSimon Schubert options, 0, stream); 4545796c8dcSSimon Schubert } 4555796c8dcSSimon Schubert else 4565796c8dcSSimon Schubert { 4575796c8dcSSimon Schubert print_floating (valaddr + embedded_offset, type, stream); 4585796c8dcSSimon Schubert } 4595796c8dcSSimon Schubert break; 4605796c8dcSSimon Schubert 4615796c8dcSSimon Schubert case TYPE_CODE_BITSTRING: 4625796c8dcSSimon Schubert case TYPE_CODE_SET: 4635796c8dcSSimon Schubert elttype = TYPE_INDEX_TYPE (type); 4645796c8dcSSimon Schubert CHECK_TYPEDEF (elttype); 4655796c8dcSSimon Schubert if (TYPE_STUB (elttype)) 4665796c8dcSSimon Schubert { 4675796c8dcSSimon Schubert fprintf_filtered (stream, "<incomplete type>"); 4685796c8dcSSimon Schubert gdb_flush (stream); 4695796c8dcSSimon Schubert break; 4705796c8dcSSimon Schubert } 4715796c8dcSSimon Schubert else 4725796c8dcSSimon Schubert { 4735796c8dcSSimon Schubert struct type *range = elttype; 4745796c8dcSSimon Schubert LONGEST low_bound, high_bound; 4755796c8dcSSimon Schubert int i; 4765796c8dcSSimon Schubert int is_bitstring = TYPE_CODE (type) == TYPE_CODE_BITSTRING; 4775796c8dcSSimon Schubert int need_comma = 0; 4785796c8dcSSimon Schubert 4795796c8dcSSimon Schubert if (is_bitstring) 4805796c8dcSSimon Schubert fputs_filtered ("B'", stream); 4815796c8dcSSimon Schubert else 4825796c8dcSSimon Schubert fputs_filtered ("[", stream); 4835796c8dcSSimon Schubert 4845796c8dcSSimon Schubert i = get_discrete_bounds (range, &low_bound, &high_bound); 485*cf7f2e2dSJohn Marino if (low_bound == 0 && high_bound == -1 && TYPE_LENGTH (type) > 0) 486*cf7f2e2dSJohn Marino { 487*cf7f2e2dSJohn Marino /* If we know the size of the set type, we can figure out the 488*cf7f2e2dSJohn Marino maximum value. */ 489*cf7f2e2dSJohn Marino i = 0; 490*cf7f2e2dSJohn Marino high_bound = TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1; 491*cf7f2e2dSJohn Marino TYPE_HIGH_BOUND (range) = high_bound; 492*cf7f2e2dSJohn Marino } 4935796c8dcSSimon Schubert maybe_bad_bstring: 4945796c8dcSSimon Schubert if (i < 0) 4955796c8dcSSimon Schubert { 4965796c8dcSSimon Schubert fputs_filtered ("<error value>", stream); 4975796c8dcSSimon Schubert goto done; 4985796c8dcSSimon Schubert } 4995796c8dcSSimon Schubert 5005796c8dcSSimon Schubert for (i = low_bound; i <= high_bound; i++) 5015796c8dcSSimon Schubert { 5025796c8dcSSimon Schubert int element = value_bit_index (type, valaddr + embedded_offset, i); 503*cf7f2e2dSJohn Marino 5045796c8dcSSimon Schubert if (element < 0) 5055796c8dcSSimon Schubert { 5065796c8dcSSimon Schubert i = element; 5075796c8dcSSimon Schubert goto maybe_bad_bstring; 5085796c8dcSSimon Schubert } 5095796c8dcSSimon Schubert if (is_bitstring) 5105796c8dcSSimon Schubert fprintf_filtered (stream, "%d", element); 5115796c8dcSSimon Schubert else if (element) 5125796c8dcSSimon Schubert { 5135796c8dcSSimon Schubert if (need_comma) 5145796c8dcSSimon Schubert fputs_filtered (", ", stream); 5155796c8dcSSimon Schubert print_type_scalar (range, i, stream); 5165796c8dcSSimon Schubert need_comma = 1; 5175796c8dcSSimon Schubert 5185796c8dcSSimon Schubert if (i + 1 <= high_bound && value_bit_index (type, valaddr + embedded_offset, ++i)) 5195796c8dcSSimon Schubert { 5205796c8dcSSimon Schubert int j = i; 521*cf7f2e2dSJohn Marino 5225796c8dcSSimon Schubert fputs_filtered ("..", stream); 5235796c8dcSSimon Schubert while (i + 1 <= high_bound 5245796c8dcSSimon Schubert && value_bit_index (type, valaddr + embedded_offset, ++i)) 5255796c8dcSSimon Schubert j = i; 5265796c8dcSSimon Schubert print_type_scalar (range, j, stream); 5275796c8dcSSimon Schubert } 5285796c8dcSSimon Schubert } 5295796c8dcSSimon Schubert } 5305796c8dcSSimon Schubert done: 5315796c8dcSSimon Schubert if (is_bitstring) 5325796c8dcSSimon Schubert fputs_filtered ("'", stream); 5335796c8dcSSimon Schubert else 5345796c8dcSSimon Schubert fputs_filtered ("]", stream); 5355796c8dcSSimon Schubert } 5365796c8dcSSimon Schubert break; 5375796c8dcSSimon Schubert 5385796c8dcSSimon Schubert case TYPE_CODE_VOID: 5395796c8dcSSimon Schubert fprintf_filtered (stream, "void"); 5405796c8dcSSimon Schubert break; 5415796c8dcSSimon Schubert 5425796c8dcSSimon Schubert case TYPE_CODE_ERROR: 543*cf7f2e2dSJohn Marino fprintf_filtered (stream, "%s", TYPE_ERROR_NAME (type)); 5445796c8dcSSimon Schubert break; 5455796c8dcSSimon Schubert 5465796c8dcSSimon Schubert case TYPE_CODE_UNDEF: 5475796c8dcSSimon Schubert /* This happens (without TYPE_FLAG_STUB set) on systems which don't use 5485796c8dcSSimon Schubert dbx xrefs (NO_DBX_XREFS in gcc) if a file has a "struct foo *bar" 5495796c8dcSSimon Schubert and no complete type for struct foo in that file. */ 5505796c8dcSSimon Schubert fprintf_filtered (stream, "<incomplete type>"); 5515796c8dcSSimon Schubert break; 5525796c8dcSSimon Schubert 5535796c8dcSSimon Schubert default: 5545796c8dcSSimon Schubert error (_("Invalid pascal type code %d in symbol table."), TYPE_CODE (type)); 5555796c8dcSSimon Schubert } 5565796c8dcSSimon Schubert gdb_flush (stream); 5575796c8dcSSimon Schubert return (0); 5585796c8dcSSimon Schubert } 5595796c8dcSSimon Schubert 5605796c8dcSSimon Schubert int 5615796c8dcSSimon Schubert pascal_value_print (struct value *val, struct ui_file *stream, 5625796c8dcSSimon Schubert const struct value_print_options *options) 5635796c8dcSSimon Schubert { 5645796c8dcSSimon Schubert struct type *type = value_type (val); 565*cf7f2e2dSJohn Marino struct value_print_options opts = *options; 566*cf7f2e2dSJohn Marino 567*cf7f2e2dSJohn Marino opts.deref_ref = 1; 5685796c8dcSSimon Schubert 5695796c8dcSSimon Schubert /* If it is a pointer, indicate what it points to. 5705796c8dcSSimon Schubert 5715796c8dcSSimon Schubert Print type also if it is a reference. 5725796c8dcSSimon Schubert 5735796c8dcSSimon Schubert Object pascal: if it is a member pointer, we will take care 5745796c8dcSSimon Schubert of that when we print it. */ 5755796c8dcSSimon Schubert if (TYPE_CODE (type) == TYPE_CODE_PTR 5765796c8dcSSimon Schubert || TYPE_CODE (type) == TYPE_CODE_REF) 5775796c8dcSSimon Schubert { 5785796c8dcSSimon Schubert /* Hack: remove (char *) for char strings. Their 5795796c8dcSSimon Schubert type is indicated by the quoted string anyway. */ 5805796c8dcSSimon Schubert if (TYPE_CODE (type) == TYPE_CODE_PTR 5815796c8dcSSimon Schubert && TYPE_NAME (type) == NULL 5825796c8dcSSimon Schubert && TYPE_NAME (TYPE_TARGET_TYPE (type)) != NULL 5835796c8dcSSimon Schubert && strcmp (TYPE_NAME (TYPE_TARGET_TYPE (type)), "char") == 0) 5845796c8dcSSimon Schubert { 5855796c8dcSSimon Schubert /* Print nothing */ 5865796c8dcSSimon Schubert } 5875796c8dcSSimon Schubert else 5885796c8dcSSimon Schubert { 5895796c8dcSSimon Schubert fprintf_filtered (stream, "("); 5905796c8dcSSimon Schubert type_print (type, "", stream, -1); 5915796c8dcSSimon Schubert fprintf_filtered (stream, ") "); 5925796c8dcSSimon Schubert } 5935796c8dcSSimon Schubert } 594*cf7f2e2dSJohn Marino return common_val_print (val, stream, 0, &opts, current_language); 5955796c8dcSSimon Schubert } 5965796c8dcSSimon Schubert 5975796c8dcSSimon Schubert 5985796c8dcSSimon Schubert static void 5995796c8dcSSimon Schubert show_pascal_static_field_print (struct ui_file *file, int from_tty, 6005796c8dcSSimon Schubert struct cmd_list_element *c, const char *value) 6015796c8dcSSimon Schubert { 6025796c8dcSSimon Schubert fprintf_filtered (file, _("Printing of pascal static members is %s.\n"), 6035796c8dcSSimon Schubert value); 6045796c8dcSSimon Schubert } 6055796c8dcSSimon Schubert 6065796c8dcSSimon Schubert static struct obstack dont_print_vb_obstack; 6075796c8dcSSimon Schubert static struct obstack dont_print_statmem_obstack; 6085796c8dcSSimon Schubert 6095796c8dcSSimon Schubert static void pascal_object_print_static_field (struct value *, 6105796c8dcSSimon Schubert struct ui_file *, int, 6115796c8dcSSimon Schubert const struct value_print_options *); 6125796c8dcSSimon Schubert 6135796c8dcSSimon Schubert static void pascal_object_print_value (struct type *, const gdb_byte *, 6145796c8dcSSimon Schubert CORE_ADDR, struct ui_file *, int, 615*cf7f2e2dSJohn Marino const struct value *, 6165796c8dcSSimon Schubert const struct value_print_options *, 6175796c8dcSSimon Schubert struct type **); 6185796c8dcSSimon Schubert 6195796c8dcSSimon Schubert /* It was changed to this after 2.4.5. */ 6205796c8dcSSimon Schubert const char pascal_vtbl_ptr_name[] = 6215796c8dcSSimon Schubert {'_', '_', 'v', 't', 'b', 'l', '_', 'p', 't', 'r', '_', 't', 'y', 'p', 'e', 0}; 6225796c8dcSSimon Schubert 6235796c8dcSSimon Schubert /* Return truth value for assertion that TYPE is of the type 6245796c8dcSSimon Schubert "pointer to virtual function". */ 6255796c8dcSSimon Schubert 6265796c8dcSSimon Schubert int 6275796c8dcSSimon Schubert pascal_object_is_vtbl_ptr_type (struct type *type) 6285796c8dcSSimon Schubert { 6295796c8dcSSimon Schubert char *typename = type_name_no_tag (type); 6305796c8dcSSimon Schubert 6315796c8dcSSimon Schubert return (typename != NULL 6325796c8dcSSimon Schubert && strcmp (typename, pascal_vtbl_ptr_name) == 0); 6335796c8dcSSimon Schubert } 6345796c8dcSSimon Schubert 6355796c8dcSSimon Schubert /* Return truth value for the assertion that TYPE is of the type 6365796c8dcSSimon Schubert "pointer to virtual function table". */ 6375796c8dcSSimon Schubert 6385796c8dcSSimon Schubert int 6395796c8dcSSimon Schubert pascal_object_is_vtbl_member (struct type *type) 6405796c8dcSSimon Schubert { 6415796c8dcSSimon Schubert if (TYPE_CODE (type) == TYPE_CODE_PTR) 6425796c8dcSSimon Schubert { 6435796c8dcSSimon Schubert type = TYPE_TARGET_TYPE (type); 6445796c8dcSSimon Schubert if (TYPE_CODE (type) == TYPE_CODE_ARRAY) 6455796c8dcSSimon Schubert { 6465796c8dcSSimon Schubert type = TYPE_TARGET_TYPE (type); 6475796c8dcSSimon Schubert if (TYPE_CODE (type) == TYPE_CODE_STRUCT /* if not using thunks */ 6485796c8dcSSimon Schubert || TYPE_CODE (type) == TYPE_CODE_PTR) /* if using thunks */ 6495796c8dcSSimon Schubert { 6505796c8dcSSimon Schubert /* Virtual functions tables are full of pointers 6515796c8dcSSimon Schubert to virtual functions. */ 6525796c8dcSSimon Schubert return pascal_object_is_vtbl_ptr_type (type); 6535796c8dcSSimon Schubert } 6545796c8dcSSimon Schubert } 6555796c8dcSSimon Schubert } 6565796c8dcSSimon Schubert return 0; 6575796c8dcSSimon Schubert } 6585796c8dcSSimon Schubert 6595796c8dcSSimon Schubert /* Mutually recursive subroutines of pascal_object_print_value and 6605796c8dcSSimon Schubert c_val_print to print out a structure's fields: 6615796c8dcSSimon Schubert pascal_object_print_value_fields and pascal_object_print_value. 6625796c8dcSSimon Schubert 6635796c8dcSSimon Schubert TYPE, VALADDR, ADDRESS, STREAM, RECURSE, and OPTIONS have the 6645796c8dcSSimon Schubert same meanings as in pascal_object_print_value and c_val_print. 6655796c8dcSSimon Schubert 6665796c8dcSSimon Schubert DONT_PRINT is an array of baseclass types that we 6675796c8dcSSimon Schubert should not print, or zero if called from top level. */ 6685796c8dcSSimon Schubert 6695796c8dcSSimon Schubert void 6705796c8dcSSimon Schubert pascal_object_print_value_fields (struct type *type, const gdb_byte *valaddr, 6715796c8dcSSimon Schubert CORE_ADDR address, struct ui_file *stream, 6725796c8dcSSimon Schubert int recurse, 673*cf7f2e2dSJohn Marino const struct value *val, 6745796c8dcSSimon Schubert const struct value_print_options *options, 6755796c8dcSSimon Schubert struct type **dont_print_vb, 6765796c8dcSSimon Schubert int dont_print_statmem) 6775796c8dcSSimon Schubert { 6785796c8dcSSimon Schubert int i, len, n_baseclasses; 6795796c8dcSSimon Schubert char *last_dont_print = obstack_next_free (&dont_print_statmem_obstack); 6805796c8dcSSimon Schubert 6815796c8dcSSimon Schubert CHECK_TYPEDEF (type); 6825796c8dcSSimon Schubert 6835796c8dcSSimon Schubert fprintf_filtered (stream, "{"); 6845796c8dcSSimon Schubert len = TYPE_NFIELDS (type); 6855796c8dcSSimon Schubert n_baseclasses = TYPE_N_BASECLASSES (type); 6865796c8dcSSimon Schubert 6875796c8dcSSimon Schubert /* Print out baseclasses such that we don't print 6885796c8dcSSimon Schubert duplicates of virtual baseclasses. */ 6895796c8dcSSimon Schubert if (n_baseclasses > 0) 6905796c8dcSSimon Schubert pascal_object_print_value (type, valaddr, address, stream, 691*cf7f2e2dSJohn Marino recurse + 1, val, options, dont_print_vb); 6925796c8dcSSimon Schubert 6935796c8dcSSimon Schubert if (!len && n_baseclasses == 1) 6945796c8dcSSimon Schubert fprintf_filtered (stream, "<No data fields>"); 6955796c8dcSSimon Schubert else 6965796c8dcSSimon Schubert { 6975796c8dcSSimon Schubert struct obstack tmp_obstack = dont_print_statmem_obstack; 6985796c8dcSSimon Schubert int fields_seen = 0; 6995796c8dcSSimon Schubert 7005796c8dcSSimon Schubert if (dont_print_statmem == 0) 7015796c8dcSSimon Schubert { 7025796c8dcSSimon Schubert /* If we're at top level, carve out a completely fresh 7035796c8dcSSimon Schubert chunk of the obstack and use that until this particular 7045796c8dcSSimon Schubert invocation returns. */ 7055796c8dcSSimon Schubert obstack_finish (&dont_print_statmem_obstack); 7065796c8dcSSimon Schubert } 7075796c8dcSSimon Schubert 7085796c8dcSSimon Schubert for (i = n_baseclasses; i < len; i++) 7095796c8dcSSimon Schubert { 7105796c8dcSSimon Schubert /* If requested, skip printing of static fields. */ 7115796c8dcSSimon Schubert if (!options->pascal_static_field_print 7125796c8dcSSimon Schubert && field_is_static (&TYPE_FIELD (type, i))) 7135796c8dcSSimon Schubert continue; 7145796c8dcSSimon Schubert if (fields_seen) 7155796c8dcSSimon Schubert fprintf_filtered (stream, ", "); 7165796c8dcSSimon Schubert else if (n_baseclasses > 0) 7175796c8dcSSimon Schubert { 7185796c8dcSSimon Schubert if (options->pretty) 7195796c8dcSSimon Schubert { 7205796c8dcSSimon Schubert fprintf_filtered (stream, "\n"); 7215796c8dcSSimon Schubert print_spaces_filtered (2 + 2 * recurse, stream); 7225796c8dcSSimon Schubert fputs_filtered ("members of ", stream); 7235796c8dcSSimon Schubert fputs_filtered (type_name_no_tag (type), stream); 7245796c8dcSSimon Schubert fputs_filtered (": ", stream); 7255796c8dcSSimon Schubert } 7265796c8dcSSimon Schubert } 7275796c8dcSSimon Schubert fields_seen = 1; 7285796c8dcSSimon Schubert 7295796c8dcSSimon Schubert if (options->pretty) 7305796c8dcSSimon Schubert { 7315796c8dcSSimon Schubert fprintf_filtered (stream, "\n"); 7325796c8dcSSimon Schubert print_spaces_filtered (2 + 2 * recurse, stream); 7335796c8dcSSimon Schubert } 7345796c8dcSSimon Schubert else 7355796c8dcSSimon Schubert { 7365796c8dcSSimon Schubert wrap_here (n_spaces (2 + 2 * recurse)); 7375796c8dcSSimon Schubert } 7385796c8dcSSimon Schubert if (options->inspect_it) 7395796c8dcSSimon Schubert { 7405796c8dcSSimon Schubert if (TYPE_CODE (TYPE_FIELD_TYPE (type, i)) == TYPE_CODE_PTR) 7415796c8dcSSimon Schubert fputs_filtered ("\"( ptr \"", stream); 7425796c8dcSSimon Schubert else 7435796c8dcSSimon Schubert fputs_filtered ("\"( nodef \"", stream); 7445796c8dcSSimon Schubert if (field_is_static (&TYPE_FIELD (type, i))) 7455796c8dcSSimon Schubert fputs_filtered ("static ", stream); 7465796c8dcSSimon Schubert fprintf_symbol_filtered (stream, TYPE_FIELD_NAME (type, i), 7475796c8dcSSimon Schubert language_cplus, 7485796c8dcSSimon Schubert DMGL_PARAMS | DMGL_ANSI); 7495796c8dcSSimon Schubert fputs_filtered ("\" \"", stream); 7505796c8dcSSimon Schubert fprintf_symbol_filtered (stream, TYPE_FIELD_NAME (type, i), 7515796c8dcSSimon Schubert language_cplus, 7525796c8dcSSimon Schubert DMGL_PARAMS | DMGL_ANSI); 7535796c8dcSSimon Schubert fputs_filtered ("\") \"", stream); 7545796c8dcSSimon Schubert } 7555796c8dcSSimon Schubert else 7565796c8dcSSimon Schubert { 7575796c8dcSSimon Schubert annotate_field_begin (TYPE_FIELD_TYPE (type, i)); 7585796c8dcSSimon Schubert 7595796c8dcSSimon Schubert if (field_is_static (&TYPE_FIELD (type, i))) 7605796c8dcSSimon Schubert fputs_filtered ("static ", stream); 7615796c8dcSSimon Schubert fprintf_symbol_filtered (stream, TYPE_FIELD_NAME (type, i), 7625796c8dcSSimon Schubert language_cplus, 7635796c8dcSSimon Schubert DMGL_PARAMS | DMGL_ANSI); 7645796c8dcSSimon Schubert annotate_field_name_end (); 7655796c8dcSSimon Schubert fputs_filtered (" = ", stream); 7665796c8dcSSimon Schubert annotate_field_value (); 7675796c8dcSSimon Schubert } 7685796c8dcSSimon Schubert 7695796c8dcSSimon Schubert if (!field_is_static (&TYPE_FIELD (type, i)) 7705796c8dcSSimon Schubert && TYPE_FIELD_PACKED (type, i)) 7715796c8dcSSimon Schubert { 7725796c8dcSSimon Schubert struct value *v; 7735796c8dcSSimon Schubert 7745796c8dcSSimon Schubert /* Bitfields require special handling, especially due to byte 7755796c8dcSSimon Schubert order problems. */ 7765796c8dcSSimon Schubert if (TYPE_FIELD_IGNORE (type, i)) 7775796c8dcSSimon Schubert { 7785796c8dcSSimon Schubert fputs_filtered ("<optimized out or zero length>", stream); 7795796c8dcSSimon Schubert } 780*cf7f2e2dSJohn Marino else if (!value_bits_valid (val, TYPE_FIELD_BITPOS (type, i), 781*cf7f2e2dSJohn Marino TYPE_FIELD_BITSIZE (type, i))) 782*cf7f2e2dSJohn Marino { 783*cf7f2e2dSJohn Marino fputs_filtered (_("<value optimized out>"), stream); 784*cf7f2e2dSJohn Marino } 7855796c8dcSSimon Schubert else 7865796c8dcSSimon Schubert { 7875796c8dcSSimon Schubert struct value_print_options opts = *options; 788*cf7f2e2dSJohn Marino 7895796c8dcSSimon Schubert v = value_from_longest (TYPE_FIELD_TYPE (type, i), 7905796c8dcSSimon Schubert unpack_field_as_long (type, valaddr, i)); 7915796c8dcSSimon Schubert 7925796c8dcSSimon Schubert opts.deref_ref = 0; 7935796c8dcSSimon Schubert common_val_print (v, stream, recurse + 1, &opts, 7945796c8dcSSimon Schubert current_language); 7955796c8dcSSimon Schubert } 7965796c8dcSSimon Schubert } 7975796c8dcSSimon Schubert else 7985796c8dcSSimon Schubert { 7995796c8dcSSimon Schubert if (TYPE_FIELD_IGNORE (type, i)) 8005796c8dcSSimon Schubert { 8015796c8dcSSimon Schubert fputs_filtered ("<optimized out or zero length>", stream); 8025796c8dcSSimon Schubert } 8035796c8dcSSimon Schubert else if (field_is_static (&TYPE_FIELD (type, i))) 8045796c8dcSSimon Schubert { 8055796c8dcSSimon Schubert /* struct value *v = value_static_field (type, i); v4.17 specific */ 8065796c8dcSSimon Schubert struct value *v; 807*cf7f2e2dSJohn Marino 8085796c8dcSSimon Schubert v = value_from_longest (TYPE_FIELD_TYPE (type, i), 8095796c8dcSSimon Schubert unpack_field_as_long (type, valaddr, i)); 8105796c8dcSSimon Schubert 8115796c8dcSSimon Schubert if (v == NULL) 8125796c8dcSSimon Schubert fputs_filtered ("<optimized out>", stream); 8135796c8dcSSimon Schubert else 8145796c8dcSSimon Schubert pascal_object_print_static_field (v, stream, recurse + 1, 8155796c8dcSSimon Schubert options); 8165796c8dcSSimon Schubert } 8175796c8dcSSimon Schubert else 8185796c8dcSSimon Schubert { 8195796c8dcSSimon Schubert struct value_print_options opts = *options; 820*cf7f2e2dSJohn Marino 8215796c8dcSSimon Schubert opts.deref_ref = 0; 8225796c8dcSSimon Schubert /* val_print (TYPE_FIELD_TYPE (type, i), 8235796c8dcSSimon Schubert valaddr + TYPE_FIELD_BITPOS (type, i) / 8, 8245796c8dcSSimon Schubert address + TYPE_FIELD_BITPOS (type, i) / 8, 0, 8255796c8dcSSimon Schubert stream, format, 0, recurse + 1, pretty); */ 8265796c8dcSSimon Schubert val_print (TYPE_FIELD_TYPE (type, i), 8275796c8dcSSimon Schubert valaddr, TYPE_FIELD_BITPOS (type, i) / 8, 8285796c8dcSSimon Schubert address + TYPE_FIELD_BITPOS (type, i) / 8, 829*cf7f2e2dSJohn Marino stream, recurse + 1, val, &opts, 8305796c8dcSSimon Schubert current_language); 8315796c8dcSSimon Schubert } 8325796c8dcSSimon Schubert } 8335796c8dcSSimon Schubert annotate_field_end (); 8345796c8dcSSimon Schubert } 8355796c8dcSSimon Schubert 8365796c8dcSSimon Schubert if (dont_print_statmem == 0) 8375796c8dcSSimon Schubert { 8385796c8dcSSimon Schubert /* Free the space used to deal with the printing 8395796c8dcSSimon Schubert of the members from top level. */ 8405796c8dcSSimon Schubert obstack_free (&dont_print_statmem_obstack, last_dont_print); 8415796c8dcSSimon Schubert dont_print_statmem_obstack = tmp_obstack; 8425796c8dcSSimon Schubert } 8435796c8dcSSimon Schubert 8445796c8dcSSimon Schubert if (options->pretty) 8455796c8dcSSimon Schubert { 8465796c8dcSSimon Schubert fprintf_filtered (stream, "\n"); 8475796c8dcSSimon Schubert print_spaces_filtered (2 * recurse, stream); 8485796c8dcSSimon Schubert } 8495796c8dcSSimon Schubert } 8505796c8dcSSimon Schubert fprintf_filtered (stream, "}"); 8515796c8dcSSimon Schubert } 8525796c8dcSSimon Schubert 8535796c8dcSSimon Schubert /* Special val_print routine to avoid printing multiple copies of virtual 8545796c8dcSSimon Schubert baseclasses. */ 8555796c8dcSSimon Schubert 8565796c8dcSSimon Schubert static void 8575796c8dcSSimon Schubert pascal_object_print_value (struct type *type, const gdb_byte *valaddr, 8585796c8dcSSimon Schubert CORE_ADDR address, struct ui_file *stream, 8595796c8dcSSimon Schubert int recurse, 860*cf7f2e2dSJohn Marino const struct value *val, 8615796c8dcSSimon Schubert const struct value_print_options *options, 8625796c8dcSSimon Schubert struct type **dont_print_vb) 8635796c8dcSSimon Schubert { 8645796c8dcSSimon Schubert struct type **last_dont_print 8655796c8dcSSimon Schubert = (struct type **) obstack_next_free (&dont_print_vb_obstack); 8665796c8dcSSimon Schubert struct obstack tmp_obstack = dont_print_vb_obstack; 8675796c8dcSSimon Schubert int i, n_baseclasses = TYPE_N_BASECLASSES (type); 8685796c8dcSSimon Schubert 8695796c8dcSSimon Schubert if (dont_print_vb == 0) 8705796c8dcSSimon Schubert { 8715796c8dcSSimon Schubert /* If we're at top level, carve out a completely fresh 8725796c8dcSSimon Schubert chunk of the obstack and use that until this particular 8735796c8dcSSimon Schubert invocation returns. */ 8745796c8dcSSimon Schubert /* Bump up the high-water mark. Now alpha is omega. */ 8755796c8dcSSimon Schubert obstack_finish (&dont_print_vb_obstack); 8765796c8dcSSimon Schubert } 8775796c8dcSSimon Schubert 8785796c8dcSSimon Schubert for (i = 0; i < n_baseclasses; i++) 8795796c8dcSSimon Schubert { 8805796c8dcSSimon Schubert int boffset; 8815796c8dcSSimon Schubert struct type *baseclass = check_typedef (TYPE_BASECLASS (type, i)); 8825796c8dcSSimon Schubert char *basename = type_name_no_tag (baseclass); 8835796c8dcSSimon Schubert const gdb_byte *base_valaddr; 8845796c8dcSSimon Schubert 8855796c8dcSSimon Schubert if (BASETYPE_VIA_VIRTUAL (type, i)) 8865796c8dcSSimon Schubert { 8875796c8dcSSimon Schubert struct type **first_dont_print 8885796c8dcSSimon Schubert = (struct type **) obstack_base (&dont_print_vb_obstack); 8895796c8dcSSimon Schubert 8905796c8dcSSimon Schubert int j = (struct type **) obstack_next_free (&dont_print_vb_obstack) 8915796c8dcSSimon Schubert - first_dont_print; 8925796c8dcSSimon Schubert 8935796c8dcSSimon Schubert while (--j >= 0) 8945796c8dcSSimon Schubert if (baseclass == first_dont_print[j]) 8955796c8dcSSimon Schubert goto flush_it; 8965796c8dcSSimon Schubert 8975796c8dcSSimon Schubert obstack_ptr_grow (&dont_print_vb_obstack, baseclass); 8985796c8dcSSimon Schubert } 8995796c8dcSSimon Schubert 9005796c8dcSSimon Schubert boffset = baseclass_offset (type, i, valaddr, address); 9015796c8dcSSimon Schubert 9025796c8dcSSimon Schubert if (options->pretty) 9035796c8dcSSimon Schubert { 9045796c8dcSSimon Schubert fprintf_filtered (stream, "\n"); 9055796c8dcSSimon Schubert print_spaces_filtered (2 * recurse, stream); 9065796c8dcSSimon Schubert } 9075796c8dcSSimon Schubert fputs_filtered ("<", stream); 9085796c8dcSSimon Schubert /* Not sure what the best notation is in the case where there is no 9095796c8dcSSimon Schubert baseclass name. */ 9105796c8dcSSimon Schubert 9115796c8dcSSimon Schubert fputs_filtered (basename ? basename : "", stream); 9125796c8dcSSimon Schubert fputs_filtered ("> = ", stream); 9135796c8dcSSimon Schubert 9145796c8dcSSimon Schubert /* The virtual base class pointer might have been clobbered by the 9155796c8dcSSimon Schubert user program. Make sure that it still points to a valid memory 9165796c8dcSSimon Schubert location. */ 9175796c8dcSSimon Schubert 9185796c8dcSSimon Schubert if (boffset != -1 && (boffset < 0 || boffset >= TYPE_LENGTH (type))) 9195796c8dcSSimon Schubert { 9205796c8dcSSimon Schubert /* FIXME (alloc): not safe is baseclass is really really big. */ 9215796c8dcSSimon Schubert gdb_byte *buf = alloca (TYPE_LENGTH (baseclass)); 922*cf7f2e2dSJohn Marino 9235796c8dcSSimon Schubert base_valaddr = buf; 9245796c8dcSSimon Schubert if (target_read_memory (address + boffset, buf, 9255796c8dcSSimon Schubert TYPE_LENGTH (baseclass)) != 0) 9265796c8dcSSimon Schubert boffset = -1; 9275796c8dcSSimon Schubert } 9285796c8dcSSimon Schubert else 9295796c8dcSSimon Schubert base_valaddr = valaddr + boffset; 9305796c8dcSSimon Schubert 9315796c8dcSSimon Schubert if (boffset == -1) 9325796c8dcSSimon Schubert fprintf_filtered (stream, "<invalid address>"); 9335796c8dcSSimon Schubert else 9345796c8dcSSimon Schubert pascal_object_print_value_fields (baseclass, base_valaddr, address + boffset, 935*cf7f2e2dSJohn Marino stream, recurse, val, options, 9365796c8dcSSimon Schubert (struct type **) obstack_base (&dont_print_vb_obstack), 9375796c8dcSSimon Schubert 0); 9385796c8dcSSimon Schubert fputs_filtered (", ", stream); 9395796c8dcSSimon Schubert 9405796c8dcSSimon Schubert flush_it: 9415796c8dcSSimon Schubert ; 9425796c8dcSSimon Schubert } 9435796c8dcSSimon Schubert 9445796c8dcSSimon Schubert if (dont_print_vb == 0) 9455796c8dcSSimon Schubert { 9465796c8dcSSimon Schubert /* Free the space used to deal with the printing 9475796c8dcSSimon Schubert of this type from top level. */ 9485796c8dcSSimon Schubert obstack_free (&dont_print_vb_obstack, last_dont_print); 9495796c8dcSSimon Schubert /* Reset watermark so that we can continue protecting 9505796c8dcSSimon Schubert ourselves from whatever we were protecting ourselves. */ 9515796c8dcSSimon Schubert dont_print_vb_obstack = tmp_obstack; 9525796c8dcSSimon Schubert } 9535796c8dcSSimon Schubert } 9545796c8dcSSimon Schubert 9555796c8dcSSimon Schubert /* Print value of a static member. 9565796c8dcSSimon Schubert To avoid infinite recursion when printing a class that contains 9575796c8dcSSimon Schubert a static instance of the class, we keep the addresses of all printed 9585796c8dcSSimon Schubert static member classes in an obstack and refuse to print them more 9595796c8dcSSimon Schubert than once. 9605796c8dcSSimon Schubert 9615796c8dcSSimon Schubert VAL contains the value to print, STREAM, RECURSE, and OPTIONS 9625796c8dcSSimon Schubert have the same meanings as in c_val_print. */ 9635796c8dcSSimon Schubert 9645796c8dcSSimon Schubert static void 9655796c8dcSSimon Schubert pascal_object_print_static_field (struct value *val, 9665796c8dcSSimon Schubert struct ui_file *stream, 9675796c8dcSSimon Schubert int recurse, 9685796c8dcSSimon Schubert const struct value_print_options *options) 9695796c8dcSSimon Schubert { 9705796c8dcSSimon Schubert struct type *type = value_type (val); 9715796c8dcSSimon Schubert struct value_print_options opts; 9725796c8dcSSimon Schubert 9735796c8dcSSimon Schubert if (TYPE_CODE (type) == TYPE_CODE_STRUCT) 9745796c8dcSSimon Schubert { 9755796c8dcSSimon Schubert CORE_ADDR *first_dont_print, addr; 9765796c8dcSSimon Schubert int i; 9775796c8dcSSimon Schubert 9785796c8dcSSimon Schubert first_dont_print 9795796c8dcSSimon Schubert = (CORE_ADDR *) obstack_base (&dont_print_statmem_obstack); 9805796c8dcSSimon Schubert i = (CORE_ADDR *) obstack_next_free (&dont_print_statmem_obstack) 9815796c8dcSSimon Schubert - first_dont_print; 9825796c8dcSSimon Schubert 9835796c8dcSSimon Schubert while (--i >= 0) 9845796c8dcSSimon Schubert { 9855796c8dcSSimon Schubert if (value_address (val) == first_dont_print[i]) 9865796c8dcSSimon Schubert { 9875796c8dcSSimon Schubert fputs_filtered ("<same as static member of an already seen type>", 9885796c8dcSSimon Schubert stream); 9895796c8dcSSimon Schubert return; 9905796c8dcSSimon Schubert } 9915796c8dcSSimon Schubert } 9925796c8dcSSimon Schubert 9935796c8dcSSimon Schubert addr = value_address (val); 9945796c8dcSSimon Schubert obstack_grow (&dont_print_statmem_obstack, (char *) &addr, 9955796c8dcSSimon Schubert sizeof (CORE_ADDR)); 9965796c8dcSSimon Schubert 9975796c8dcSSimon Schubert CHECK_TYPEDEF (type); 9985796c8dcSSimon Schubert pascal_object_print_value_fields (type, value_contents (val), addr, 999*cf7f2e2dSJohn Marino stream, recurse, NULL, options, 1000*cf7f2e2dSJohn Marino NULL, 1); 10015796c8dcSSimon Schubert return; 10025796c8dcSSimon Schubert } 10035796c8dcSSimon Schubert 10045796c8dcSSimon Schubert opts = *options; 10055796c8dcSSimon Schubert opts.deref_ref = 0; 10065796c8dcSSimon Schubert common_val_print (val, stream, recurse, &opts, current_language); 10075796c8dcSSimon Schubert } 10085796c8dcSSimon Schubert 10095796c8dcSSimon Schubert extern initialize_file_ftype _initialize_pascal_valprint; /* -Wmissing-prototypes */ 10105796c8dcSSimon Schubert 10115796c8dcSSimon Schubert void 10125796c8dcSSimon Schubert _initialize_pascal_valprint (void) 10135796c8dcSSimon Schubert { 10145796c8dcSSimon Schubert add_setshow_boolean_cmd ("pascal_static-members", class_support, 10155796c8dcSSimon Schubert &user_print_options.pascal_static_field_print, _("\ 10165796c8dcSSimon Schubert Set printing of pascal static members."), _("\ 10175796c8dcSSimon Schubert Show printing of pascal static members."), NULL, 10185796c8dcSSimon Schubert NULL, 10195796c8dcSSimon Schubert show_pascal_static_field_print, 10205796c8dcSSimon Schubert &setprintlist, &showprintlist); 10215796c8dcSSimon Schubert } 1022