6c6a4840bd5a0215fcaa722a1b5ddb0b04541700
[external/binutils.git] / gdb / testsuite / gdb.fortran / vla-value.exp
1 # Copyright 2015-2016 Free Software Foundation, Inc.
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 standard_testfile "vla.f90"
17
18 if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile} \
19      {debug f90 quiet}] } {
20     return -1
21 }
22
23 if ![runto_main] {
24     untested "could not run to main"
25     return -1
26 }
27
28 # Try to access values in non allocated VLA
29 gdb_breakpoint [gdb_get_line_number "vla1-init"]
30 gdb_continue_to_breakpoint "vla1-init"
31 gdb_test "print vla1" " = <not allocated>" "print non-allocated vla1"
32 gdb_test "print &vla1" \
33   " = \\\(PTR TO -> \\\( real\\\(kind=4\\\) \\\(<not allocated>\\\)\\\)\\\) $hex" \
34   "print non-allocated &vla1"
35 gdb_test "print vla1(1,1,1)" "no such vector element \\\(vector not allocated\\\)" \
36   "print member in non-allocated vla1 (1)"
37 gdb_test "print vla1(101,202,303)" \
38   "no such vector element \\\(vector not allocated\\\)" \
39   "print member in non-allocated vla1 (2)"
40 gdb_test "print vla1(5,2,18)=1" "no such vector element \\\(vector not allocated\\\)" \
41   "set member in non-allocated vla1"
42
43 # Try to access value in allocated VLA
44 gdb_breakpoint [gdb_get_line_number "vla2-allocated"]
45 gdb_continue_to_breakpoint "vla2-allocated"
46 gdb_test "next" "\\d+(\\t|\\s)+vla1\\\(3, 6, 9\\\) = 42" \
47   "step over value assignment of vla1"
48 gdb_test "print &vla1" \
49   " = \\\(PTR TO -> \\\( real\\\(kind=4\\\) \\\(10,10,10\\\)\\\)\\\) $hex" \
50   "print allocated &vla1"
51 gdb_test "print vla1(3, 6, 9)" " = 1311" "print allocated vla1(3,6,9)"
52 gdb_test "print vla1(1, 3, 8)" " = 1311" "print allocated vla1(1,3,8)"
53 gdb_test "print vla1(9, 9, 9) = 999" " = 999" \
54   "print allocated vla1(9,9,9)=1"
55
56 # Try to access values in allocated VLA after specific assignment
57 gdb_breakpoint [gdb_get_line_number "vla1-filled"]
58 gdb_continue_to_breakpoint "vla1-filled"
59 gdb_test "print vla1(3, 6, 9)" " = 42" \
60   "print allocated vla1(3,6,9) after specific assignment (filled)"
61 gdb_test "print vla1(1, 3, 8)" " = 1001" \
62   "print allocated vla1(1,3,8) after specific assignment (filled)"
63 gdb_test "print vla1(9, 9, 9)" " = 999" \
64   "print allocated vla1(9,9,9) after assignment in debugger (filled)"
65
66 # Try to access values in undefined pointer to VLA (dangling)
67 gdb_test "print pvla" " = <not associated>" "print undefined pvla"
68 gdb_test "print &pvla" \
69   " = \\\(PTR TO -> \\\( real\\\(kind=4\\\) \\\(<not associated>\\\)\\\)\\\) $hex" \
70   "print non-associated &pvla"
71 gdb_test "print pvla(1, 3, 8)" "no such vector element \\\(vector not associated\\\)" \
72   "print undefined pvla(1,3,8)"
73
74 # Try to access values in pointer to VLA and compare them
75 gdb_breakpoint [gdb_get_line_number "pvla-associated"]
76 gdb_continue_to_breakpoint "pvla-associated"
77 gdb_test "print &pvla" \
78   " = \\\(PTR TO -> \\\( real\\\(kind=4\\\) \\\(10,10,10\\\)\\\)\\\) $hex" \
79   "print associated &pvla"
80 gdb_test "print pvla(3, 6, 9)" " = 42" "print associated pvla(3,6,9)"
81 gdb_test "print pvla(1, 3, 8)" " = 1001" "print associated pvla(1,3,8)"
82 gdb_test "print pvla(9, 9, 9)" " = 999" "print associated pvla(9,9,9)"
83
84 # Fill values to VLA using pointer and check
85 gdb_breakpoint [gdb_get_line_number "pvla-re-associated"]
86 gdb_continue_to_breakpoint "pvla-re-associated"
87 gdb_test "print pvla(5, 45, 20)" \
88   " = 1" "print pvla(5, 45, 20) after filled using pointer"
89 gdb_test "print vla2(5, 45, 20)" \
90   " = 1" "print vla2(5, 45, 20) after filled using pointer"
91 gdb_test "print pvla(7, 45, 14)" " = 2" \
92   "print pvla(7, 45, 14) after filled using pointer"
93 gdb_test "print vla2(7, 45, 14)" " = 2" \
94   "print vla2(7, 45, 14) after filled using pointer"
95
96 # Try to access values of deassociated VLA pointer
97 gdb_breakpoint [gdb_get_line_number "pvla-deassociated"]
98 gdb_continue_to_breakpoint "pvla-deassociated"
99 gdb_test "print pvla(5, 45, 20)" \
100   "no such vector element \\\(vector not associated\\\)" \
101   "print pvla(5, 45, 20) after deassociated"
102 gdb_test "print pvla(7, 45, 14)" \
103   "no such vector element \\\(vector not associated\\\)" \
104   "print pvla(7, 45, 14) after dissasociated"
105 gdb_test "print pvla" " = <not associated>" \
106   "print vla1 after deassociated"
107
108 # Try to access values of deallocated VLA
109 gdb_breakpoint [gdb_get_line_number "vla1-deallocated"]
110 gdb_continue_to_breakpoint "vla1-deallocated"
111 gdb_test "print vla1(3, 6, 9)" "no such vector element \\\(vector not allocated\\\)" \
112   "print allocated vla1(3,6,9) after specific assignment (deallocated)"
113 gdb_test "print vla1(1, 3, 8)" "no such vector element \\\(vector not allocated\\\)" \
114   "print allocated vla1(1,3,8) after specific assignment (deallocated)"
115 gdb_test "print vla1(9, 9, 9)" "no such vector element \\\(vector not allocated\\\)" \
116   "print allocated vla1(9,9,9) after assignment in debugger (deallocated)"
117
118
119 # Try to assign VLA to user variable
120 clean_restart ${testfile}
121
122 if ![runto MAIN__] then {
123     perror "couldn't run to breakpoint MAIN__"
124     continue
125 }
126 gdb_breakpoint [gdb_get_line_number "vla2-allocated"]
127 gdb_continue_to_breakpoint "vla2-allocated"
128 gdb_test "next" "\\d+.*vla1\\(3, 6, 9\\) = 42" "next (1)"
129
130 gdb_test_no_output "set \$myvar = vla1" "set \$myvar = vla1"
131 gdb_test "print \$myvar" \
132   " = \\( *\\( *\\( *1311, *1311, *1311,\[()1311, .\]*\\)" \
133   "print \$myvar set to vla1"
134
135 gdb_test "next" "\\d+.*vla1\\(1, 3, 8\\) = 1001" "next (2)"
136 gdb_test "print \$myvar(3,6,9)" " = 1311" "print \$myvar(3,6,9)"
137
138 gdb_breakpoint [gdb_get_line_number "pvla-associated"]
139 gdb_continue_to_breakpoint "pvla-associated"
140 gdb_test_no_output "set \$mypvar = pvla" "set \$mypvar = pvla"
141 gdb_test "print \$mypvar(1,3,8)" " = 1001" "print \$mypvar(1,3,8)"
142
143 # deallocate pointer and make sure user defined variable still has the
144 # right value.
145 gdb_breakpoint [gdb_get_line_number "pvla-deassociated"]
146 gdb_continue_to_breakpoint "pvla-deassociated"
147 gdb_test "print \$mypvar(1,3,8)" " = 1001" \
148   "print \$mypvar(1,3,8) after deallocated"