diff options
author | Bernhard Heckel <bernhard.heckel@intel.com> | 2022-10-13 15:17:23 +0200 |
---|---|---|
committer | Ijaz, Abdul B <abdul.b.ijaz@intel.com> | 2024-02-02 08:57:16 +0100 |
commit | f18fc7e56fbb605aa38643881eb0228313466551 (patch) | |
tree | d97a46d5aa4592514b7842f84a9a541371fed236 /gdb/gdbtypes.c | |
parent | 2e07108364e2c8494a41919a56ca4a40092c9d58 (diff) | |
download | binutils-f18fc7e56fbb605aa38643881eb0228313466551.zip binutils-f18fc7e56fbb605aa38643881eb0228313466551.tar.gz binutils-f18fc7e56fbb605aa38643881eb0228313466551.tar.bz2 |
gdb, types: Resolve pointer types dynamically
This commit allows pointers to be dynamic types (on the outmost
level). Similar to references, a pointer is considered a dynamic type
if its target type is a dynamic type and it is on the outmost level.
Also this commit removes the redundant code inside function
"value_check_printable" for handling of DW_AT_associated type.
The pointer resolution follows the one of references.
This change generally makes the GDB output more verbose. We are able to
print more details about a pointer's target like the dimension of an array.
In Fortran, if we have a pointer to a dynamic type
type buffer
real, dimension(:), pointer :: ptr
end type buffer
type(buffer), pointer :: buffer_ptr
allocate (buffer_ptr)
allocate (buffer_ptr%ptr (5))
which then gets allocated, we now resolve the dynamic type before
printing the pointer's type:
Before:
(gdb) ptype buffer_ptr
type = PTR TO -> ( Type buffer
real(kind=4) :: alpha(:)
End Type buffer )
After:
(gdb) ptype buffer_ptr
type = PTR TO -> ( Type buffer
real(kind=4) :: alpha(5)
End Type buffer )
Similarly in C++ we can dynamically resolve e.g. pointers to arrays:
int len = 3;
int arr[len];
int (*ptr)[len];
int ptr = &arr;
Once the pointer is assigned one gets:
Before:
(gdb) p ptr
$1 = (int (*)[variable length]) 0x123456
(gdb) ptype ptr
type = int (*)[variable length]
After:
(gdb) p ptr
$1 = (int (*)[3]) 0x123456
(gdb) ptype ptr
type = int (*)[3]
For more examples see the modified/added test cases.
Tested-by: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
Approved-By: Tom Tromey <tom@tromey.com>
Diffstat (limited to 'gdb/gdbtypes.c')
-rw-r--r-- | gdb/gdbtypes.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c index 2e55a29..ece161d 100644 --- a/gdb/gdbtypes.c +++ b/gdb/gdbtypes.c @@ -2043,8 +2043,9 @@ is_dynamic_type_internal (struct type *type, int top_level) { type = check_typedef (type); - /* We only want to recognize references at the outermost level. */ - if (top_level && type->code () == TYPE_CODE_REF) + /* We only want to recognize references and pointers at the outermost + level. */ + if (top_level && type->is_pointer_or_reference ()) type = check_typedef (type->target_type ()); /* Types that have a dynamic TYPE_DATA_LOCATION are considered @@ -2780,6 +2781,8 @@ resolve_dynamic_type_internal (struct type *type, switch (type->code ()) { case TYPE_CODE_REF: + case TYPE_CODE_PTR: + case TYPE_CODE_RVALUE_REF: { struct property_addr_info pinfo; |