static void ada_val_print_ref (struct type *type, const gdb_byte *valaddr, int offset, int offset_aligned, CORE_ADDR address, struct ui_file *stream, int recurse, const struct value *original_value, const struct value_print_options *options, const struct language_defn *language) { /* For references, the debugger is expected to print the value as an address if DEREF_REF is null. But printing an address in place of the object value would be confusing to an Ada programmer. So, for Ada values, we print the actual dereferenced value regardless. */ struct type *elttype = check_typedef (TYPE_TARGET_TYPE (type)); struct value *deref_val; CORE_ADDR deref_val_int; if (TYPE_CODE (elttype) == TYPE_CODE_UNDEF) { fputs_filtered ("<ref to undefined type>", stream); return; } deref_val = coerce_ref_if_computed (original_value); if (deref_val) { if (ada_is_tagged_type (value_type (deref_val), 1)) deref_val = ada_tag_value_at_base_address (deref_val); common_val_print (deref_val, stream, recurse + 1, options, language); return; } deref_val_int = unpack_pointer (type, valaddr + offset_aligned); if (deref_val_int == 0) { fputs_filtered ("(null)", stream); return; } deref_val = ada_value_ind (value_from_pointer (lookup_pointer_type (elttype), deref_val_int)); if (ada_is_tagged_type (value_type (deref_val), 1)) deref_val = ada_tag_value_at_base_address (deref_val); /* Make sure that the object does not have an unreasonable size before trying to print it. This can happen for instance with references to dynamic objects whose contents is uninitialized (Eg: an array whose bounds are not set yet). */ ada_ensure_varsize_limit (value_type (deref_val)); val_print (value_type (deref_val), value_contents_for_printing (deref_val), value_embedded_offset (deref_val), value_address (deref_val), stream, recurse + 1, deref_val, options, language); }
static int ada_varobj_get_struct_number_of_children (struct value *parent_value, struct type *parent_type) { int n_children = 0; int i; gdb_assert (TYPE_CODE (parent_type) == TYPE_CODE_STRUCT || TYPE_CODE (parent_type) == TYPE_CODE_UNION); for (i = 0; i < TYPE_NFIELDS (parent_type); i++) { if (ada_is_ignored_field (parent_type, i)) continue; if (ada_is_wrapper_field (parent_type, i)) { struct value *elt_value; struct type *elt_type; ada_varobj_struct_elt (parent_value, parent_type, i, &elt_value, &elt_type); if (ada_is_tagged_type (elt_type, 0)) { /* We must not use ada_varobj_get_number_of_children to determine is element's number of children, because this function first calls ada_varobj_decode_var, which "fixes" the element. For tagged types, this includes reading the object's tag to determine its real type, which happens to be the parent_type, and leads to an infinite loop (because the element gets fixed back into the parent). */ n_children += ada_varobj_get_struct_number_of_children (elt_value, elt_type); } else n_children += ada_varobj_get_number_of_children (elt_value, elt_type); } else if (ada_is_variant_part (parent_type, i)) { /* In normal situations, the variant part of the record should have been "fixed". Or, in other words, it should have been replaced by the branch of the variant part that is relevant for our value. But there are still situations where this can happen, however (Eg. when our parent is a NULL pointer). We do not support showing this part of the record for now, so just pretend this field does not exist. */ } else n_children++; } return n_children; }
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 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_adjust_for_child_access (struct value **value, struct type **type) { /* Pointers to struct/union types are special: Instead of having one child (the struct), their children are the components of the struct/union type. We handle this situation by dereferencing the (value, type) couple. */ if (TYPE_CODE (*type) == TYPE_CODE_PTR && (TYPE_CODE (TYPE_TARGET_TYPE (*type)) == TYPE_CODE_STRUCT || TYPE_CODE (TYPE_TARGET_TYPE (*type)) == TYPE_CODE_UNION) && !ada_is_array_descriptor_type (TYPE_TARGET_TYPE (*type)) && !ada_is_constrained_packed_array_type (TYPE_TARGET_TYPE (*type))) ada_varobj_ind (*value, *type, value, type); /* If this is a tagged type, we need to transform it a bit in order to be able to fetch its full view. As always with tagged types, we can only do that if we have a value. */ if (*value != NULL && ada_is_tagged_type (*type, 1)) { *value = ada_tag_value_at_base_address (*value); *type = value_type (*value); } }
static void ada_varobj_describe_struct_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) { int fieldno; int childno = 0; gdb_assert (TYPE_CODE (parent_type) == TYPE_CODE_STRUCT); for (fieldno = 0; fieldno < TYPE_NFIELDS (parent_type); fieldno++) { if (ada_is_ignored_field (parent_type, fieldno)) continue; if (ada_is_wrapper_field (parent_type, fieldno)) { struct value *elt_value; struct type *elt_type; int elt_n_children; ada_varobj_struct_elt (parent_value, parent_type, fieldno, &elt_value, &elt_type); if (ada_is_tagged_type (elt_type, 0)) { /* Same as in ada_varobj_get_struct_number_of_children: For tagged types, we must be careful to not call ada_varobj_get_number_of_children, to prevent our element from being fixed back into the parent. */ elt_n_children = ada_varobj_get_struct_number_of_children (elt_value, elt_type); } else elt_n_children = ada_varobj_get_number_of_children (elt_value, elt_type); /* Is the child we're looking for one of the children of this wrapper field? */ if (child_index - childno < elt_n_children) { if (ada_is_tagged_type (elt_type, 0)) { /* Same as in ada_varobj_get_struct_number_of_children: For tagged types, we must be careful to not call ada_varobj_describe_child, to prevent our element from being fixed back into the parent. */ ada_varobj_describe_struct_child (elt_value, elt_type, parent_name, parent_path_expr, child_index - childno, child_name, child_value, child_type, child_path_expr); } else ada_varobj_describe_child (elt_value, elt_type, parent_name, parent_path_expr, child_index - childno, child_name, child_value, child_type, child_path_expr); return; } /* The child we're looking for is beyond this wrapper field, so skip all its children. */ childno += elt_n_children; continue; } else if (ada_is_variant_part (parent_type, fieldno)) { /* In normal situations, the variant part of the record should have been "fixed". Or, in other words, it should have been replaced by the branch of the variant part that is relevant for our value. But there are still situations where this can happen, however (Eg. when our parent is a NULL pointer). We do not support showing this part of the record for now, so just pretend this field does not exist. */ continue; } if (childno == child_index) { if (child_name) { /* The name of the child is none other than the field's name, except that we need to strip suffixes from it. For instance, fields with alignment constraints will have an __XVA suffix added to them. */ const char *field_name = TYPE_FIELD_NAME (parent_type, fieldno); int child_name_len = ada_name_prefix_len (field_name); *child_name = xstrprintf ("%.*s", child_name_len, field_name); } if (child_value && parent_value) ada_varobj_struct_elt (parent_value, parent_type, fieldno, child_value, NULL); if (child_type) ada_varobj_struct_elt (parent_value, parent_type, fieldno, NULL, child_type); if (child_path_expr) { /* The name of the child is none other than the field's name, except that we need to strip suffixes from it. For instance, fields with alignment constraints will have an __XVA suffix added to them. */ const char *field_name = TYPE_FIELD_NAME (parent_type, fieldno); int child_name_len = ada_name_prefix_len (field_name); *child_path_expr = xstrprintf ("(%s).%.*s", parent_path_expr, child_name_len, field_name); } return; } childno++; } /* Something went wrong. Either we miscounted the number of children, or CHILD_INDEX was too high. But we should never reach here. We don't have enough information to recover nicely, so just raise an assertion failure. */ gdb_assert_not_reached ("unexpected code path"); }