]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit
gdb, types: Resolve pointer types dynamically
authorBernhard Heckel <bernhard.heckel@intel.com>
Thu, 13 Oct 2022 13:17:23 +0000 (15:17 +0200)
committerIjaz, Abdul B <abdul.b.ijaz@intel.com>
Fri, 2 Feb 2024 07:57:16 +0000 (08:57 +0100)
commitf18fc7e56fbb605aa38643881eb0228313466551
treed97a46d5aa4592514b7842f84a9a541371fed236
parent2e07108364e2c8494a41919a56ca4a40092c9d58
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>
gdb/gdbtypes.c
gdb/testsuite/gdb.cp/vla-cxx.cc
gdb/testsuite/gdb.cp/vla-cxx.exp
gdb/testsuite/gdb.dwarf2/dynarr-ptr.exp
gdb/testsuite/gdb.fortran/pointer-to-pointer.exp
gdb/testsuite/gdb.fortran/pointers.exp [new file with mode: 0644]
gdb/testsuite/gdb.fortran/pointers.f90
gdb/valprint.c