static void print_record_type (struct type *type0, struct ui_file *stream, int show, int level, const struct type_print_options *flags) { struct type *parent_type; struct type *type; type = ada_find_parallel_type (type0, "___XVE"); if (type == NULL) type = type0; parent_type = ada_parent_type (type); if (ada_type_name (parent_type) != NULL) { const char *parent_name = decoded_type_name (parent_type); /* If we fail to decode the parent type name, then use the parent type name as is. Not pretty, but should never happen except when the debugging info is incomplete or incorrect. This prevents a crash trying to print a NULL pointer. */ if (parent_name == NULL) parent_name = ada_type_name (parent_type); fprintf_filtered (stream, "new %s with record", parent_name); } else if (parent_type == NULL && ada_is_tagged_type (type, 0)) fprintf_filtered (stream, "tagged record"); else fprintf_filtered (stream, "record"); if (show < 0) fprintf_filtered (stream, " ... end record"); else { int flds; flds = 0; if (parent_type != NULL && ada_type_name (parent_type) == NULL) flds += print_record_field_types (parent_type, parent_type, stream, show, level, flags); flds += print_record_field_types (type, type, stream, show, level, flags); if (flds > 0) fprintf_filtered (stream, "\n%*send record", level, ""); else if (flds < 0) fprintf_filtered (stream, _(" <incomplete type> end record")); else fprintf_filtered (stream, " null; end record"); } }
static char * decoded_type_name (struct type *type) { if (ada_type_name (type) == NULL) return NULL; else { const char *raw_name = ada_type_name (type); char *s, *q; if (name_buffer == NULL || name_buffer_len <= strlen (raw_name)) { name_buffer_len = 16 + 2 * strlen (raw_name); name_buffer = xrealloc (name_buffer, name_buffer_len); } strcpy (name_buffer, raw_name); s = (char *) strstr (name_buffer, "___"); if (s != NULL) *s = '\0'; s = name_buffer + strlen (name_buffer) - 1; while (s > name_buffer && (s[0] != '_' || s[-1] != '_')) s -= 1; if (s == name_buffer) return name_buffer; if (!islower (s[1])) return NULL; for (s = q = name_buffer; *s != '\0'; q += 1) { if (s[0] == '_' && s[1] == '_') { *q = '.'; s += 2; } else { *q = *s; s += 1; } } *q = '\0'; return name_buffer; } }
static char * decoded_type_name(struct type *the_type) { if (ada_type_name(the_type) == NULL) return NULL; else { char *raw_name = ada_type_name(the_type); char *s, *q; if ((name_buffer == NULL) || (name_buffer_len <= strlen(raw_name))) { name_buffer_len = (16UL + 2UL * strlen(raw_name)); name_buffer = (char *)xrealloc(name_buffer, name_buffer_len); } strcpy(name_buffer, raw_name); s = (char *)strstr(name_buffer, "___"); if (s != NULL) *s = '\0'; s = (name_buffer + strlen(name_buffer) - 1); while ((s > name_buffer) && ((s[0] != '_') || (s[-1] != '_'))) s -= 1; if (s == name_buffer) return name_buffer; if (!islower(s[1])) return NULL; for (s = q = name_buffer; *s != '\0'; q += 1) { if ((s[0] == '_') && (s[1] == '_')) { *q = '.'; s += 2; } else { *q = *s; s += 1; } } *q = '\0'; return name_buffer; } }
static void print_record_type (struct type *type0, struct ui_file *stream, int show, int level) { struct type *parent_type; struct type *type; type = ada_find_parallel_type (type0, "___XVE"); if (type == NULL) type = type0; parent_type = ada_parent_type (type); if (ada_type_name (parent_type) != NULL) fprintf_filtered (stream, "new %s with record", decoded_type_name (parent_type)); else if (parent_type == NULL && ada_is_tagged_type (type, 0)) fprintf_filtered (stream, "tagged record"); else fprintf_filtered (stream, "record"); if (show < 0) fprintf_filtered (stream, " ... end record"); else { int flds; flds = 0; if (parent_type != NULL && ada_type_name (parent_type) == NULL) flds += print_record_field_types (parent_type, parent_type, stream, show, level); flds += print_record_field_types (type, type, stream, show, level); if (flds > 0) fprintf_filtered (stream, "\n%*send record", level, ""); else if (flds < 0) fprintf_filtered (stream, _(" <incomplete type> end record")); else fprintf_filtered (stream, " null; end record"); } }
static void ada_varobj_describe_simple_array_child (struct value *parent_value, struct type *parent_type, const char *parent_name, const char *parent_path_expr, int child_index, char **child_name, struct value **child_value, struct type **child_type, char **child_path_expr) { struct type *index_type; int real_index; gdb_assert (TYPE_CODE (parent_type) == TYPE_CODE_ARRAY); index_type = TYPE_INDEX_TYPE (parent_type); real_index = child_index + ada_discrete_type_low_bound (index_type); if (child_name) *child_name = ada_varobj_scalar_image (index_type, real_index); if (child_value && parent_value) ada_varobj_simple_array_elt (parent_value, parent_type, real_index, child_value, NULL); if (child_type) ada_varobj_simple_array_elt (parent_value, parent_type, real_index, NULL, child_type); if (child_path_expr) { char *index_img = ada_varobj_scalar_image (index_type, real_index); struct cleanup *cleanups = make_cleanup (xfree, index_img); /* Enumeration litterals by themselves are potentially ambiguous. For instance, consider the following package spec: package Pck is type Color is (Red, Green, Blue, White); type Blood_Cells is (White, Red); end Pck; In this case, the litteral "red" for instance, or even the fully-qualified litteral "pck.red" cannot be resolved by itself. Type qualification is needed to determine which enumeration litterals should be used. The following variable will be used to contain the name of the array index type when such type qualification is needed. */ const char *index_type_name = NULL; /* If the index type is a range type, find the base type. */ while (TYPE_CODE (index_type) == TYPE_CODE_RANGE) index_type = TYPE_TARGET_TYPE (index_type); if (TYPE_CODE (index_type) == TYPE_CODE_ENUM || TYPE_CODE (index_type) == TYPE_CODE_BOOL) { index_type_name = ada_type_name (index_type); if (index_type_name) index_type_name = ada_decode (index_type_name); } if (index_type_name != NULL) *child_path_expr = xstrprintf ("(%s)(%.*s'(%s))", parent_path_expr, ada_name_prefix_len (index_type_name), index_type_name, index_img); else *child_path_expr = xstrprintf ("(%s)(%s)", parent_path_expr, index_img); do_cleanups (cleanups); } }
void ada_print_type (struct type *type0, const char *varstring, struct ui_file *stream, int show, int level, const struct type_print_options *flags) { struct type *type = ada_check_typedef (ada_get_base_type (type0)); char *type_name = decoded_type_name (type0); int is_var_decl = (varstring != NULL && varstring[0] != '\0'); if (type == NULL) { if (is_var_decl) fprintf_filtered (stream, "%.*s: ", ada_name_prefix_len (varstring), varstring); fprintf_filtered (stream, "<null type?>"); return; } if (show > 0) type = ada_check_typedef (type); if (is_var_decl && TYPE_CODE (type) != TYPE_CODE_FUNC) fprintf_filtered (stream, "%.*s: ", ada_name_prefix_len (varstring), varstring); if (type_name != NULL && show <= 0 && !ada_is_aligner_type (type)) { fprintf_filtered (stream, "%.*s", ada_name_prefix_len (type_name), type_name); return; } if (ada_is_aligner_type (type)) ada_print_type (ada_aligned_type (type), "", stream, show, level, flags); else if (ada_is_constrained_packed_array_type (type) && TYPE_CODE (type) != TYPE_CODE_PTR) print_array_type (type, stream, show, level, flags); else switch (TYPE_CODE (type)) { default: fprintf_filtered (stream, "<"); c_print_type (type, "", stream, show, level, flags); fprintf_filtered (stream, ">"); break; case TYPE_CODE_PTR: case TYPE_CODE_TYPEDEF: fprintf_filtered (stream, "access "); ada_print_type (TYPE_TARGET_TYPE (type), "", stream, show, level, flags); break; case TYPE_CODE_REF: fprintf_filtered (stream, "<ref> "); ada_print_type (TYPE_TARGET_TYPE (type), "", stream, show, level, flags); break; case TYPE_CODE_ARRAY: print_array_type (type, stream, show, level, flags); break; case TYPE_CODE_BOOL: fprintf_filtered (stream, "(false, true)"); break; case TYPE_CODE_INT: if (ada_is_fixed_point_type (type)) print_fixed_point_type (type, stream); else { const char *name = ada_type_name (type); if (!ada_is_range_type_name (name)) fprintf_filtered (stream, _("<%d-byte integer>"), TYPE_LENGTH (type)); else { fprintf_filtered (stream, "range "); print_range_type (type, stream); } } break; case TYPE_CODE_RANGE: if (ada_is_fixed_point_type (type)) print_fixed_point_type (type, stream); else if (ada_is_modular_type (type)) fprintf_filtered (stream, "mod %s", int_string (ada_modulus (type), 10, 0, 0, 1)); else { fprintf_filtered (stream, "range "); print_range (type, stream); } break; case TYPE_CODE_FLT: fprintf_filtered (stream, _("<%d-byte float>"), TYPE_LENGTH (type)); break; case TYPE_CODE_ENUM: if (show < 0) fprintf_filtered (stream, "(...)"); else print_enum_type (type, stream); break; case TYPE_CODE_STRUCT: if (ada_is_array_descriptor_type (type)) print_array_type (type, stream, show, level, flags); else if (ada_is_bogus_array_descriptor (type)) fprintf_filtered (stream, _("array (?) of ? (<mal-formed descriptor>)")); else print_record_type (type, stream, show, level, flags); break; case TYPE_CODE_UNION: print_unchecked_union_type (type, stream, show, level, flags); break; case TYPE_CODE_FUNC: print_func_type (type, stream, varstring, flags); break; } }