static int alphafbsd_return_in_memory (struct type *type) { enum type_code code; int i; /* All aggregate types that won't fit in a register must be returned in memory. */ if (TYPE_LENGTH (type) > ALPHA_REGISTER_SIZE) return 1; /* The only aggregate types that can be returned in a register are structs and unions. Arrays must be returned in memory. */ code = TYPE_CODE (type); if (code != TYPE_CODE_STRUCT && code != TYPE_CODE_UNION) return 1; /* We need to check if this struct/union is "integer" like. For this to be true, the offset of each adressable subfield must be zero. Note that bit fields are not addressable. */ for (i = 0; i < TYPE_NFIELDS (type); i++) { /* If the field bitsize is non-zero, it isn't adressable. */ if (TYPE_FIELD_BITPOS (type, i) != 0 && TYPE_FIELD_BITSIZE (type, i) == 0) return 1; } return 0; }
static void ada_val_print_array (struct type *type, const gdb_byte *valaddr, int offset, int offset_aligned, CORE_ADDR address, struct ui_file *stream, int recurse, struct value *original_value, const struct value_print_options *options) { /* For an array of characters, print with string syntax. */ if (ada_is_string_type (type) && (options->format == 0 || options->format == 's')) { ada_val_print_string (type, valaddr, offset, offset_aligned, address, stream, recurse, original_value, options); return; } fprintf_filtered (stream, "("); print_optional_low_bound (stream, type, options); if (TYPE_FIELD_BITSIZE (type, 0) > 0) val_print_packed_array_elements (type, valaddr, offset_aligned, 0, stream, recurse, original_value, options); else val_print_array_elements (type, offset_aligned, address, stream, recurse, original_value, options, 0); fprintf_filtered (stream, ")"); }
void m2_record_fields (struct type *type, struct ui_file *stream, int show, int level) { /* Print the tag if it exists. */ if (TYPE_TAG_NAME (type) != NULL) { if (strncmp (TYPE_TAG_NAME (type), "$$", 2) != 0) { fputs_filtered (TYPE_TAG_NAME (type), stream); if (show > 0) fprintf_filtered (stream, " = "); } } wrap_here (" "); if (show < 0) { if (TYPE_CODE (type) == DECLARED_TYPE_STRUCT) fprintf_filtered (stream, "RECORD ... END "); else if (TYPE_DECLARED_TYPE (type) == DECLARED_TYPE_UNION) fprintf_filtered (stream, "CASE ... END "); } else if (show > 0) { int i; int len = TYPE_NFIELDS (type); if (TYPE_CODE (type) == TYPE_CODE_STRUCT) fprintf_filtered (stream, "RECORD\n"); else if (TYPE_CODE (type) == TYPE_CODE_UNION) /* i18n: Do not translate "CASE" and "OF" */ fprintf_filtered (stream, _("CASE <variant> OF\n")); for (i = TYPE_N_BASECLASSES (type); i < len; i++) { QUIT; print_spaces_filtered (level + 4, stream); fputs_filtered (TYPE_FIELD_NAME (type, i), stream); fputs_filtered (" : ", stream); m2_print_type (TYPE_FIELD_TYPE (type, i), "", stream, 0, level + 4); if (TYPE_FIELD_PACKED (type, i)) { /* It is a bitfield. This code does not attempt to look at the bitpos and reconstruct filler, unnamed fields. This would lead to misleading results if the compiler does not put out fields for such things (I don't know what it does). */ fprintf_filtered (stream, " : %d", TYPE_FIELD_BITSIZE (type, i)); } fprintf_filtered (stream, ";\n"); } fprintfi_filtered (level, stream, "END "); } }
static void store_regs (struct type *regs_type, CORE_ADDR regs_base) { struct gdbarch *gdbarch = target_gdbarch (); struct regcache *regcache = get_thread_regcache (inferior_ptid); int fieldno; for (fieldno = 0; fieldno < TYPE_NFIELDS (regs_type); fieldno++) { const char *reg_name = TYPE_FIELD_NAME (regs_type, fieldno); ULONGEST reg_bitpos = TYPE_FIELD_BITPOS (regs_type, fieldno); ULONGEST reg_bitsize = TYPE_FIELD_BITSIZE (regs_type, fieldno); ULONGEST reg_offset; struct type *reg_type = check_typedef (TYPE_FIELD_TYPE (regs_type, fieldno)); ULONGEST reg_size = TYPE_LENGTH (reg_type); int regnum; struct value *regval; CORE_ADDR inferior_addr; if (strcmp (reg_name, COMPILE_I_SIMPLE_REGISTER_DUMMY) == 0) continue; if ((reg_bitpos % 8) != 0 || reg_bitsize != 0) error (_("Invalid register \"%s\" position %s bits or size %s bits"), reg_name, pulongest (reg_bitpos), pulongest (reg_bitsize)); reg_offset = reg_bitpos / 8; if (TYPE_CODE (reg_type) != TYPE_CODE_INT && TYPE_CODE (reg_type) != TYPE_CODE_PTR) error (_("Invalid register \"%s\" type code %d"), reg_name, TYPE_CODE (reg_type)); regnum = compile_register_name_demangle (gdbarch, reg_name); regval = value_from_register (reg_type, regnum, get_current_frame ()); if (value_optimized_out (regval)) error (_("Register \"%s\" is optimized out."), reg_name); if (!value_entirely_available (regval)) error (_("Register \"%s\" is not available."), reg_name); inferior_addr = regs_base + reg_offset; if (0 != target_write_memory (inferior_addr, value_contents (regval), reg_size)) error (_("Cannot write register \"%s\" to inferior memory at %s."), reg_name, paddress (gdbarch, inferior_addr)); } }
void c_type_print_base (struct type *type, struct ui_file *stream, int show, int level) { int i; int len, real_len; int lastval; char *mangled_name; char *demangled_name; char *demangled_no_static; enum { s_none, s_public, s_private, s_protected } section_type; int need_access_label = 0; int j, len2; QUIT; wrap_here (" "); if (type == NULL) { fputs_filtered (_("<type unknown>"), stream); return; } /* When SHOW is zero or less, and there is a valid type name, then always just print the type name directly from the type. */ /* If we have "typedef struct foo {. . .} bar;" do we want to print it as "struct foo" or as "bar"? Pick the latter, because C++ folk tend to expect things like "class5 *foo" rather than "struct class5 *foo". */ if (show <= 0 && TYPE_NAME (type) != NULL) { c_type_print_modifier (type, stream, 0, 1); fputs_filtered (TYPE_NAME (type), stream); return; } CHECK_TYPEDEF (type); switch (TYPE_CODE (type)) { case TYPE_CODE_TYPEDEF: case TYPE_CODE_ARRAY: case TYPE_CODE_PTR: case TYPE_CODE_MEMBER: case TYPE_CODE_REF: case TYPE_CODE_FUNC: case TYPE_CODE_METHOD: c_type_print_base (TYPE_TARGET_TYPE (type), stream, show, level); break; case TYPE_CODE_STRUCT: c_type_print_modifier (type, stream, 0, 1); /* Note TYPE_CODE_STRUCT and TYPE_CODE_CLASS have the same value, * so we use another means for distinguishing them. */ if (HAVE_CPLUS_STRUCT (type)) { switch (TYPE_DECLARED_TYPE (type)) { case DECLARED_TYPE_CLASS: fprintf_filtered (stream, "class "); break; case DECLARED_TYPE_UNION: fprintf_filtered (stream, "union "); break; case DECLARED_TYPE_STRUCT: fprintf_filtered (stream, "struct "); break; default: /* If there is a CPLUS_STRUCT, assume class if not * otherwise specified in the declared_type field. */ fprintf_filtered (stream, "class "); break; } /* switch */ } else { /* If not CPLUS_STRUCT, then assume it's a C struct */ fprintf_filtered (stream, "struct "); } goto struct_union; case TYPE_CODE_UNION: c_type_print_modifier (type, stream, 0, 1); fprintf_filtered (stream, "union "); struct_union: /* Print the tag if it exists. * The HP aCC compiler emits * a spurious "{unnamed struct}"/"{unnamed union}"/"{unnamed enum}" * tag for unnamed struct/union/enum's, which we don't * want to print. */ if (TYPE_TAG_NAME (type) != NULL && strncmp (TYPE_TAG_NAME (type), "{unnamed", 8)) { fputs_filtered (TYPE_TAG_NAME (type), stream); if (show > 0) fputs_filtered (" ", stream); } wrap_here (" "); if (show < 0) { /* If we just printed a tag name, no need to print anything else. */ if (TYPE_TAG_NAME (type) == NULL) fprintf_filtered (stream, "{...}"); } else if (show > 0 || TYPE_TAG_NAME (type) == NULL) { cp_type_print_derivation_info (stream, type); fprintf_filtered (stream, "{\n"); if ((TYPE_NFIELDS (type) == 0) && (TYPE_NFN_FIELDS (type) == 0)) { if (TYPE_STUB (type)) fprintfi_filtered (level + 4, stream, _("<incomplete type>\n")); else fprintfi_filtered (level + 4, stream, _("<no data fields>\n")); } /* Start off with no specific section type, so we can print one for the first field we find, and use that section type thereafter until we find another type. */ section_type = s_none; /* For a class, if all members are private, there's no need for a "private:" label; similarly, for a struct or union masquerading as a class, if all members are public, there's no need for a "public:" label. */ if ((TYPE_DECLARED_TYPE (type) == DECLARED_TYPE_CLASS) || (TYPE_DECLARED_TYPE (type) == DECLARED_TYPE_TEMPLATE)) { QUIT; len = TYPE_NFIELDS (type); for (i = TYPE_N_BASECLASSES (type); i < len; i++) if (!TYPE_FIELD_PRIVATE (type, i)) { need_access_label = 1; break; } QUIT; if (!need_access_label) { len2 = TYPE_NFN_FIELDS (type); for (j = 0; j < len2; j++) { len = TYPE_FN_FIELDLIST_LENGTH (type, j); for (i = 0; i < len; i++) if (!TYPE_FN_FIELD_PRIVATE (TYPE_FN_FIELDLIST1 (type, j), i)) { need_access_label = 1; break; } if (need_access_label) break; } } } else if ((TYPE_DECLARED_TYPE (type) == DECLARED_TYPE_STRUCT) || (TYPE_DECLARED_TYPE (type) == DECLARED_TYPE_UNION)) { QUIT; len = TYPE_NFIELDS (type); for (i = TYPE_N_BASECLASSES (type); i < len; i++) if (TYPE_FIELD_PRIVATE (type, i) || TYPE_FIELD_PROTECTED (type, i)) { need_access_label = 1; break; } QUIT; if (!need_access_label) { len2 = TYPE_NFN_FIELDS (type); for (j = 0; j < len2; j++) { QUIT; len = TYPE_FN_FIELDLIST_LENGTH (type, j); for (i = 0; i < len; i++) if (TYPE_FN_FIELD_PRIVATE (TYPE_FN_FIELDLIST1 (type, j), i) || TYPE_FN_FIELD_PROTECTED (TYPE_FN_FIELDLIST1 (type, j), i)) { need_access_label = 1; break; } if (need_access_label) break; } } } /* If there is a base class for this type, do not print the field that it occupies. */ len = TYPE_NFIELDS (type); for (i = TYPE_N_BASECLASSES (type); i < len; i++) { QUIT; /* Don't print out virtual function table. */ /* HP ANSI C++ case */ if (TYPE_HAS_VTABLE (type) && (strncmp (TYPE_FIELD_NAME (type, i), "__vfp", 5) == 0)) continue; /* Other compilers */ if (strncmp (TYPE_FIELD_NAME (type, i), "_vptr", 5) == 0 && is_cplus_marker ((TYPE_FIELD_NAME (type, i))[5])) continue; /* If this is a C++ class we can print the various C++ section labels. */ if (HAVE_CPLUS_STRUCT (type) && need_access_label) { if (TYPE_FIELD_PROTECTED (type, i)) { if (section_type != s_protected) { section_type = s_protected; fprintfi_filtered (level + 2, stream, "protected:\n"); } } else if (TYPE_FIELD_PRIVATE (type, i)) { if (section_type != s_private) { section_type = s_private; fprintfi_filtered (level + 2, stream, "private:\n"); } } else { if (section_type != s_public) { section_type = s_public; fprintfi_filtered (level + 2, stream, "public:\n"); } } } print_spaces_filtered (level + 4, stream); if (TYPE_FIELD_STATIC (type, i)) { fprintf_filtered (stream, "static "); } c_print_type (TYPE_FIELD_TYPE (type, i), TYPE_FIELD_NAME (type, i), stream, show - 1, level + 4); if (!TYPE_FIELD_STATIC (type, i) && TYPE_FIELD_PACKED (type, i)) { /* It is a bitfield. This code does not attempt to look at the bitpos and reconstruct filler, unnamed fields. This would lead to misleading results if the compiler does not put out fields for such things (I don't know what it does). */ fprintf_filtered (stream, " : %d", TYPE_FIELD_BITSIZE (type, i)); } fprintf_filtered (stream, ";\n"); } /* If there are both fields and methods, put a blank line between them. Make sure to count only method that we will display; artificial methods will be hidden. */ len = TYPE_NFN_FIELDS (type); real_len = 0; for (i = 0; i < len; i++) { struct fn_field *f = TYPE_FN_FIELDLIST1 (type, i); int len2 = TYPE_FN_FIELDLIST_LENGTH (type, i); int j; for (j = 0; j < len2; j++) if (!TYPE_FN_FIELD_ARTIFICIAL (f, j)) real_len++; } if (real_len > 0 && section_type != s_none) fprintf_filtered (stream, "\n"); /* C++: print out the methods */ for (i = 0; i < len; i++) { struct fn_field *f = TYPE_FN_FIELDLIST1 (type, i); int j, len2 = TYPE_FN_FIELDLIST_LENGTH (type, i); char *method_name = TYPE_FN_FIELDLIST_NAME (type, i); char *name = type_name_no_tag (type); int is_constructor = name && strcmp (method_name, name) == 0; for (j = 0; j < len2; j++) { char *physname = TYPE_FN_FIELD_PHYSNAME (f, j); int is_full_physname_constructor = is_constructor_name (physname) || is_destructor_name (physname) || method_name[0] == '~'; /* Do not print out artificial methods. */ if (TYPE_FN_FIELD_ARTIFICIAL (f, j)) continue; QUIT; if (TYPE_FN_FIELD_PROTECTED (f, j)) { if (section_type != s_protected) { section_type = s_protected; fprintfi_filtered (level + 2, stream, "protected:\n"); } } else if (TYPE_FN_FIELD_PRIVATE (f, j)) { if (section_type != s_private) { section_type = s_private; fprintfi_filtered (level + 2, stream, "private:\n"); } } else { if (section_type != s_public) { section_type = s_public; fprintfi_filtered (level + 2, stream, "public:\n"); } } print_spaces_filtered (level + 4, stream); if (TYPE_FN_FIELD_VIRTUAL_P (f, j)) fprintf_filtered (stream, "virtual "); else if (TYPE_FN_FIELD_STATIC_P (f, j)) fprintf_filtered (stream, "static "); if (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f, j)) == 0) { /* Keep GDB from crashing here. */ fprintf_filtered (stream, _("<undefined type> %s;\n"), TYPE_FN_FIELD_PHYSNAME (f, j)); break; } else if (!is_constructor && /* constructors don't have declared types */ !is_full_physname_constructor && /* " " */ !is_type_conversion_operator (type, i, j)) { type_print (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f, j)), "", stream, -1); fputs_filtered (" ", stream); } if (TYPE_FN_FIELD_STUB (f, j)) /* Build something we can demangle. */ mangled_name = gdb_mangle_name (type, i, j); else mangled_name = TYPE_FN_FIELD_PHYSNAME (f, j); demangled_name = cplus_demangle (mangled_name, DMGL_ANSI | DMGL_PARAMS); if (demangled_name == NULL) { /* in some cases (for instance with the HP demangling), if a function has more than 10 arguments, the demangling will fail. Let's try to reconstruct the function signature from the symbol information */ if (!TYPE_FN_FIELD_STUB (f, j)) { int staticp = TYPE_FN_FIELD_STATIC_P (f, j); struct type *mtype = TYPE_FN_FIELD_TYPE (f, j); cp_type_print_method_args (mtype, "", method_name, staticp, stream); } else fprintf_filtered (stream, _("<badly mangled name '%s'>"), mangled_name); } else { char *p; char *demangled_no_class = remove_qualifiers (demangled_name); /* get rid of the `static' appended by the demangler */ p = strstr (demangled_no_class, " static"); if (p != NULL) { int length = p - demangled_no_class; demangled_no_static = (char *) xmalloc (length + 1); strncpy (demangled_no_static, demangled_no_class, length); *(demangled_no_static + length) = '\0'; fputs_filtered (demangled_no_static, stream); xfree (demangled_no_static); } else fputs_filtered (demangled_no_class, stream); xfree (demangled_name); } if (TYPE_FN_FIELD_STUB (f, j)) xfree (mangled_name); fprintf_filtered (stream, ";\n"); } } fprintfi_filtered (level, stream, "}"); if (TYPE_LOCALTYPE_PTR (type) && show >= 0) fprintfi_filtered (level, stream, _(" (Local at %s:%d)\n"), TYPE_LOCALTYPE_FILE (type), TYPE_LOCALTYPE_LINE (type)); } if (TYPE_CODE (type) == TYPE_CODE_TEMPLATE) goto go_back; break; case TYPE_CODE_ENUM: c_type_print_modifier (type, stream, 0, 1); /* HP C supports sized enums */ if (deprecated_hp_som_som_object_present) switch (TYPE_LENGTH (type)) { case 1: fputs_filtered ("char ", stream); break; case 2: fputs_filtered ("short ", stream); break; default: break; } fprintf_filtered (stream, "enum "); /* Print the tag name if it exists. The aCC compiler emits a spurious "{unnamed struct}"/"{unnamed union}"/"{unnamed enum}" tag for unnamed struct/union/enum's, which we don't want to print. */ if (TYPE_TAG_NAME (type) != NULL && strncmp (TYPE_TAG_NAME (type), "{unnamed", 8)) { fputs_filtered (TYPE_TAG_NAME (type), stream); if (show > 0) fputs_filtered (" ", stream); } wrap_here (" "); if (show < 0) { /* If we just printed a tag name, no need to print anything else. */ if (TYPE_TAG_NAME (type) == NULL) fprintf_filtered (stream, "{...}"); } else if (show > 0 || TYPE_TAG_NAME (type) == NULL) { fprintf_filtered (stream, "{"); len = TYPE_NFIELDS (type); lastval = 0; for (i = 0; i < len; i++) { QUIT; if (i) fprintf_filtered (stream, ", "); wrap_here (" "); fputs_filtered (TYPE_FIELD_NAME (type, i), stream); if (lastval != TYPE_FIELD_BITPOS (type, i)) { /* APPLE LOCAL begin print unsigned */ if (TYPE_FLAGS (type) & TYPE_FLAG_UNSIGNED) fprintf_filtered (stream, " = %u", TYPE_FIELD_BITPOS (type, i)); else fprintf_filtered (stream, " = %d", TYPE_FIELD_BITPOS (type, i)); /* APPLE LOCAL end print unsigned */ lastval = TYPE_FIELD_BITPOS (type, i); } lastval++; } fprintf_filtered (stream, "}"); } break; case TYPE_CODE_VOID: fprintf_filtered (stream, "void"); break; case TYPE_CODE_UNDEF: fprintf_filtered (stream, _("struct <unknown>")); break; case TYPE_CODE_ERROR: fprintf_filtered (stream, _("<unknown type>")); break; case TYPE_CODE_RANGE: /* This should not occur */ fprintf_filtered (stream, _("<range type>")); break; case TYPE_CODE_TEMPLATE: /* Called on "ptype t" where "t" is a template. Prints the template header (with args), e.g.: template <class T1, class T2> class " and then merges with the struct/union/class code to print the rest of the definition. */ c_type_print_modifier (type, stream, 0, 1); fprintf_filtered (stream, "template <"); for (i = 0; i < TYPE_NTEMPLATE_ARGS (type); i++) { struct template_arg templ_arg; templ_arg = TYPE_TEMPLATE_ARG (type, i); fprintf_filtered (stream, "class %s", templ_arg.name); if (i < TYPE_NTEMPLATE_ARGS (type) - 1) fprintf_filtered (stream, ", "); } fprintf_filtered (stream, "> class "); /* Yuck, factor this out to a subroutine so we can call it and return to the point marked with the "goback:" label... - RT */ goto struct_union; go_back: if (TYPE_NINSTANTIATIONS (type) > 0) { fprintf_filtered (stream, _("\ntemplate instantiations:\n")); for (i = 0; i < TYPE_NINSTANTIATIONS (type); i++) { fprintf_filtered (stream, " "); c_type_print_base (TYPE_INSTANTIATION (type, i), stream, 0, level); if (i < TYPE_NINSTANTIATIONS (type) - 1) fprintf_filtered (stream, "\n"); } } break; case TYPE_CODE_NAMESPACE: fputs_filtered ("namespace ", stream); fputs_filtered (TYPE_TAG_NAME (type), stream); break; default: /* Handle types not explicitly handled by the other cases, such as fundamental types. For these, just print whatever the type name is, as recorded in the type itself. If there is no type name, then complain. */ if (TYPE_NAME (type) != NULL) { c_type_print_modifier (type, stream, 0, 1); fputs_filtered (TYPE_NAME (type), stream); } else { /* At least for dump_symtab, it is important that this not be an error (). */ fprintf_filtered (stream, _("<invalid type code %d>"), TYPE_CODE (type)); } break; } }
void pascal_object_print_value_fields (struct type *type, const gdb_byte *valaddr, int offset, CORE_ADDR address, struct ui_file *stream, int recurse, const struct value *val, const struct value_print_options *options, struct type **dont_print_vb, int dont_print_statmem) { int i, len, n_baseclasses; char *last_dont_print = (char *) obstack_next_free (&dont_print_statmem_obstack); type = check_typedef (type); fprintf_filtered (stream, "{"); len = TYPE_NFIELDS (type); n_baseclasses = TYPE_N_BASECLASSES (type); /* Print out baseclasses such that we don't print duplicates of virtual baseclasses. */ if (n_baseclasses > 0) pascal_object_print_value (type, valaddr, offset, address, stream, recurse + 1, val, options, dont_print_vb); if (!len && n_baseclasses == 1) fprintf_filtered (stream, "<No data fields>"); else { struct obstack tmp_obstack = dont_print_statmem_obstack; int fields_seen = 0; if (dont_print_statmem == 0) { /* If we're at top level, carve out a completely fresh chunk of the obstack and use that until this particular invocation returns. */ obstack_finish (&dont_print_statmem_obstack); } for (i = n_baseclasses; i < len; i++) { /* If requested, skip printing of static fields. */ if (!options->pascal_static_field_print && field_is_static (&TYPE_FIELD (type, i))) continue; if (fields_seen) fprintf_filtered (stream, ", "); else if (n_baseclasses > 0) { if (options->prettyformat) { fprintf_filtered (stream, "\n"); print_spaces_filtered (2 + 2 * recurse, stream); fputs_filtered ("members of ", stream); fputs_filtered (type_name_no_tag (type), stream); fputs_filtered (": ", stream); } } fields_seen = 1; if (options->prettyformat) { fprintf_filtered (stream, "\n"); print_spaces_filtered (2 + 2 * recurse, stream); } else { wrap_here (n_spaces (2 + 2 * recurse)); } annotate_field_begin (TYPE_FIELD_TYPE (type, i)); if (field_is_static (&TYPE_FIELD (type, i))) fputs_filtered ("static ", stream); fprintf_symbol_filtered (stream, TYPE_FIELD_NAME (type, i), language_cplus, DMGL_PARAMS | DMGL_ANSI); annotate_field_name_end (); fputs_filtered (" = ", stream); annotate_field_value (); if (!field_is_static (&TYPE_FIELD (type, i)) && TYPE_FIELD_PACKED (type, i)) { struct value *v; /* Bitfields require special handling, especially due to byte order problems. */ if (TYPE_FIELD_IGNORE (type, i)) { fputs_filtered ("<optimized out or zero length>", stream); } else if (value_bits_synthetic_pointer (val, TYPE_FIELD_BITPOS (type, i), TYPE_FIELD_BITSIZE (type, i))) { fputs_filtered (_("<synthetic pointer>"), stream); } else { struct value_print_options opts = *options; v = value_field_bitfield (type, i, valaddr, offset, val); opts.deref_ref = 0; common_val_print (v, stream, recurse + 1, &opts, current_language); } } else { if (TYPE_FIELD_IGNORE (type, i)) { fputs_filtered ("<optimized out or zero length>", stream); } else if (field_is_static (&TYPE_FIELD (type, i))) { /* struct value *v = value_static_field (type, i); v4.17 specific. */ struct value *v; v = value_field_bitfield (type, i, valaddr, offset, val); if (v == NULL) val_print_optimized_out (NULL, stream); else pascal_object_print_static_field (v, stream, recurse + 1, options); } else { struct value_print_options opts = *options; opts.deref_ref = 0; /* val_print (TYPE_FIELD_TYPE (type, i), valaddr + TYPE_FIELD_BITPOS (type, i) / 8, address + TYPE_FIELD_BITPOS (type, i) / 8, 0, stream, format, 0, recurse + 1, pretty); */ val_print (TYPE_FIELD_TYPE (type, i), valaddr, offset + TYPE_FIELD_BITPOS (type, i) / 8, address, stream, recurse + 1, val, &opts, current_language); } } annotate_field_end (); } if (dont_print_statmem == 0) { /* Free the space used to deal with the printing of the members from top level. */ obstack_free (&dont_print_statmem_obstack, last_dont_print); dont_print_statmem_obstack = tmp_obstack; } if (options->prettyformat) { fprintf_filtered (stream, "\n"); print_spaces_filtered (2 * recurse, stream); } } fprintf_filtered (stream, "}"); }
void pascal_type_print_base (struct type *type, struct ui_file *stream, int show, int level) { int i; int len; int lastval; enum { s_none, s_public, s_private, s_protected } section_type; QUIT; wrap_here (" "); if (type == NULL) { fputs_filtered ("<type unknown>", stream); return; } /* void pointer */ if ((TYPE_CODE (type) == TYPE_CODE_PTR) && (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_VOID)) { fputs_filtered (TYPE_NAME (type) ? TYPE_NAME (type) : "pointer", stream); return; } /* When SHOW is zero or less, and there is a valid type name, then always just print the type name directly from the type. */ if (show <= 0 && TYPE_NAME (type) != NULL) { fputs_filtered (TYPE_NAME (type), stream); return; } CHECK_TYPEDEF (type); switch (TYPE_CODE (type)) { case TYPE_CODE_TYPEDEF: case TYPE_CODE_PTR: case TYPE_CODE_MEMBER: case TYPE_CODE_REF: /* case TYPE_CODE_FUNC: case TYPE_CODE_METHOD: */ pascal_type_print_base (TYPE_TARGET_TYPE (type), stream, show, level); break; case TYPE_CODE_ARRAY: /* pascal_type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, 0); pascal_type_print_base (TYPE_TARGET_TYPE (type), stream, show, level); pascal_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 0, 0); */ pascal_print_type (TYPE_TARGET_TYPE (type), NULL, stream, 0, 0); break; case TYPE_CODE_FUNC: case TYPE_CODE_METHOD: /* pascal_type_print_base (TYPE_TARGET_TYPE (type), stream, show, level); only after args !! */ break; case TYPE_CODE_STRUCT: if (TYPE_TAG_NAME (type) != NULL) { fputs_filtered (TYPE_TAG_NAME (type), stream); fputs_filtered (" = ", stream); } if (HAVE_CPLUS_STRUCT (type)) { fprintf_filtered (stream, "class "); } else { fprintf_filtered (stream, "record "); } goto struct_union; case TYPE_CODE_UNION: if (TYPE_TAG_NAME (type) != NULL) { fputs_filtered (TYPE_TAG_NAME (type), stream); fputs_filtered (" = ", stream); } fprintf_filtered (stream, "case <?> of "); struct_union: wrap_here (" "); if (show < 0) { /* If we just printed a tag name, no need to print anything else. */ if (TYPE_TAG_NAME (type) == NULL) fprintf_filtered (stream, "{...}"); } else if (show > 0 || TYPE_TAG_NAME (type) == NULL) { pascal_type_print_derivation_info (stream, type); fprintf_filtered (stream, "\n"); if ((TYPE_NFIELDS (type) == 0) && (TYPE_NFN_FIELDS (type) == 0)) { if (TYPE_STUB (type)) fprintfi_filtered (level + 4, stream, "<incomplete type>\n"); else fprintfi_filtered (level + 4, stream, "<no data fields>\n"); } /* Start off with no specific section type, so we can print one for the first field we find, and use that section type thereafter until we find another type. */ section_type = s_none; /* If there is a base class for this type, do not print the field that it occupies. */ len = TYPE_NFIELDS (type); for (i = TYPE_N_BASECLASSES (type); i < len; i++) { QUIT; /* Don't print out virtual function table. */ if (DEPRECATED_STREQN (TYPE_FIELD_NAME (type, i), "_vptr", 5) && is_cplus_marker ((TYPE_FIELD_NAME (type, i))[5])) continue; /* If this is a pascal object or class we can print the various section labels. */ if (HAVE_CPLUS_STRUCT (type)) { if (TYPE_FIELD_PROTECTED (type, i)) { if (section_type != s_protected) { section_type = s_protected; fprintfi_filtered (level + 2, stream, "protected\n"); } } else if (TYPE_FIELD_PRIVATE (type, i)) { if (section_type != s_private) { section_type = s_private; fprintfi_filtered (level + 2, stream, "private\n"); } } else { if (section_type != s_public) { section_type = s_public; fprintfi_filtered (level + 2, stream, "public\n"); } } } print_spaces_filtered (level + 4, stream); if (TYPE_FIELD_STATIC (type, i)) { fprintf_filtered (stream, "static "); } pascal_print_type (TYPE_FIELD_TYPE (type, i), TYPE_FIELD_NAME (type, i), stream, show - 1, level + 4); if (!TYPE_FIELD_STATIC (type, i) && TYPE_FIELD_PACKED (type, i)) { /* It is a bitfield. This code does not attempt to look at the bitpos and reconstruct filler, unnamed fields. This would lead to misleading results if the compiler does not put out fields for such things (I don't know what it does). */ fprintf_filtered (stream, " : %d", TYPE_FIELD_BITSIZE (type, i)); } fprintf_filtered (stream, ";\n"); } /* If there are both fields and methods, put a space between. */ len = TYPE_NFN_FIELDS (type); if (len && section_type != s_none) fprintf_filtered (stream, "\n"); /* Pbject pascal: print out the methods */ for (i = 0; i < len; i++) { struct fn_field *f = TYPE_FN_FIELDLIST1 (type, i); int j, len2 = TYPE_FN_FIELDLIST_LENGTH (type, i); char *method_name = TYPE_FN_FIELDLIST_NAME (type, i); /* this is GNU C++ specific how can we know constructor/destructor? It might work for GNU pascal */ for (j = 0; j < len2; j++) { char *physname = TYPE_FN_FIELD_PHYSNAME (f, j); int is_constructor = DEPRECATED_STREQN (physname, "__ct__", 6); int is_destructor = DEPRECATED_STREQN (physname, "__dt__", 6); QUIT; if (TYPE_FN_FIELD_PROTECTED (f, j)) { if (section_type != s_protected) { section_type = s_protected; fprintfi_filtered (level + 2, stream, "protected\n"); } } else if (TYPE_FN_FIELD_PRIVATE (f, j)) { if (section_type != s_private) { section_type = s_private; fprintfi_filtered (level + 2, stream, "private\n"); } } else { if (section_type != s_public) { section_type = s_public; fprintfi_filtered (level + 2, stream, "public\n"); } } print_spaces_filtered (level + 4, stream); if (TYPE_FN_FIELD_STATIC_P (f, j)) fprintf_filtered (stream, "static "); if (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f, j)) == 0) { /* Keep GDB from crashing here. */ fprintf_filtered (stream, "<undefined type> %s;\n", TYPE_FN_FIELD_PHYSNAME (f, j)); break; } if (is_constructor) { fprintf_filtered (stream, "constructor "); } else if (is_destructor) { fprintf_filtered (stream, "destructor "); } else if (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f, j)) != 0 && TYPE_CODE (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f, j))) != TYPE_CODE_VOID) { fprintf_filtered (stream, "function "); } else { fprintf_filtered (stream, "procedure "); } /* this does not work, no idea why !! */ pascal_type_print_method_args (physname, method_name, stream); if (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f, j)) != 0 && TYPE_CODE (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f, j))) != TYPE_CODE_VOID) { fputs_filtered (" : ", stream); type_print (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f, j)), "", stream, -1); } if (TYPE_FN_FIELD_VIRTUAL_P (f, j)) fprintf_filtered (stream, "; virtual"); fprintf_filtered (stream, ";\n"); } } fprintfi_filtered (level, stream, "end"); } break; case TYPE_CODE_ENUM: if (TYPE_TAG_NAME (type) != NULL) { fputs_filtered (TYPE_TAG_NAME (type), stream); if (show > 0) fputs_filtered (" ", stream); } /* enum is just defined by type enume_name = (enum_member1,enum_member2,...) */ fprintf_filtered (stream, " = "); wrap_here (" "); if (show < 0) { /* If we just printed a tag name, no need to print anything else. */ if (TYPE_TAG_NAME (type) == NULL) fprintf_filtered (stream, "(...)"); } else if (show > 0 || TYPE_TAG_NAME (type) == NULL) { fprintf_filtered (stream, "("); len = TYPE_NFIELDS (type); lastval = 0; for (i = 0; i < len; i++) { QUIT; if (i) fprintf_filtered (stream, ", "); wrap_here (" "); fputs_filtered (TYPE_FIELD_NAME (type, i), stream); if (lastval != TYPE_FIELD_BITPOS (type, i)) { fprintf_filtered (stream, " := %d", TYPE_FIELD_BITPOS (type, i)); lastval = TYPE_FIELD_BITPOS (type, i); } lastval++; } fprintf_filtered (stream, ")"); } break; case TYPE_CODE_VOID: fprintf_filtered (stream, "void"); break; case TYPE_CODE_UNDEF: fprintf_filtered (stream, "record <unknown>"); break; case TYPE_CODE_ERROR: fprintf_filtered (stream, "<unknown type>"); break; /* this probably does not work for enums */ case TYPE_CODE_RANGE: { struct type *target = TYPE_TARGET_TYPE (type); if (target == NULL) target = builtin_type_long; print_type_scalar (target, TYPE_LOW_BOUND (type), stream); fputs_filtered ("..", stream); print_type_scalar (target, TYPE_HIGH_BOUND (type), stream); } break; case TYPE_CODE_SET: fputs_filtered ("set of ", stream); pascal_print_type (TYPE_INDEX_TYPE (type), "", stream, show - 1, level); break; case TYPE_CODE_BITSTRING: fputs_filtered ("BitString", stream); break; case TYPE_CODE_STRING: fputs_filtered ("String", stream); break; default: /* Handle types not explicitly handled by the other cases, such as fundamental types. For these, just print whatever the type name is, as recorded in the type itself. If there is no type name, then complain. */ if (TYPE_NAME (type) != NULL) { fputs_filtered (TYPE_NAME (type), stream); } else { /* At least for dump_symtab, it is important that this not be an error (). */ fprintf_filtered (stream, "<invalid unnamed pascal type code %d>", TYPE_CODE (type)); } break; } }
static void java_print_value_fields (struct type *type, const gdb_byte *valaddr, int offset, CORE_ADDR address, struct ui_file *stream, int recurse, const struct value *val, const struct value_print_options *options) { int i, len, n_baseclasses; CHECK_TYPEDEF (type); fprintf_filtered (stream, "{"); len = TYPE_NFIELDS (type); n_baseclasses = TYPE_N_BASECLASSES (type); if (n_baseclasses > 0) { int i, n_baseclasses = TYPE_N_BASECLASSES (type); for (i = 0; i < n_baseclasses; i++) { int boffset; struct type *baseclass = check_typedef (TYPE_BASECLASS (type, i)); const char *basename = TYPE_NAME (baseclass); const gdb_byte *base_valaddr; if (BASETYPE_VIA_VIRTUAL (type, i)) continue; if (basename != NULL && strcmp (basename, "java.lang.Object") == 0) continue; boffset = 0; if (options->prettyformat) { fprintf_filtered (stream, "\n"); print_spaces_filtered (2 * (recurse + 1), stream); } fputs_filtered ("<", stream); /* Not sure what the best notation is in the case where there is no baseclass name. */ fputs_filtered (basename ? basename : "", stream); fputs_filtered ("> = ", stream); base_valaddr = valaddr; java_print_value_fields (baseclass, base_valaddr, offset + boffset, address, stream, recurse + 1, val, options); fputs_filtered (", ", stream); } } if (!len && n_baseclasses == 1) fprintf_filtered (stream, "<No data fields>"); else { int fields_seen = 0; for (i = n_baseclasses; i < len; i++) { /* If requested, skip printing of static fields. */ if (field_is_static (&TYPE_FIELD (type, i))) { const char *name = TYPE_FIELD_NAME (type, i); if (!options->static_field_print) continue; if (name != NULL && strcmp (name, "class") == 0) continue; } if (fields_seen) fprintf_filtered (stream, ", "); else if (n_baseclasses > 0) { if (options->prettyformat) { fprintf_filtered (stream, "\n"); print_spaces_filtered (2 + 2 * recurse, stream); fputs_filtered ("members of ", stream); fputs_filtered (type_name_no_tag (type), stream); fputs_filtered (": ", stream); } } fields_seen = 1; if (options->prettyformat) { fprintf_filtered (stream, "\n"); print_spaces_filtered (2 + 2 * recurse, stream); } else { wrap_here (n_spaces (2 + 2 * recurse)); } annotate_field_begin (TYPE_FIELD_TYPE (type, i)); if (field_is_static (&TYPE_FIELD (type, i))) fputs_filtered ("static ", stream); fprintf_symbol_filtered (stream, TYPE_FIELD_NAME (type, i), language_cplus, DMGL_PARAMS | DMGL_ANSI); annotate_field_name_end (); fputs_filtered (": ", stream); annotate_field_value (); if (!field_is_static (&TYPE_FIELD (type, i)) && TYPE_FIELD_PACKED (type, i)) { struct value *v; /* Bitfields require special handling, especially due to byte order problems. */ if (TYPE_FIELD_IGNORE (type, i)) { fputs_filtered ("<optimized out or zero length>", stream); } else if (value_bits_synthetic_pointer (val, TYPE_FIELD_BITPOS (type, i), TYPE_FIELD_BITSIZE (type, i))) { fputs_filtered (_("<synthetic pointer>"), stream); } else if (!value_bits_valid (val, TYPE_FIELD_BITPOS (type, i), TYPE_FIELD_BITSIZE (type, i))) { val_print_optimized_out (val, stream); } else { struct value_print_options opts; v = value_field_bitfield (type, i, valaddr, offset, val); opts = *options; opts.deref_ref = 0; common_val_print (v, stream, recurse + 1, &opts, current_language); } } else { if (TYPE_FIELD_IGNORE (type, i)) { fputs_filtered ("<optimized out or zero length>", stream); } else if (field_is_static (&TYPE_FIELD (type, i))) { struct value_print_options opts; struct value *v = value_static_field (type, i); struct type *t = check_typedef (value_type (v)); if (TYPE_CODE (t) == TYPE_CODE_STRUCT) v = value_addr (v); opts = *options; opts.deref_ref = 0; common_val_print (v, stream, recurse + 1, &opts, current_language); } else if (TYPE_FIELD_TYPE (type, i) == NULL) fputs_filtered ("<unknown type>", stream); else { struct value_print_options opts = *options; opts.deref_ref = 0; val_print (TYPE_FIELD_TYPE (type, i), valaddr, offset + TYPE_FIELD_BITPOS (type, i) / 8, address, stream, recurse + 1, val, &opts, current_language); } } annotate_field_end (); } if (options->prettyformat) { fprintf_filtered (stream, "\n"); print_spaces_filtered (2 * recurse, stream); } } fprintf_filtered (stream, "}"); }
/* Helper function for typy_fields which converts a single field to a dictionary. Returns NULL on error. */ static PyObject * convert_field (struct type *type, int field) { PyObject *result = field_new (); PyObject *arg; if (!result) return NULL; if (!field_is_static (&TYPE_FIELD (type, field))) { arg = PyLong_FromLong (TYPE_FIELD_BITPOS (type, field)); if (!arg) goto fail; if (PyObject_SetAttrString (result, "bitpos", arg) < 0) goto failarg; } if (TYPE_FIELD_NAME (type, field)) arg = PyString_FromString (TYPE_FIELD_NAME (type, field)); else { arg = Py_None; Py_INCREF (arg); } if (!arg) goto fail; if (PyObject_SetAttrString (result, "name", arg) < 0) goto failarg; arg = TYPE_FIELD_ARTIFICIAL (type, field) ? Py_True : Py_False; Py_INCREF (arg); if (PyObject_SetAttrString (result, "artificial", arg) < 0) goto failarg; if (TYPE_CODE (type) == TYPE_CODE_CLASS) arg = field < TYPE_N_BASECLASSES (type) ? Py_True : Py_False; else arg = Py_False; Py_INCREF (arg); if (PyObject_SetAttrString (result, "is_base_class", arg) < 0) goto failarg; arg = PyLong_FromLong (TYPE_FIELD_BITSIZE (type, field)); if (!arg) goto fail; if (PyObject_SetAttrString (result, "bitsize", arg) < 0) goto failarg; /* A field can have a NULL type in some situations. */ if (TYPE_FIELD_TYPE (type, field) == NULL) { arg = Py_None; Py_INCREF (arg); } else arg = type_to_type_object (TYPE_FIELD_TYPE (type, field)); if (!arg) goto fail; if (PyObject_SetAttrString (result, "type", arg) < 0) goto failarg; return result; failarg: Py_DECREF (arg); fail: Py_DECREF (result); return NULL; }
static void print_array_type (struct type *type, struct ui_file *stream, int show, int level, const struct type_print_options *flags) { int bitsize; int n_indices; if (ada_is_constrained_packed_array_type (type)) type = ada_coerce_to_simple_array_type (type); bitsize = 0; fprintf_filtered (stream, "array ("); if (type == NULL) { fprintf_filtered (stream, _("<undecipherable array type>")); return; } n_indices = -1; if (ada_is_simple_array_type (type)) { struct type *range_desc_type; struct type *arr_type; range_desc_type = ada_find_parallel_type (type, "___XA"); ada_fixup_array_indexes_type (range_desc_type); bitsize = 0; if (range_desc_type == NULL) { for (arr_type = type; TYPE_CODE (arr_type) == TYPE_CODE_ARRAY; arr_type = TYPE_TARGET_TYPE (arr_type)) { if (arr_type != type) fprintf_filtered (stream, ", "); print_range (TYPE_INDEX_TYPE (arr_type), stream); if (TYPE_FIELD_BITSIZE (arr_type, 0) > 0) bitsize = TYPE_FIELD_BITSIZE (arr_type, 0); } } else { int k; n_indices = TYPE_NFIELDS (range_desc_type); for (k = 0, arr_type = type; k < n_indices; k += 1, arr_type = TYPE_TARGET_TYPE (arr_type)) { if (k > 0) fprintf_filtered (stream, ", "); print_range_type (TYPE_FIELD_TYPE (range_desc_type, k), stream); if (TYPE_FIELD_BITSIZE (arr_type, 0) > 0) bitsize = TYPE_FIELD_BITSIZE (arr_type, 0); } } } else { int i, i0; for (i = i0 = ada_array_arity (type); i > 0; i -= 1) fprintf_filtered (stream, "%s<>", i == i0 ? "" : ", "); } fprintf_filtered (stream, ") of "); wrap_here (""); ada_print_type (ada_array_element_type (type, n_indices), "", stream, show == 0 ? 0 : show - 1, level + 1, flags); if (bitsize > 0) fprintf_filtered (stream, " <packed: %d-bit elements>", bitsize); }
static int print_field_values (struct type *type, const gdb_byte *valaddr, int offset, struct ui_file *stream, int recurse, struct value *val, const struct value_print_options *options, int comma_needed, struct type *outer_type, int outer_offset, const struct language_defn *language) { int i, len; len = TYPE_NFIELDS (type); for (i = 0; i < len; i += 1) { if (ada_is_ignored_field (type, i)) continue; if (ada_is_wrapper_field (type, i)) { comma_needed = print_field_values (TYPE_FIELD_TYPE (type, i), valaddr, (offset + TYPE_FIELD_BITPOS (type, i) / HOST_CHAR_BIT), stream, recurse, val, options, comma_needed, type, offset, language); continue; } else if (ada_is_variant_part (type, i)) { comma_needed = print_variant_part (type, i, valaddr, offset, stream, recurse, val, options, comma_needed, outer_type, outer_offset, language); continue; } if (comma_needed) fprintf_filtered (stream, ", "); comma_needed = 1; if (options->prettyformat) { fprintf_filtered (stream, "\n"); print_spaces_filtered (2 + 2 * recurse, stream); } else { wrap_here (n_spaces (2 + 2 * recurse)); } annotate_field_begin (TYPE_FIELD_TYPE (type, i)); fprintf_filtered (stream, "%.*s", ada_name_prefix_len (TYPE_FIELD_NAME (type, i)), TYPE_FIELD_NAME (type, i)); annotate_field_name_end (); fputs_filtered (" => ", stream); annotate_field_value (); if (TYPE_FIELD_PACKED (type, i)) { /* Bitfields require special handling, especially due to byte order problems. */ if (HAVE_CPLUS_STRUCT (type) && TYPE_FIELD_IGNORE (type, i)) { fputs_filtered (_("<optimized out or zero length>"), stream); } else { struct value *v; int bit_pos = TYPE_FIELD_BITPOS (type, i); int bit_size = TYPE_FIELD_BITSIZE (type, i); struct value_print_options opts; adjust_type_signedness (TYPE_FIELD_TYPE (type, i)); v = ada_value_primitive_packed_val (NULL, valaddr, offset + bit_pos / HOST_CHAR_BIT, bit_pos % HOST_CHAR_BIT, bit_size, TYPE_FIELD_TYPE (type, i)); opts = *options; opts.deref_ref = 0; val_print (TYPE_FIELD_TYPE (type, i), value_embedded_offset (v), 0, stream, recurse + 1, v, &opts, language); } } else { struct value_print_options opts = *options; opts.deref_ref = 0; val_print (TYPE_FIELD_TYPE (type, i), (offset + TYPE_FIELD_BITPOS (type, i) / HOST_CHAR_BIT), 0, stream, recurse + 1, val, &opts, language); } annotate_field_end (); } return comma_needed; }
static void val_print_packed_array_elements (struct type *type, const gdb_byte *valaddr, int offset, int bitoffset, struct ui_file *stream, int recurse, struct value *val, const struct value_print_options *options) { unsigned int i; unsigned int things_printed = 0; unsigned len; struct type *elttype, *index_type; unsigned long bitsize = TYPE_FIELD_BITSIZE (type, 0); struct value *mark = value_mark (); LONGEST low = 0; elttype = TYPE_TARGET_TYPE (type); index_type = TYPE_INDEX_TYPE (type); { LONGEST high; if (get_discrete_bounds (index_type, &low, &high) < 0) len = 1; else len = high - low + 1; } i = 0; annotate_array_section_begin (i, elttype); while (i < len && things_printed < options->print_max) { struct value *v0, *v1; int i0; if (i != 0) { if (options->prettyformat_arrays) { fprintf_filtered (stream, ",\n"); print_spaces_filtered (2 + 2 * recurse, stream); } else { fprintf_filtered (stream, ", "); } } wrap_here (n_spaces (2 + 2 * recurse)); maybe_print_array_index (index_type, i + low, stream, options); i0 = i; v0 = ada_value_primitive_packed_val (NULL, valaddr + offset, (i0 * bitsize) / HOST_CHAR_BIT, (i0 * bitsize) % HOST_CHAR_BIT, bitsize, elttype); while (1) { i += 1; if (i >= len) break; v1 = ada_value_primitive_packed_val (NULL, valaddr + offset, (i * bitsize) / HOST_CHAR_BIT, (i * bitsize) % HOST_CHAR_BIT, bitsize, elttype); if (TYPE_LENGTH (check_typedef (value_type (v0))) != TYPE_LENGTH (check_typedef (value_type (v1)))) break; if (!value_contents_eq (v0, value_embedded_offset (v0), v1, value_embedded_offset (v1), TYPE_LENGTH (check_typedef (value_type (v0))))) break; } if (i - i0 > options->repeat_count_threshold) { struct value_print_options opts = *options; opts.deref_ref = 0; val_print (elttype, value_embedded_offset (v0), 0, stream, recurse + 1, v0, &opts, current_language); annotate_elt_rep (i - i0); fprintf_filtered (stream, _(" <repeats %u times>"), i - i0); annotate_elt_rep_end (); } else { int j; struct value_print_options opts = *options; opts.deref_ref = 0; for (j = i0; j < i; j += 1) { if (j > i0) { if (options->prettyformat_arrays) { fprintf_filtered (stream, ",\n"); print_spaces_filtered (2 + 2 * recurse, stream); } else { fprintf_filtered (stream, ", "); } wrap_here (n_spaces (2 + 2 * recurse)); maybe_print_array_index (index_type, j + low, stream, options); } val_print (elttype, value_embedded_offset (v0), 0, stream, recurse + 1, v0, &opts, current_language); annotate_elt (); } } things_printed += i - i0; } annotate_array_section_end (); if (i < len) { fprintf_filtered (stream, "..."); } value_free_to_mark (mark); }
static int print_field_values (struct type *type, char *valaddr, struct ui_file *stream, int format, int recurse, enum val_prettyprint pretty, int comma_needed, struct type *outer_type, char *outer_valaddr) { int i, len; len = TYPE_NFIELDS (type); for (i = 0; i < len; i += 1) { if (ada_is_ignored_field (type, i)) continue; if (ada_is_wrapper_field (type, i)) { comma_needed = print_field_values (TYPE_FIELD_TYPE (type, i), valaddr + TYPE_FIELD_BITPOS (type, i) / HOST_CHAR_BIT, stream, format, recurse, pretty, comma_needed, type, valaddr); continue; } else if (ada_is_variant_part (type, i)) { comma_needed = print_variant_part (type, i, valaddr, stream, format, recurse, pretty, comma_needed, outer_type, outer_valaddr); continue; } if (comma_needed) fprintf_filtered (stream, ", "); comma_needed = 1; if (pretty) { fprintf_filtered (stream, "\n"); print_spaces_filtered (2 + 2 * recurse, stream); } else { wrap_here (n_spaces (2 + 2 * recurse)); } if (inspect_it) { if (TYPE_CODE (TYPE_FIELD_TYPE (type, i)) == TYPE_CODE_PTR) fputs_filtered ("\"( ptr \"", stream); else fputs_filtered ("\"( nodef \"", stream); fprintf_symbol_filtered (stream, TYPE_FIELD_NAME (type, i), language_cplus, DMGL_NO_OPTS); fputs_filtered ("\" \"", stream); fprintf_symbol_filtered (stream, TYPE_FIELD_NAME (type, i), language_cplus, DMGL_NO_OPTS); fputs_filtered ("\") \"", stream); } else { annotate_field_begin (TYPE_FIELD_TYPE (type, i)); fprintf_filtered (stream, "%.*s", ada_name_prefix_len (TYPE_FIELD_NAME (type, i)), TYPE_FIELD_NAME (type, i)); annotate_field_name_end (); fputs_filtered (" => ", stream); annotate_field_value (); } if (TYPE_FIELD_PACKED (type, i)) { struct value *v; /* Bitfields require special handling, especially due to byte order problems. */ if (TYPE_CPLUS_SPECIFIC (type) != NULL && TYPE_FIELD_IGNORE (type, i)) { fputs_filtered ("<optimized out or zero length>", stream); } else { int bit_pos = TYPE_FIELD_BITPOS (type, i); int bit_size = TYPE_FIELD_BITSIZE (type, i); adjust_type_signedness (TYPE_FIELD_TYPE (type, i)); v = ada_value_primitive_packed_val (NULL, valaddr, bit_pos / HOST_CHAR_BIT, bit_pos % HOST_CHAR_BIT, bit_size, TYPE_FIELD_TYPE (type, i)); val_print (TYPE_FIELD_TYPE (type, i), VALUE_CONTENTS (v), 0, 0, stream, format, 0, recurse + 1, pretty); } } else ada_val_print (TYPE_FIELD_TYPE (type, i), valaddr + TYPE_FIELD_BITPOS (type, i) / HOST_CHAR_BIT, 0, 0, stream, format, 0, recurse + 1, pretty); annotate_field_end (); } return comma_needed; }
static int ada_val_print_1 (struct type *type, char *valaddr0, int embedded_offset, CORE_ADDR address, struct ui_file *stream, int format, int deref_ref, int recurse, enum val_prettyprint pretty) { unsigned int len; int i; struct type *elttype; unsigned int eltlen; LONGEST val; char *valaddr = valaddr0 + embedded_offset; CHECK_TYPEDEF (type); if (ada_is_array_descriptor_type (type) || ada_is_packed_array_type (type)) { int retn; struct value *mark = value_mark (); struct value *val; val = value_from_contents_and_address (type, valaddr, address); val = ada_coerce_to_simple_array_ptr (val); if (val == NULL) { fprintf_filtered (stream, "(null)"); retn = 0; } else retn = ada_val_print_1 (VALUE_TYPE (val), VALUE_CONTENTS (val), 0, VALUE_ADDRESS (val), stream, format, deref_ref, recurse, pretty); value_free_to_mark (mark); return retn; } valaddr = ada_aligned_value_addr (type, valaddr); embedded_offset -= valaddr - valaddr0 - embedded_offset; type = printable_val_type (type, valaddr); switch (TYPE_CODE (type)) { default: return c_val_print (type, valaddr0, embedded_offset, address, stream, format, deref_ref, recurse, pretty); case TYPE_CODE_PTR: { int ret = c_val_print (type, valaddr0, embedded_offset, address, stream, format, deref_ref, recurse, pretty); if (ada_is_tag_type (type)) { struct value *val = value_from_contents_and_address (type, valaddr, address); const char *name = ada_tag_name (val); if (name != NULL) fprintf_filtered (stream, " (%s)", name); return 0; } return ret; } case TYPE_CODE_INT: case TYPE_CODE_RANGE: if (ada_is_fixed_point_type (type)) { LONGEST v = unpack_long (type, valaddr); int len = TYPE_LENGTH (type); fprintf_filtered (stream, len < 4 ? "%.11g" : "%.17g", (double) ada_fixed_to_float (type, v)); return 0; } else if (ada_is_vax_floating_type (type)) { struct value *val = value_from_contents_and_address (type, valaddr, address); struct value *func = ada_vax_float_print_function (type); if (func != 0) { static struct type *parray_of_char = NULL; struct value *printable_val; if (parray_of_char == NULL) parray_of_char = make_pointer_type (create_array_type (NULL, builtin_type_char, create_range_type (NULL, builtin_type_int, 0, 32)), NULL); printable_val = value_ind (value_cast (parray_of_char, call_function_by_hand (func, 1, &val))); fprintf_filtered (stream, "%s", VALUE_CONTENTS (printable_val)); return 0; } /* No special printing function. Do as best we can. */ } else if (TYPE_CODE (type) == TYPE_CODE_RANGE) { struct type *target_type = TYPE_TARGET_TYPE (type); if (TYPE_LENGTH (type) != TYPE_LENGTH (target_type)) { /* Obscure case of range type that has different length from its base type. Perform a conversion, or we will get a nonsense value. Actually, we could use the same code regardless of lengths; I'm just avoiding a cast. */ struct value *v = value_cast (target_type, value_from_contents_and_address (type, valaddr, 0)); return ada_val_print_1 (target_type, VALUE_CONTENTS (v), 0, 0, stream, format, 0, recurse + 1, pretty); } else return ada_val_print_1 (TYPE_TARGET_TYPE (type), valaddr0, embedded_offset, address, stream, format, deref_ref, recurse, pretty); } else { format = format ? format : output_format; if (format) { print_scalar_formatted (valaddr, type, format, 0, stream); } else if (ada_is_system_address_type (type)) { /* FIXME: We want to print System.Address variables using the same format as for any access type. But for some reason GNAT encodes the System.Address type as an int, so we have to work-around this deficiency by handling System.Address values as a special case. */ fprintf_filtered (stream, "("); type_print (type, "", stream, -1); fprintf_filtered (stream, ") "); print_address_numeric (extract_typed_address (valaddr, builtin_type_void_data_ptr), 1, stream); } else { val_print_type_code_int (type, valaddr, stream); if (ada_is_character_type (type)) { fputs_filtered (" ", stream); ada_printchar ((unsigned char) unpack_long (type, valaddr), stream); } } return 0; } case TYPE_CODE_ENUM: if (format) { print_scalar_formatted (valaddr, type, format, 0, stream); break; } len = TYPE_NFIELDS (type); val = unpack_long (type, valaddr); for (i = 0; i < len; i++) { QUIT; if (val == TYPE_FIELD_BITPOS (type, i)) { break; } } if (i < len) { const char *name = ada_enum_name (TYPE_FIELD_NAME (type, i)); if (name[0] == '\'') fprintf_filtered (stream, "%ld %s", (long) val, name); else fputs_filtered (name, stream); } else { print_longest (stream, 'd', 0, val); } break; case TYPE_CODE_FLT: if (format) return c_val_print (type, valaddr0, embedded_offset, address, stream, format, deref_ref, recurse, pretty); else ada_print_floating (valaddr0 + embedded_offset, type, stream); break; case TYPE_CODE_UNION: case TYPE_CODE_STRUCT: if (ada_is_bogus_array_descriptor (type)) { fprintf_filtered (stream, "(...?)"); return 0; } else { print_record (type, valaddr, stream, format, recurse, pretty); return 0; } case TYPE_CODE_ARRAY: elttype = TYPE_TARGET_TYPE (type); if (elttype == NULL) eltlen = 0; else eltlen = TYPE_LENGTH (elttype); /* FIXME: This doesn't deal with non-empty arrays of 0-length items (not a typical case!) */ if (eltlen == 0) len = 0; else len = TYPE_LENGTH (type) / eltlen; /* For an array of chars, print with string syntax. */ if (ada_is_string_type (type) && (format == 0 || format == 's')) { if (prettyprint_arrays) { print_spaces_filtered (2 + 2 * recurse, stream); } /* If requested, look for the first null char and only print elements up to it. */ if (stop_print_at_null) { int temp_len; /* Look for a NULL char. */ for (temp_len = 0; temp_len < len && temp_len < print_max && char_at (valaddr, temp_len, eltlen) != 0; temp_len += 1); len = temp_len; } printstr (stream, valaddr, len, 0, eltlen); } else { len = 0; fprintf_filtered (stream, "("); print_optional_low_bound (stream, type); if (TYPE_FIELD_BITSIZE (type, 0) > 0) val_print_packed_array_elements (type, valaddr, 0, stream, format, recurse, pretty); else val_print_array_elements (type, valaddr, address, stream, format, deref_ref, recurse, pretty, 0); fprintf_filtered (stream, ")"); } gdb_flush (stream); return len; case TYPE_CODE_REF: elttype = check_typedef (TYPE_TARGET_TYPE (type)); /* De-reference the reference */ if (deref_ref) { if (TYPE_CODE (elttype) != TYPE_CODE_UNDEF) { LONGEST deref_val_int = (LONGEST) unpack_pointer (lookup_pointer_type (builtin_type_void), valaddr); if (deref_val_int != 0) { struct value *deref_val = ada_value_ind (value_from_longest (lookup_pointer_type (elttype), deref_val_int)); val_print (VALUE_TYPE (deref_val), VALUE_CONTENTS (deref_val), 0, VALUE_ADDRESS (deref_val), stream, format, deref_ref, recurse + 1, pretty); } else fputs_filtered ("(null)", stream); } else fputs_filtered ("???", stream); } break; } gdb_flush (stream); return 0; }
static void val_print_packed_array_elements (struct type *type, char *valaddr, int bitoffset, struct ui_file *stream, int format, int recurse, enum val_prettyprint pretty) { unsigned int i; unsigned int things_printed = 0; unsigned len; struct type *elttype; unsigned eltlen; unsigned long bitsize = TYPE_FIELD_BITSIZE (type, 0); struct value *mark = value_mark (); elttype = TYPE_TARGET_TYPE (type); eltlen = TYPE_LENGTH (check_typedef (elttype)); { LONGEST low, high; if (get_discrete_bounds (TYPE_FIELD_TYPE (type, 0), &low, &high) < 0) len = 1; else len = high - low + 1; } i = 0; annotate_array_section_begin (i, elttype); while (i < len && things_printed < print_max) { struct value *v0, *v1; int i0; if (i != 0) { if (prettyprint_arrays) { fprintf_filtered (stream, ",\n"); print_spaces_filtered (2 + 2 * recurse, stream); } else { fprintf_filtered (stream, ", "); } } wrap_here (n_spaces (2 + 2 * recurse)); i0 = i; v0 = ada_value_primitive_packed_val (NULL, valaddr, (i0 * bitsize) / HOST_CHAR_BIT, (i0 * bitsize) % HOST_CHAR_BIT, bitsize, elttype); while (1) { i += 1; if (i >= len) break; v1 = ada_value_primitive_packed_val (NULL, valaddr, (i * bitsize) / HOST_CHAR_BIT, (i * bitsize) % HOST_CHAR_BIT, bitsize, elttype); if (memcmp (VALUE_CONTENTS (v0), VALUE_CONTENTS (v1), eltlen) != 0) break; } if (i - i0 > repeat_count_threshold) { val_print (elttype, VALUE_CONTENTS (v0), 0, 0, stream, format, 0, recurse + 1, pretty); annotate_elt_rep (i - i0); fprintf_filtered (stream, " <repeats %u times>", i - i0); annotate_elt_rep_end (); } else { int j; for (j = i0; j < i; j += 1) { if (j > i0) { if (prettyprint_arrays) { fprintf_filtered (stream, ",\n"); print_spaces_filtered (2 + 2 * recurse, stream); } else { fprintf_filtered (stream, ", "); } wrap_here (n_spaces (2 + 2 * recurse)); } val_print (elttype, VALUE_CONTENTS (v0), 0, 0, stream, format, 0, recurse + 1, pretty); annotate_elt (); } } things_printed += i - i0; } annotate_array_section_end (); if (i < len) { fprintf_filtered (stream, "..."); } value_free_to_mark (mark); }
void c_type_print_base (struct type *type, struct ui_file *stream, int show, int level) { int i; int len, real_len; enum { s_none, s_public, s_private, s_protected } section_type; int need_access_label = 0; int j, len2; QUIT; wrap_here (" "); if (type == NULL) { fputs_filtered (_("<type unknown>"), stream); return; } /* When SHOW is zero or less, and there is a valid type name, then always just print the type name directly from the type. */ /* If we have "typedef struct foo {. . .} bar;" do we want to print it as "struct foo" or as "bar"? Pick the latter, because C++ folk tend to expect things like "class5 *foo" rather than "struct class5 *foo". */ if (show <= 0 && TYPE_NAME (type) != NULL) { c_type_print_modifier (type, stream, 0, 1); fputs_filtered (TYPE_NAME (type), stream); return; } CHECK_TYPEDEF (type); switch (TYPE_CODE (type)) { case TYPE_CODE_TYPEDEF: /* If we get here, the typedef doesn't have a name, and we couldn't resolve TYPE_TARGET_TYPE. Not much we can do. */ gdb_assert (TYPE_NAME (type) == NULL); gdb_assert (TYPE_TARGET_TYPE (type) == NULL); fprintf_filtered (stream, _("<unnamed typedef>")); break; case TYPE_CODE_ARRAY: case TYPE_CODE_PTR: case TYPE_CODE_MEMBERPTR: case TYPE_CODE_REF: case TYPE_CODE_FUNC: case TYPE_CODE_METHOD: case TYPE_CODE_METHODPTR: c_type_print_base (TYPE_TARGET_TYPE (type), stream, show, level); break; case TYPE_CODE_STRUCT: case TYPE_CODE_UNION: c_type_print_modifier (type, stream, 0, 1); if (TYPE_CODE (type) == TYPE_CODE_UNION) fprintf_filtered (stream, "union "); else if (TYPE_DECLARED_CLASS (type)) fprintf_filtered (stream, "class "); else fprintf_filtered (stream, "struct "); /* Print the tag if it exists. The HP aCC compiler emits a spurious "{unnamed struct}"/"{unnamed union}"/"{unnamed enum}" tag for unnamed struct/union/enum's, which we don't want to print. */ if (TYPE_TAG_NAME (type) != NULL && strncmp (TYPE_TAG_NAME (type), "{unnamed", 8)) { fputs_filtered (TYPE_TAG_NAME (type), stream); if (show > 0) fputs_filtered (" ", stream); } wrap_here (" "); if (show < 0) { /* If we just printed a tag name, no need to print anything else. */ if (TYPE_TAG_NAME (type) == NULL) fprintf_filtered (stream, "{...}"); } else if (show > 0 || TYPE_TAG_NAME (type) == NULL) { struct type *basetype; int vptr_fieldno; cp_type_print_derivation_info (stream, type); fprintf_filtered (stream, "{\n"); if (TYPE_NFIELDS (type) == 0 && TYPE_NFN_FIELDS (type) == 0 && TYPE_TYPEDEF_FIELD_COUNT (type) == 0) { if (TYPE_STUB (type)) fprintfi_filtered (level + 4, stream, _("<incomplete type>\n")); else fprintfi_filtered (level + 4, stream, _("<no data fields>\n")); } /* Start off with no specific section type, so we can print one for the first field we find, and use that section type thereafter until we find another type. */ section_type = s_none; /* For a class, if all members are private, there's no need for a "private:" label; similarly, for a struct or union masquerading as a class, if all members are public, there's no need for a "public:" label. */ if (TYPE_DECLARED_CLASS (type)) { QUIT; len = TYPE_NFIELDS (type); for (i = TYPE_N_BASECLASSES (type); i < len; i++) if (!TYPE_FIELD_PRIVATE (type, i)) { need_access_label = 1; break; } QUIT; if (!need_access_label) { len2 = TYPE_NFN_FIELDS (type); for (j = 0; j < len2; j++) { len = TYPE_FN_FIELDLIST_LENGTH (type, j); for (i = 0; i < len; i++) if (!TYPE_FN_FIELD_PRIVATE (TYPE_FN_FIELDLIST1 (type, j), i)) { need_access_label = 1; break; } if (need_access_label) break; } } } else { QUIT; len = TYPE_NFIELDS (type); for (i = TYPE_N_BASECLASSES (type); i < len; i++) if (TYPE_FIELD_PRIVATE (type, i) || TYPE_FIELD_PROTECTED (type, i)) { need_access_label = 1; break; } QUIT; if (!need_access_label) { len2 = TYPE_NFN_FIELDS (type); for (j = 0; j < len2; j++) { QUIT; len = TYPE_FN_FIELDLIST_LENGTH (type, j); for (i = 0; i < len; i++) if (TYPE_FN_FIELD_PROTECTED (TYPE_FN_FIELDLIST1 (type, j), i) || TYPE_FN_FIELD_PRIVATE (TYPE_FN_FIELDLIST1 (type, j), i)) { need_access_label = 1; break; } if (need_access_label) break; } } } /* If there is a base class for this type, do not print the field that it occupies. */ len = TYPE_NFIELDS (type); vptr_fieldno = get_vptr_fieldno (type, &basetype); for (i = TYPE_N_BASECLASSES (type); i < len; i++) { QUIT; /* If we have a virtual table pointer, omit it. Even if virtual table pointers are not specifically marked in the debug info, they should be artificial. */ if ((i == vptr_fieldno && type == basetype) || TYPE_FIELD_ARTIFICIAL (type, i)) continue; if (need_access_label) { if (TYPE_FIELD_PROTECTED (type, i)) { if (section_type != s_protected) { section_type = s_protected; fprintfi_filtered (level + 2, stream, "protected:\n"); } } else if (TYPE_FIELD_PRIVATE (type, i)) { if (section_type != s_private) { section_type = s_private; fprintfi_filtered (level + 2, stream, "private:\n"); } } else { if (section_type != s_public) { section_type = s_public; fprintfi_filtered (level + 2, stream, "public:\n"); } } } print_spaces_filtered (level + 4, stream); if (field_is_static (&TYPE_FIELD (type, i))) fprintf_filtered (stream, "static "); c_print_type (TYPE_FIELD_TYPE (type, i), TYPE_FIELD_NAME (type, i), stream, show - 1, level + 4); if (!field_is_static (&TYPE_FIELD (type, i)) && TYPE_FIELD_PACKED (type, i)) { /* It is a bitfield. This code does not attempt to look at the bitpos and reconstruct filler, unnamed fields. This would lead to misleading results if the compiler does not put out fields for such things (I don't know what it does). */ fprintf_filtered (stream, " : %d", TYPE_FIELD_BITSIZE (type, i)); } fprintf_filtered (stream, ";\n"); } /* If there are both fields and methods, put a blank line between them. Make sure to count only method that we will display; artificial methods will be hidden. */ len = TYPE_NFN_FIELDS (type); real_len = 0; for (i = 0; i < len; i++) { struct fn_field *f = TYPE_FN_FIELDLIST1 (type, i); int len2 = TYPE_FN_FIELDLIST_LENGTH (type, i); int j; for (j = 0; j < len2; j++) if (!TYPE_FN_FIELD_ARTIFICIAL (f, j)) real_len++; } if (real_len > 0 && section_type != s_none) fprintf_filtered (stream, "\n"); /* C++: print out the methods. */ for (i = 0; i < len; i++) { struct fn_field *f = TYPE_FN_FIELDLIST1 (type, i); int j, len2 = TYPE_FN_FIELDLIST_LENGTH (type, i); const char *method_name = TYPE_FN_FIELDLIST_NAME (type, i); const char *name = type_name_no_tag (type); int is_constructor = name && strcmp (method_name, name) == 0; for (j = 0; j < len2; j++) { const char *mangled_name; char *demangled_name; struct cleanup *inner_cleanup; const char *physname = TYPE_FN_FIELD_PHYSNAME (f, j); int is_full_physname_constructor = is_constructor_name (physname) || is_destructor_name (physname) || method_name[0] == '~'; /* Do not print out artificial methods. */ if (TYPE_FN_FIELD_ARTIFICIAL (f, j)) continue; inner_cleanup = make_cleanup (null_cleanup, NULL); QUIT; if (TYPE_FN_FIELD_PROTECTED (f, j)) { if (section_type != s_protected) { section_type = s_protected; fprintfi_filtered (level + 2, stream, "protected:\n"); } } else if (TYPE_FN_FIELD_PRIVATE (f, j)) { if (section_type != s_private) { section_type = s_private; fprintfi_filtered (level + 2, stream, "private:\n"); } } else { if (section_type != s_public) { section_type = s_public; fprintfi_filtered (level + 2, stream, "public:\n"); } } print_spaces_filtered (level + 4, stream); if (TYPE_FN_FIELD_VIRTUAL_P (f, j)) fprintf_filtered (stream, "virtual "); else if (TYPE_FN_FIELD_STATIC_P (f, j)) fprintf_filtered (stream, "static "); if (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f, j)) == 0) { /* Keep GDB from crashing here. */ fprintf_filtered (stream, _("<undefined type> %s;\n"), TYPE_FN_FIELD_PHYSNAME (f, j)); break; } else if (!is_constructor /* Constructors don't have declared types. */ && !is_full_physname_constructor /* " " */ && !is_type_conversion_operator (type, i, j)) { type_print (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f, j)), "", stream, -1); fputs_filtered (" ", stream); } if (TYPE_FN_FIELD_STUB (f, j)) { char *tem; /* Build something we can demangle. */ tem = gdb_mangle_name (type, i, j); make_cleanup (xfree, tem); mangled_name = tem; } else mangled_name = TYPE_FN_FIELD_PHYSNAME (f, j); demangled_name = cplus_demangle (mangled_name, DMGL_ANSI | DMGL_PARAMS); if (demangled_name == NULL) { /* In some cases (for instance with the HP demangling), if a function has more than 10 arguments, the demangling will fail. Let's try to reconstruct the function signature from the symbol information. */ if (!TYPE_FN_FIELD_STUB (f, j)) { int staticp = TYPE_FN_FIELD_STATIC_P (f, j); struct type *mtype = TYPE_FN_FIELD_TYPE (f, j); cp_type_print_method_args (mtype, "", method_name, staticp, stream); } else fprintf_filtered (stream, _("<badly mangled name '%s'>"), mangled_name); } else { char *p; char *demangled_no_class = remove_qualifiers (demangled_name); /* Get rid of the `static' appended by the demangler. */ p = strstr (demangled_no_class, " static"); if (p != NULL) { int length = p - demangled_no_class; char *demangled_no_static; demangled_no_static = (char *) xmalloc (length + 1); strncpy (demangled_no_static, demangled_no_class, length); *(demangled_no_static + length) = '\0'; fputs_filtered (demangled_no_static, stream); xfree (demangled_no_static); } else fputs_filtered (demangled_no_class, stream); xfree (demangled_name); } do_cleanups (inner_cleanup); fprintf_filtered (stream, ";\n"); } } /* Print typedefs defined in this class. */ if (TYPE_TYPEDEF_FIELD_COUNT (type) != 0) { if (TYPE_NFIELDS (type) != 0 || TYPE_NFN_FIELDS (type) != 0) fprintf_filtered (stream, "\n"); for (i = 0; i < TYPE_TYPEDEF_FIELD_COUNT (type); i++) { struct type *target = TYPE_TYPEDEF_FIELD_TYPE (type, i); /* Dereference the typedef declaration itself. */ gdb_assert (TYPE_CODE (target) == TYPE_CODE_TYPEDEF); target = TYPE_TARGET_TYPE (target); print_spaces_filtered (level + 4, stream); fprintf_filtered (stream, "typedef "); c_print_type (target, TYPE_TYPEDEF_FIELD_NAME (type, i), stream, show - 1, level + 4); fprintf_filtered (stream, ";\n"); } } fprintfi_filtered (level, stream, "}"); if (TYPE_LOCALTYPE_PTR (type) && show >= 0) fprintfi_filtered (level, stream, _(" (Local at %s:%d)\n"), TYPE_LOCALTYPE_FILE (type), TYPE_LOCALTYPE_LINE (type)); } break; case TYPE_CODE_ENUM: c_type_print_modifier (type, stream, 0, 1); fprintf_filtered (stream, "enum "); /* Print the tag name if it exists. The aCC compiler emits a spurious "{unnamed struct}"/"{unnamed union}"/"{unnamed enum}" tag for unnamed struct/union/enum's, which we don't want to print. */ if (TYPE_TAG_NAME (type) != NULL && strncmp (TYPE_TAG_NAME (type), "{unnamed", 8)) { fputs_filtered (TYPE_TAG_NAME (type), stream); if (show > 0) fputs_filtered (" ", stream); } wrap_here (" "); if (show < 0) { /* If we just printed a tag name, no need to print anything else. */ if (TYPE_TAG_NAME (type) == NULL) fprintf_filtered (stream, "{...}"); } else if (show > 0 || TYPE_TAG_NAME (type) == NULL) { LONGEST lastval = 0; fprintf_filtered (stream, "{"); len = TYPE_NFIELDS (type); for (i = 0; i < len; i++) { QUIT; if (i) fprintf_filtered (stream, ", "); wrap_here (" "); fputs_filtered (TYPE_FIELD_NAME (type, i), stream); if (lastval != TYPE_FIELD_ENUMVAL (type, i)) { fprintf_filtered (stream, " = %s", plongest (TYPE_FIELD_ENUMVAL (type, i))); lastval = TYPE_FIELD_ENUMVAL (type, i); } lastval++; } fprintf_filtered (stream, "}"); } break; case TYPE_CODE_VOID: fprintf_filtered (stream, "void"); break; case TYPE_CODE_UNDEF: fprintf_filtered (stream, _("struct <unknown>")); break; case TYPE_CODE_ERROR: fprintf_filtered (stream, "%s", TYPE_ERROR_NAME (type)); break; case TYPE_CODE_RANGE: /* This should not occur. */ fprintf_filtered (stream, _("<range type>")); break; case TYPE_CODE_NAMESPACE: fputs_filtered ("namespace ", stream); fputs_filtered (TYPE_TAG_NAME (type), stream); break; default: /* Handle types not explicitly handled by the other cases, such as fundamental types. For these, just print whatever the type name is, as recorded in the type itself. If there is no type name, then complain. */ if (TYPE_NAME (type) != NULL) { c_type_print_modifier (type, stream, 0, 1); fputs_filtered (TYPE_NAME (type), stream); } else { /* At least for dump_symtab, it is important that this not be an error (). */ fprintf_filtered (stream, _("<invalid type code %d>"), TYPE_CODE (type)); } break; } }
static PyObject * convert_field (struct type *type, int field) { gdbpy_ref<> result (field_new ()); if (result == NULL) return NULL; gdbpy_ref<> arg (type_to_type_object (type)); if (arg == NULL) return NULL; if (PyObject_SetAttrString (result.get (), "parent_type", arg.get ()) < 0) return NULL; if (!field_is_static (&TYPE_FIELD (type, field))) { const char *attrstring; if (TYPE_CODE (type) == TYPE_CODE_ENUM) { arg.reset (gdb_py_long_from_longest (TYPE_FIELD_ENUMVAL (type, field))); attrstring = "enumval"; } else { arg.reset (gdb_py_long_from_longest (TYPE_FIELD_BITPOS (type, field))); attrstring = "bitpos"; } if (arg == NULL) return NULL; /* At least python-2.4 had the second parameter non-const. */ if (PyObject_SetAttrString (result.get (), (char *) attrstring, arg.get ()) < 0) return NULL; } arg.reset (NULL); if (TYPE_FIELD_NAME (type, field)) { const char *field_name = TYPE_FIELD_NAME (type, field); if (field_name[0] != '\0') { arg.reset (PyString_FromString (TYPE_FIELD_NAME (type, field))); if (arg == NULL) return NULL; } } if (arg == NULL) { arg.reset (Py_None); Py_INCREF (arg.get ()); } if (PyObject_SetAttrString (result.get (), "name", arg.get ()) < 0) return NULL; arg.reset (TYPE_FIELD_ARTIFICIAL (type, field) ? Py_True : Py_False); Py_INCREF (arg.get ()); if (PyObject_SetAttrString (result.get (), "artificial", arg.get ()) < 0) return NULL; if (TYPE_CODE (type) == TYPE_CODE_STRUCT) arg.reset (field < TYPE_N_BASECLASSES (type) ? Py_True : Py_False); else arg.reset (Py_False); Py_INCREF (arg.get ()); if (PyObject_SetAttrString (result.get (), "is_base_class", arg.get ()) < 0) return NULL; arg.reset (PyLong_FromLong (TYPE_FIELD_BITSIZE (type, field))); if (arg == NULL) return NULL; if (PyObject_SetAttrString (result.get (), "bitsize", arg.get ()) < 0) return NULL; /* A field can have a NULL type in some situations. */ if (TYPE_FIELD_TYPE (type, field) == NULL) { arg.reset (Py_None); Py_INCREF (arg.get ()); } else arg.reset (type_to_type_object (TYPE_FIELD_TYPE (type, field))); if (arg == NULL) return NULL; if (PyObject_SetAttrString (result.get (), "type", arg.get ()) < 0) return NULL; return result.release (); }
static void compile_cplus_convert_struct_or_union_members (compile_cplus_instance *instance, struct type *type, gcc_type comp_type) { for (int i = TYPE_N_BASECLASSES (type); i < TYPE_NFIELDS (type); ++i) { const char *field_name = TYPE_FIELD_NAME (type, i); if (TYPE_FIELD_IGNORE (type, i) || TYPE_FIELD_ARTIFICIAL (type, i)) continue; /* GDB records unnamed/anonymous fields with empty string names. */ if (*field_name == '\0') field_name = nullptr; gcc_type field_type = instance->convert_type (TYPE_FIELD_TYPE (type, i)); if (field_is_static (&TYPE_FIELD (type, i))) { CORE_ADDR physaddr; switch (TYPE_FIELD_LOC_KIND (type, i)) { case FIELD_LOC_KIND_PHYSADDR: { physaddr = TYPE_FIELD_STATIC_PHYSADDR (type, i); instance->plugin ().build_decl ("field physaddr", field_name, (GCC_CP_SYMBOL_VARIABLE | get_field_access_flag (type, i)), field_type, nullptr, physaddr, nullptr, 0); } break; case FIELD_LOC_KIND_PHYSNAME: { const char *physname = TYPE_FIELD_STATIC_PHYSNAME (type, i); struct block_symbol sym = lookup_symbol (physname, instance->block (), VAR_DOMAIN, nullptr); if (sym.symbol == nullptr) { /* We didn't actually find the symbol. There's little we can do but ignore this member. */ continue; } const char *filename = symbol_symtab (sym.symbol)->filename; unsigned int line = SYMBOL_LINE (sym.symbol); physaddr = SYMBOL_VALUE_ADDRESS (sym.symbol); instance->plugin ().build_decl ("field physname", field_name, (GCC_CP_SYMBOL_VARIABLE| get_field_access_flag (type, i)), field_type, nullptr, physaddr, filename, line); } break; default: gdb_assert_not_reached ("unexpected static field location kind"); } } else { unsigned long bitsize = TYPE_FIELD_BITSIZE (type, i); enum gcc_cp_symbol_kind field_flags = GCC_CP_SYMBOL_FIELD | get_field_access_flag (type, i); if (bitsize == 0) bitsize = 8 * TYPE_LENGTH (TYPE_FIELD_TYPE (type, i)); instance->plugin ().build_field (field_name, field_type, field_flags, bitsize, TYPE_FIELD_BITPOS (type, i)); } } }