
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>
57 lines
1.8 KiB
Text
57 lines
1.8 KiB
Text
# Copyright 2020-2024 Free Software Foundation, Inc.
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation; either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/> .
|
|
|
|
# Test for GDB printing a pointer to a type containing a buffer.
|
|
|
|
require allow_fortran_tests
|
|
|
|
standard_testfile ".f90"
|
|
load_lib fortran.exp
|
|
|
|
if {[prepare_for_testing ${testfile}.exp ${testfile} ${srcfile} \
|
|
{debug f90}]} {
|
|
return -1
|
|
}
|
|
|
|
if ![fortran_runto_main] {
|
|
return -1
|
|
}
|
|
|
|
# Depending on the compiler being used, the type names can be printed
|
|
# differently.
|
|
set real4 [fortran_real4]
|
|
|
|
gdb_breakpoint [gdb_get_line_number "Break Here"]
|
|
gdb_continue_to_breakpoint "Break Here"
|
|
|
|
gdb_test "print buffer" \
|
|
" = \\(PTR TO -> \\( Type l_buffer \\)\\) $hex"
|
|
gdb_test "ptype buffer" \
|
|
[multi_line \
|
|
"type = PTR TO -> \\( Type l_buffer" \
|
|
" $real4 :: alpha\\(5\\)" \
|
|
"End Type l_buffer \\)" ]
|
|
gdb_test "ptype buffer%alpha" "type = $real4 \\(5\\)"
|
|
|
|
# GDB allows pointer types to be dereferenced using '*'. This is not
|
|
# real Fortran syntax, just something extra that GDB supports.
|
|
gdb_test "print *buffer" \
|
|
" = \\( alpha = \\(1\\.5, 2\\.5, 3\\.5, 4\\.5, 5\\.5\\) \\)"
|
|
gdb_test "ptype *buffer" \
|
|
[multi_line \
|
|
"type = Type l_buffer" \
|
|
" $real4 :: alpha\\(5\\)" \
|
|
"End Type l_buffer" ]
|
|
gdb_test "ptype (*buffer)%alpha" "type = $real4 \\(5\\)"
|