]>
Commit | Line | Data |
---|---|---|
1d506c26 | 1 | # Copyright 2020-2024 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 | ||
35 | load_lib dwarf.exp | |
36 | ||
ce8d533e | 37 | require dwarf2_support |
b7874836 AB |
38 | |
39 | standard_testfile .c -dw.S | |
40 | ||
f2259ae7 TV |
41 | set flags {} |
42 | lappend flags debug | |
43 | lappend_include_file flags $srcdir/lib/attributes.h | |
44 | ||
45 | if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} $flags] } { | |
b7874836 AB |
46 | return -1 |
47 | } | |
48 | ||
f2259ae7 TV |
49 | with_shared_gdb { |
50 | set func_info_vars [get_func_info main $flags] | |
51 | ||
52 | set int_size [get_sizeof "int" "UNKNOWN"] | |
53 | set voidp_size [get_sizeof "void *" "UNKNOWN"] | |
54 | } | |
55 | ||
b7874836 AB |
56 | set asm_file [standard_output_file $srcfile2] |
57 | Dwarf::assemble $asm_file { | |
f2259ae7 TV |
58 | global func_info_vars |
59 | foreach var $func_info_vars { | |
60 | global $var | |
61 | } | |
62 | global int_size | |
63 | global voidp_size | |
64 | ||
b7874836 AB |
65 | cu {} { |
66 | global srcfile | |
67 | ||
68 | compile_unit { | |
69 | {producer "gcc" } | |
70 | {language @DW_LANG_Fortran90} | |
71 | {name ${srcfile}} | |
72 | {low_pc 0 addr} | |
73 | } { | |
74 | declare_labels array_type_label integer_type_label | |
75 | ||
b7874836 AB |
76 | integer_type_label: DW_TAG_base_type { |
77 | {DW_AT_byte_size $int_size DW_FORM_sdata} | |
78 | {DW_AT_encoding @DW_ATE_signed} | |
79 | {DW_AT_name integer} | |
80 | } | |
81 | ||
82 | array_type_label: DW_TAG_array_type { | |
83 | {DW_AT_type :$integer_type_label} | |
84 | {DW_AT_data_location { | |
85 | DW_OP_push_object_address | |
86 | DW_OP_deref | |
87 | } SPECIAL_expr} | |
88 | {DW_AT_allocated { | |
89 | DW_OP_lit0 | |
90 | } SPECIAL_expr} | |
91 | } { | |
92 | DW_TAG_subrange_type { | |
93 | {DW_AT_type :$integer_type_label} | |
94 | {DW_AT_lower_bound { | |
95 | DW_OP_skip -3 | |
96 | } SPECIAL_expr} | |
97 | {DW_AT_upper_bound { | |
98 | DW_OP_skip -3 | |
99 | } SPECIAL_expr} | |
100 | {DW_AT_byte_stride { | |
101 | DW_OP_skip -3 | |
102 | } SPECIAL_expr} | |
103 | } | |
104 | } | |
105 | ||
106 | DW_TAG_variable { | |
107 | {DW_AT_location { | |
108 | DW_OP_addr [gdb_target_symbol dyn_object] | |
109 | } SPECIAL_expr} | |
110 | {name "dyn_object"} | |
111 | {type :$array_type_label} | |
112 | } | |
f2259ae7 TV |
113 | subprogram { |
114 | {external 1 flag} | |
115 | {DW_AT_name main} | |
116 | {DW_AT_low_pc $main_start DW_FORM_addr} | |
117 | {DW_AT_high_pc $main_end DW_FORM_addr} | |
118 | } | |
b7874836 AB |
119 | } |
120 | } | |
121 | } | |
122 | ||
f2259ae7 TV |
123 | set flags {} |
124 | lappend flags {nodebug} | |
125 | lappend_include_file flags $srcdir/lib/attributes.h | |
126 | ||
b7874836 | 127 | if { [prepare_for_testing "failed to prepare" "${testfile}" \ |
f2259ae7 | 128 | [list $srcfile $asm_file] $flags] } { |
b7874836 AB |
129 | return -1 |
130 | } | |
131 | ||
132 | if ![runto_main] { | |
133 | return -1 | |
134 | } | |
135 | ||
136 | gdb_breakpoint "marker_label" | |
137 | gdb_continue_to_breakpoint "stop at marker_label" | |
138 | gdb_test "ptype dyn_object" "type = integer, allocatable \\(:\\)" |