]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.dwarf2/dyn-type-unallocated.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.dwarf2 / dyn-type-unallocated.exp
CommitLineData
213516ef 1# Copyright 2020-2023 Free Software Foundation, Inc.
b7874836
AB
2
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.
7#
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.
12#
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/>.
15
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.
19#
20# The problem is that, at least in some gfortran compiled programs,
21# these values are undefined until the array is allocated.
22#
23# As a result, executing the dwarf expressions was triggering integer
24# overflow in some cases.
25#
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
28# not-allocated.
29#
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.
34
35load_lib dwarf.exp
36
37if {![dwarf2_support]} {
38 return 0
39}
40
41standard_testfile .c -dw.S
42
43if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] } {
44 return -1
45}
46
47set asm_file [standard_output_file $srcfile2]
48Dwarf::assemble $asm_file {
49 cu {} {
50 global srcfile
51
52 compile_unit {
53 {producer "gcc" }
54 {language @DW_LANG_Fortran90}
55 {name ${srcfile}}
56 {low_pc 0 addr}
57 } {
58 declare_labels array_type_label integer_type_label
59
60 set int_size [get_sizeof "int" "UNKNOWN"]
61 set voidp_size [get_sizeof "void *" "UNKNOWN"]
62
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}
66 {DW_AT_name integer}
67 }
68
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
73 DW_OP_deref
74 } SPECIAL_expr}
75 {DW_AT_allocated {
76 DW_OP_lit0
77 } SPECIAL_expr}
78 } {
79 DW_TAG_subrange_type {
80 {DW_AT_type :$integer_type_label}
81 {DW_AT_lower_bound {
82 DW_OP_skip -3
83 } SPECIAL_expr}
84 {DW_AT_upper_bound {
85 DW_OP_skip -3
86 } SPECIAL_expr}
87 {DW_AT_byte_stride {
88 DW_OP_skip -3
89 } SPECIAL_expr}
90 }
91 }
92
93 DW_TAG_variable {
94 {DW_AT_location {
95 DW_OP_addr [gdb_target_symbol dyn_object]
96 } SPECIAL_expr}
97 {name "dyn_object"}
98 {type :$array_type_label}
99 }
100 subprogram {
101 {external 1 flag}
102 {MACRO_AT_func {main}}
103 }
104 }
105 }
106}
107
108if { [prepare_for_testing "failed to prepare" "${testfile}" \
109 [list $srcfile $asm_file] {nodebug}] } {
110 return -1
111}
112
113if ![runto_main] {
114 return -1
115}
116
117gdb_breakpoint "marker_label"
118gdb_continue_to_breakpoint "stop at marker_label"
119gdb_test "ptype dyn_object" "type = integer, allocatable \\(:\\)"