diff options
author | Joel Brobecker <brobecker@adacore.com> | 2015-01-05 14:32:36 +0400 |
---|---|---|
committer | Joel Brobecker <brobecker@adacore.com> | 2015-01-29 12:08:47 +0400 |
commit | df25ebbd091aebc132f97ffd6ce9cf7964a57981 (patch) | |
tree | 85422e183eef04a63ebf40305230ea281b16c304 /gdb/dwarf2loc.h | |
parent | 4a0ca9ec1ee3bc18da72ce42cdd7c2959e58aa76 (diff) | |
download | gdb-df25ebbd091aebc132f97ffd6ce9cf7964a57981.zip gdb-df25ebbd091aebc132f97ffd6ce9cf7964a57981.tar.gz gdb-df25ebbd091aebc132f97ffd6ce9cf7964a57981.tar.bz2 |
gdb/DWARF: Support for arrays whose bound is a discriminant.
Consider the following declarations:
type Array_Type is array (Integer range <>) of Integer;
type Record_Type (N : Integer) is record
A : Array_Type (1 .. N);
end record;
R : Record_Type := Get (10);
It defines what Ada programers call a "discriminated record", where
"N" is a component of that record called a "discriminant", and where
"A" is a component defined as an array type whose upper bound is
equal to the value of the discriminant.
So far, we rely on a number of fairly complex GNAT-specific encodings
to handle this situation. This patch is to enhance GDB to be able to
print this record in the case where the compiler has been modified
to replace those encodings by pure DWARF constructs.
In particular, the debugging information generated for the record above
looks like the following. "R" is a record..
.uleb128 0x10 # (DIE (0x13e) DW_TAG_structure_type)
.long .LASF17 # DW_AT_name: "foo__record_type"
... whose is is of course dynamic (not our concern here)...
.uleb128 0xd # DW_AT_byte_size
.byte 0x97 # DW_OP_push_object_address
.byte 0x94 # DW_OP_deref_size
.byte 0x4
.byte 0x99 # DW_OP_call4
.long 0x19b
.byte 0x23 # DW_OP_plus_uconst
.uleb128 0x7
.byte 0x9 # DW_OP_const1s
.byte 0xfc
.byte 0x1a # DW_OP_and
.byte 0x1 # DW_AT_decl_file (foo.adb)
.byte 0x6 # DW_AT_decl_line
... and then has 2 members, fist "n" (our discriminant);
.uleb128 0x11 # (DIE (0x153) DW_TAG_member)
.ascii "n\0" # DW_AT_name
.byte 0x1 # DW_AT_decl_file (foo.adb)
.byte 0x6 # DW_AT_decl_line
.long 0x194 # DW_AT_type
.byte 0 # DW_AT_data_member_location
... and "A"...
.uleb128 0x11 # (DIE (0x181) DW_TAG_member)
.ascii "a\0" # DW_AT_name
.long 0x15d # DW_AT_type
.byte 0x4 # DW_AT_data_member_location
... which is an array ...
.uleb128 0x12 # (DIE (0x15d) DW_TAG_array_type)
.long .LASF18 # DW_AT_name: "foo__record_type__T4b"
.long 0x194 # DW_AT_type
... whose lower bound is implicitly 1, and the upper bound
a reference to DIE 0x153 = "N":
.uleb128 0x13 # (DIE (0x16a) DW_TAG_subrange_type)
.long 0x174 # DW_AT_type
.long 0x153 # DW_AT_upper_bound
This patch enhanced GDB to understand references to other DIEs
where the DIE's address is at an offset of its enclosing type.
The difficulty was that the address used to resolve the array's
type (R's address + 4 bytes) is different from the address used
as the base to compute N's address (an offset to R's address).
We're solving this issue by using a stack of addresses rather
than a single address when trying to resolve a type. Each address
in the stack corresponds to each containing level. For instance,
if resolving the field of a struct, the stack should contain
the address of the field at the top, and then the address of
the struct. That way, if the field makes a reference to an object
of the struct, we can retrieve the address of that struct, and
properly resolve the dynamic property references that struct.
gdb/ChangeLog:
* gdbtypes.h (struct dynamic_prop): New PROP_ADDR_OFFSET enum
kind.
* gdbtypes.c (resolve_dynamic_type_internal): Replace "addr"
parameter by "addr_stack" parameter.
(resolve_dynamic_range): Replace "addr" parameter by
"stack_addr" parameter. Update function documentation.
Update code accordingly.
(resolve_dynamic_array, resolve_dynamic_union)
(resolve_dynamic_struct, resolve_dynamic_type_internal): Likewise.
(resolve_dynamic_type): Update code, following the changes made
to resolve_dynamic_type_internal's interface.
* dwarf2loc.h (struct property_addr_info): New.
(dwarf2_evaluate_property): Replace "address" parameter
by "addr_stack" parameter. Adjust function documentation.
(struct dwarf2_offset_baton): New.
(struct dwarf2_property_baton): Update documentation of
field "referenced_type" to be more general. New field
"offset_info" in union data field.
* dwarf2loc.c (dwarf2_evaluate_property): Replace "address"
parameter by "addr_stack" parameter. Adjust code accordingly.
Add support for PROP_ADDR_OFFSET properties.
* dwarf2read.c (attr_to_dynamic_prop): Add support for
DW_AT_data_member_location attributes as well. Use case
statements instead of if/else condition.
gdb/testsuite/ChangeLog:
* gdb.ada/disc_arr_bound: New testcase.
Tested on x86_64-linux, no regression.
Diffstat (limited to 'gdb/dwarf2loc.h')
-rw-r--r-- | gdb/dwarf2loc.h | 45 |
1 files changed, 41 insertions, 4 deletions
diff --git a/gdb/dwarf2loc.h b/gdb/dwarf2loc.h index a369361..0932456 100644 --- a/gdb/dwarf2loc.h +++ b/gdb/dwarf2loc.h @@ -102,13 +102,30 @@ struct value *dwarf2_evaluate_loc_desc (struct type *type, size_t size, struct dwarf2_per_cu_data *per_cu); -/* Converts a dynamic property into a static one. ADDRESS is the address - of the object currently being evaluated and might be nedded. +/* A chain of addresses that might be needed to resolve a dynamic + property. */ + +struct property_addr_info +{ + /* The type of the object whose dynamic properties, if any, are + being resolved. */ + struct type *type; + + /* The address of that object. */ + CORE_ADDR addr; + + /* If not NULL, a pointer to the info for the object containing + the object described by this node. */ + struct property_addr_info *next; +}; + +/* Converts a dynamic property into a static one. ADDR_STACK is the stack + of addresses that might be needed to evaluate the property. Returns 1 if PROP could be converted and the static value is passed back into VALUE, otherwise returns 0. */ int dwarf2_evaluate_property (const struct dynamic_prop *prop, - CORE_ADDR address, + struct property_addr_info *addr_stack, CORE_ADDR *value); /* A helper for the compiler interface that compiles a single dynamic @@ -177,6 +194,23 @@ struct dwarf2_loclist_baton unsigned char from_dwo; }; +/* The baton used when a dynamic property is an offset to a parent + type. This can be used, for instance, then the bound of an array + inside a record is determined by the value of another field inside + that record. */ + +struct dwarf2_offset_baton +{ + /* The offset from the parent type where the value of the property + is stored. In the example provided above, this would be the offset + of the field being used as the array bound. */ + LONGEST offset; + + /* The type of the object whose property is dynamic. In the example + provided above, this would the the array's index type. */ + struct type *type; +}; + /* A dynamic property is either expressed as a single location expression or a location list. If the property is an indirection, pointing to another die, keep track of the targeted type in REFERENCED_TYPE. */ @@ -184,7 +218,7 @@ struct dwarf2_loclist_baton struct dwarf2_property_baton { /* If the property is an indirection, we need to evaluate the location - LOCEXPR or LOCLIST in the context of the type REFERENCED_TYPE. + in the context of the type REFERENCED_TYPE. If NULL, the location is the actual value of the property. */ struct type *referenced_type; union @@ -194,6 +228,9 @@ struct dwarf2_property_baton /* Location list to be evaluated in the context of REFERENCED_TYPE. */ struct dwarf2_loclist_baton loclist; + + /* The location is an offset to REFERENCED_TYPE. */ + struct dwarf2_offset_baton offset_info; }; }; |