Automatic Copyright Year update after running gdb/copyright.py
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.fortran / intvar-dynamic-types.exp
CommitLineData
88b9d363 1# Copyright 2020-2022 Free Software Foundation, Inc.
3c8c6de2
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# Places a value with components that have dynamic type into a GDB
17# user variable, and then prints the user variable.
18
19standard_testfile ".f90"
20load_lib "fortran.exp"
21
22if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile} \
23 {debug f90 quiet}] } {
24 return -1
25}
26
27if ![fortran_runto_main] {
28 untested "could not run to main"
29 return -1
30}
31
32gdb_breakpoint [gdb_get_line_number "Break here"]
33gdb_continue_to_breakpoint "Break here"
34
35gdb_test_no_output "set \$a=some_var" "set \$a internal variable"
36
37foreach 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"
42
43 gdb_test "print $var%array_one" \
44 " = \\(\\(1, 1\\) \\(1, 1\\) \\(1, 1\\)\\)" \
45 "print array_one field"
46
47 gdb_test "print $var%a_field" \
48 " = 5" \
49 "print a_field field"
50
51 gdb_test "print $var%array_two" \
52 " = \\(\\(2, 2, 2\\) \\(2, 2, 2\\)\\)" \
53 "print array_two field"
54 }
55}
56
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.
60gdb_test_no_output "set \$b = some_var%array_one"
61gdb_test_no_output "set \$c = some_var%array_two"
62gdb_test "print \$b" \
63 " = \\(\\(1, 1\\) \\(1, 1\\) \\(1, 1\\)\\)"
64gdb_test "print \$c" \
65 " = \\(\\(2, 2, 2\\) \\(2, 2, 2\\)\\)"
66gdb_test_no_output "set \$b(2,2) = 3"
67gdb_test_no_output "set \$c(3,1) = 4"
68gdb_test "print \$b" \
69 " = \\(\\(1, 1\\) \\(1, 3\\) \\(1, 1\\)\\)" \
70 "print \$b after a change"
71gdb_test "print \$c" \
72 " = \\(\\(2, 2, 4\\) \\(2, 2, 2\\)\\)" \
73 "print \$c after a change"
74gdb_test "print some_var%array_one" \
75 " = \\(\\(1, 1\\) \\(1, 1\\) \\(1, 1\\)\\)"
76gdb_test "print some_var%array_two" \
77 " = \\(\\(2, 2, 2\\) \\(2, 2, 2\\)\\)"
78
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.
82#
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.
85#
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.
91gdb_test_no_output "set \$a%a_field = 3"
92gdb_test_no_output "set \$a%array_one(2,2) = 3"
93gdb_test_no_output "set \$a%array_two(3,1) = 4"
94gdb_test "print \$a" \
95 " = \\( array_one = \\(\\(1, 1\\) \\(1, 3\\) \\(1, 1\\)\\), a_field = 3, array_two = \\(\\(2, 2, 4\\) \\(2, 2, 2\\)\\) \\)"
96gdb_test "print some_var" \
97 " = \\( array_one = \\(\\(1, 1\\) \\(1, 3\\) \\(1, 1\\)\\), a_field = 5, array_two = \\(\\(2, 2, 4\\) \\(2, 2, 2\\)\\) \\)"
This page took 0.108726 seconds and 4 git commands to generate.