Rename gdb/ChangeLog to gdb/ChangeLog-2021
[binutils-gdb.git] / gdb / testsuite / gdb.fortran / intvar-dynamic-types.exp
blob16dc603cb47718b66974556d56b658183394c02f
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 # Places a value with components that have dynamic type into a GDB
17 # user variable, and then prints the user variable.
19 standard_testfile ".f90"
20 load_lib "fortran.exp"
22 if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile} \
23 {debug f90 quiet}] } {
24 return -1
27 if ![fortran_runto_main] {
28 untested "could not run to main"
29 return -1
32 gdb_breakpoint [gdb_get_line_number "Break here"]
33 gdb_continue_to_breakpoint "Break here"
35 gdb_test_no_output "set \$a=some_var" "set \$a internal variable"
37 foreach var { "\$a" "some_var" } {
38 with_test_prefix "print $var" {
39 gdb_test "print $var" \
40 " = \\( array_one = \\(\\(1, 1\\) \\(1, 1\\) \\(1, 1\\)\\), a_field = 5, array_two = \\(\\(2, 2, 2\\) \\(2, 2, 2\\)\\) \\)" \
41 "print full contents"
43 gdb_test "print $var%array_one" \
44 " = \\(\\(1, 1\\) \\(1, 1\\) \\(1, 1\\)\\)" \
45 "print array_one field"
47 gdb_test "print $var%a_field" \
48 " = 5" \
49 "print a_field field"
51 gdb_test "print $var%array_two" \
52 " = \\(\\(2, 2, 2\\) \\(2, 2, 2\\)\\)" \
53 "print array_two field"
57 # Create new user variables for the fields of some_var, and show that
58 # modifying these variables does not change the original value from
59 # the program.
60 gdb_test_no_output "set \$b = some_var%array_one"
61 gdb_test_no_output "set \$c = some_var%array_two"
62 gdb_test "print \$b" \
63 " = \\(\\(1, 1\\) \\(1, 1\\) \\(1, 1\\)\\)"
64 gdb_test "print \$c" \
65 " = \\(\\(2, 2, 2\\) \\(2, 2, 2\\)\\)"
66 gdb_test_no_output "set \$b(2,2) = 3"
67 gdb_test_no_output "set \$c(3,1) = 4"
68 gdb_test "print \$b" \
69 " = \\(\\(1, 1\\) \\(1, 3\\) \\(1, 1\\)\\)" \
70 "print \$b after a change"
71 gdb_test "print \$c" \
72 " = \\(\\(2, 2, 4\\) \\(2, 2, 2\\)\\)" \
73 "print \$c after a change"
74 gdb_test "print some_var%array_one" \
75 " = \\(\\(1, 1\\) \\(1, 1\\) \\(1, 1\\)\\)"
76 gdb_test "print some_var%array_two" \
77 " = \\(\\(2, 2, 2\\) \\(2, 2, 2\\)\\)"
79 # Now modify the user variable '$a', which is a copy of 'some_var',
80 # and then check how this change is reflected in the original
81 # 'some_var', and the user variable $a.
83 # When we change 'a_field' which is a non-dynamic field within the
84 # user variable, the change is only visible within the user variable.
86 # In contrast, when we change 'array_one' and 'array_two', which are
87 # both fields of dynanic type, then the change is visible in both the
88 # user variable and the original program variable 'some_var'. This
89 # makes sense if you consider the dynamic type as if it was a C
90 # pointer with automatic indirection.
91 gdb_test_no_output "set \$a%a_field = 3"
92 gdb_test_no_output "set \$a%array_one(2,2) = 3"
93 gdb_test_no_output "set \$a%array_two(3,1) = 4"
94 gdb_test "print \$a" \
95 " = \\( array_one = \\(\\(1, 1\\) \\(1, 3\\) \\(1, 1\\)\\), a_field = 3, array_two = \\(\\(2, 2, 4\\) \\(2, 2, 2\\)\\) \\)"
96 gdb_test "print some_var" \
97 " = \\( array_one = \\(\\(1, 1\\) \\(1, 3\\) \\(1, 1\\)\\), a_field = 5, array_two = \\(\\(2, 2, 4\\) \\(2, 2, 2\\)\\) \\)"