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