1 # Copyright 2020-2021 Free Software Foundation, Inc.
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 # Test for issue PR gdb/27059. The problem was that when resolving a
17 # dynamic type that was not-allocated GDB would still try to execute
18 # the DWARF expressions for the upper, lower, and byte-stride values.
20 # The problem is that, at least in some gfortran compiled programs,
21 # these values are undefined until the array is allocated.
23 # As a result, executing the dwarf expressions was triggering integer
24 # overflow in some cases.
26 # This test aims to make the sometimes occurring integer overflow a
27 # more noticeable error by creating an array that is always marked as
30 # The dwarf expressions for the various attributes then contains an
31 # infinite loop. If GDB ever tries to execute these expressions we
32 # will get a test timeout. With this issue fixed the expressions are
33 # never executed and the test completes as we'd expect.
37 if {![dwarf2_support]} {
41 standard_testfile .c -dw.S
43 if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] } {
47 set asm_file [standard_output_file $srcfile2]
48 Dwarf::assemble $asm_file {
54 {language @DW_LANG_Fortran90}
58 declare_labels array_type_label integer_type_label
60 set int_size [get_sizeof "int" "UNKNOWN"]
61 set voidp_size [get_sizeof "void *" "UNKNOWN"]
63 integer_type_label: DW_TAG_base_type {
64 {DW_AT_byte_size $int_size DW_FORM_sdata}
65 {DW_AT_encoding @DW_ATE_signed}
69 array_type_label: DW_TAG_array_type {
70 {DW_AT_type :$integer_type_label}
71 {DW_AT_data_location {
72 DW_OP_push_object_address
79 DW_TAG_subrange_type {
80 {DW_AT_type :$integer_type_label}
95 DW_OP_addr [gdb_target_symbol dyn_object]
98 {type :$array_type_label}
102 {MACRO_AT_func {main}}
108 if { [prepare_for_testing "failed to prepare" "${testfile}" \
109 [list $srcfile $asm_file] {nodebug}] } {
117 gdb_breakpoint "marker_label"
118 gdb_continue_to_breakpoint "stop at marker_label"
119 gdb_test "ptype dyn_object" "type = integer, allocatable \\(:\\)"