aboutsummaryrefslogtreecommitdiff
path: root/gdb/ada-lang.c
diff options
context:
space:
mode:
authorJoel Brobecker <brobecker@gnat.com>2010-01-12 05:49:00 +0000
committerJoel Brobecker <brobecker@gnat.com>2010-01-12 05:49:00 +0000
commitb4ba55a1812c4bde23d52111e54d2b72a1ec4af1 (patch)
treeb84c1cfcfebf30685854b3e01f7553ce70ac6bfc /gdb/ada-lang.c
parentcc761f759cdb2966648d33c92f85c6e6e3e5da82 (diff)
downloadgdb-b4ba55a1812c4bde23d52111e54d2b72a1ec4af1.zip
gdb-b4ba55a1812c4bde23d52111e54d2b72a1ec4af1.tar.gz
gdb-b4ba55a1812c4bde23d52111e54d2b72a1ec4af1.tar.bz2
gdb/ChangeLog:
Add support for DW_AT_GNAT_descriptive_type. * gdbtypes.h (enum type_specific_kind): New enum. (struct main_type) [type_specific_field]: New component. [type_specific]: Add new component "gnat_stuff". (struct gnat_aux_type): New type. (INIT_CPLUS_SPECIFIC): Also set TYPE_SPECIFIC_FIELD (type). (HAVE_CPLUS_STRUCT): Also check TYPE_SPECIFIC_FIELD (type). (gnat_aux_default, allocate_gnat_aux_type): Add declaration. (INIT_GNAT_SPECIFIC, ALLOCATE_GNAT_AUX_TYPE, HAVE_GNAT_AUX_INFO) (TYPE_SPECIFIC_FIELD): New macros. (TYPE_CPLUS_SPECIFIC): Return cplus_struct_default if the given type does not hold any cplus-specific data. (TYPE_RAW_CPLUS_SPECIFIC): New macro. (TYPE_GNAT_SPECIFIC, TYPE_DESCRIPTIVE_TYPE): New macros. (TYPE_IS_OPAQUE): Use HAVE_CPLUS_STRUCT to check if type has cplus-specific data. * gdbtypes.c (allocate_cplus_struct_type): Minor stylistic rewrite. Set new component TYPE_SPECIFIC_FIELD (type). (gnat_aux_default): New constant. (allocate_gnat_aux_type): New function. (init_type): Add initialization the type-specific stuff for TYPE_CODE_FLT and TYPE_CODE_FUNC types. (print_gnat_stuff): New function. (recursive_dump_type): Use HAVE_CPLUS_STRUCT to check for cplus- specific data. Adjust code that prints the contents of the type-specific union using the TYPE_SPECIFIC_FIELD value. * dwarf2read.c (dwarf2_attach_fields_to_type): Do not allocate the type cplus stuff for Ada types. (dwarf2_add_member_fn, dwarf2_attach_fn_fields_to_type): Error out if these routines are called with an Ada type. (read_structure_type, read_array_type, read_subrange_type): Add call to set_descriptive_type. (set_die_type): Initialize the gnat-specific data if necessary. (need_gnat_info, die_descriptive_type, set_descriptive_type): New functions. * ada-lang.c (decode_constrained_packed_array_type): Use decode_constrained_packed_array_type instead of doing a standard lookup to locate a parallel type. (find_parallel_type_by_descriptive_type): New function. (ada_find_parallel_type_with_name): New function. (ada_find_parallel_type): Reimplement using ada_find_parallel_type_with_name. * ada-valprint.c (print_field_values): Use HAVE_CPLUS_STRUCT to check if type has a cplus stuff. * linespec.c (total_number_of_methods): Likewise. * mdebugread.c (new_type): Likewise. gdb/testsuite/ChangeLog: * gdb.base/maint.exp: Adjust the expected output for the "maint print type" test. Use gdb_test_multiple instead of gdb_sent/gdb_expect.
Diffstat (limited to 'gdb/ada-lang.c')
-rw-r--r--gdb/ada-lang.c82
1 files changed, 72 insertions, 10 deletions
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index b101d58..317c8d3 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -157,6 +157,9 @@ static struct type *ada_lookup_struct_elt_type (struct type *, char *,
static struct value *evaluate_subexp_type (struct expression *, int *);
+static struct type *ada_find_parallel_type_with_name (struct type *,
+ const char *);
+
static int is_dynamic_field (struct type *, int);
static struct type *to_fixed_variant_branch_type (struct type *,
@@ -1874,13 +1877,13 @@ decode_constrained_packed_array_type (struct type *type)
memcpy (name, raw_name, tail - raw_name);
name[tail - raw_name] = '\000';
- sym = standard_lookup (name, get_selected_block (0), VAR_DOMAIN);
- if (sym == NULL || SYMBOL_TYPE (sym) == NULL)
+ shadow_type = ada_find_parallel_type_with_name (type, name);
+
+ if (shadow_type == NULL)
{
lim_warning (_("could not find bounds information on packed array"));
return NULL;
}
- shadow_type = SYMBOL_TYPE (sym);
CHECK_TYPEDEF (shadow_type);
if (TYPE_CODE (shadow_type) != TYPE_CODE_ARRAY)
@@ -6666,31 +6669,90 @@ ada_type_name (struct type *type)
return TYPE_TAG_NAME (type);
}
-/* Find a parallel type to TYPE whose name is formed by appending
+/* Search the list of "descriptive" types associated to TYPE for a type
+ whose name is NAME. */
+
+static struct type *
+find_parallel_type_by_descriptive_type (struct type *type, const char *name)
+{
+ struct type *result;
+
+ /* If there no descriptive-type info, then there is no parallel type
+ to be found. */
+ if (!HAVE_GNAT_AUX_INFO (type))
+ return NULL;
+
+ result = TYPE_DESCRIPTIVE_TYPE (type);
+ while (result != NULL)
+ {
+ char *result_name = ada_type_name (result);
+
+ if (result_name == NULL)
+ {
+ warning (_("unexpected null name on descriptive type"));
+ return NULL;
+ }
+
+ /* If the names match, stop. */
+ if (strcmp (result_name, name) == 0)
+ break;
+
+ /* Otherwise, look at the next item on the list, if any. */
+ if (HAVE_GNAT_AUX_INFO (result))
+ result = TYPE_DESCRIPTIVE_TYPE (result);
+ else
+ result = NULL;
+ }
+
+ /* If we didn't find a match, see whether this is a packed array. With
+ older compilers, the descriptive type information is either absent or
+ irrelevant when it comes to packed arrays so the above lookup fails.
+ Fall back to using a parallel lookup by name in this case. */
+ if (result == NULL && ada_is_packed_array_type (type))
+ return ada_find_any_type (name);
+
+ return result;
+}
+
+/* Find a parallel type to TYPE with the specified NAME, using the
+ descriptive type taken from the debugging information, if available,
+ and otherwise using the (slower) name-based method. */
+
+static struct type *
+ada_find_parallel_type_with_name (struct type *type, const char *name)
+{
+ struct type *result = NULL;
+
+ if (HAVE_GNAT_AUX_INFO (type))
+ result = find_parallel_type_by_descriptive_type (type, name);
+ else
+ result = ada_find_any_type (name);
+
+ return result;
+}
+
+/* Same as above, but specify the name of the parallel type by appending
SUFFIX to the name of TYPE. */
struct type *
ada_find_parallel_type (struct type *type, const char *suffix)
{
- static char *name;
- static size_t name_len = 0;
+ char *name, *typename = ada_type_name (type);
int len;
- char *typename = ada_type_name (type);
if (typename == NULL)
return NULL;
len = strlen (typename);
- GROW_VECT (name, name_len, len + strlen (suffix) + 1);
+ name = (char *) alloca (len + strlen (suffix) + 1);
strcpy (name, typename);
strcpy (name + len, suffix);
- return ada_find_any_type (name);
+ return ada_find_parallel_type_with_name (type, name);
}
-
/* If TYPE is a variable-size record type, return the corresponding template
type describing its fields. Otherwise, return NULL. */