Revert "[gdb/testsuite] Clean standard_output_file dir in gdb_init"
[binutils-gdb.git] / gdb / testsuite / gdb.fortran / array-slices-sub-slices.exp
blob10778b1543f2e69add1cc8db02263be031ff5078
1 # Copyright 2020-2023 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 # Create a slice of an array, then take a slice of that slice.
18 require allow_fortran_tests
20 standard_testfile ".f90"
21 load_lib fortran.exp
23 if {[prepare_for_testing ${testfile}.exp ${testfile} ${srcfile} \
24 {debug f90}]} {
25 return -1
28 # Avoid shared lib symbols.
29 gdb_test_no_output "set auto-solib-add off"
31 if ![fortran_runto_main] {
32 return -1
35 # Avoid libc symbols, in particular the 'array' type.
36 gdb_test_no_output "nosharedlibrary"
38 # gdb_breakpoint [gdb_get_line_number "Display Message Breakpoint"]
39 gdb_breakpoint [gdb_get_line_number "Stop Here"]
40 gdb_breakpoint [gdb_get_line_number "Final Breakpoint"]
42 # We're going to print some reasonably large arrays.
43 gdb_test_no_output "set print elements unlimited"
45 gdb_continue_to_breakpoint "Stop Here"
47 # Print a slice, capture the convenience variable name created.
48 set cmd "print array (1:10:2, 1:10:2)"
49 gdb_test_multiple $cmd $cmd {
50 -re "\r\n\\\$(\\d+) = .*\r\n$gdb_prompt $" {
51 set varname "\$$expect_out(1,string)"
55 # Now check that we can correctly extract all the elements from this
56 # slice.
57 for { set j 1 } { $j < 6 } { incr j } {
58 for { set i 1 } { $i < 6 } { incr i } {
59 set val [expr ((($i - 1) * 2) + (($j - 1) * 20)) + 1]
60 gdb_test "print ${varname} ($i,$j)" " = $val"
64 # Now take a slice of the slice.
65 gdb_test "print ${varname} (3:5, 3:5)" \
66 " = \\(\\(45, 47, 49\\) \\(65, 67, 69\\) \\(85, 87, 89\\)\\)"
68 # Now take a different slice of a slice.
69 set cmd "print ${varname} (1:5:2, 1:5:2)"
70 gdb_test_multiple $cmd $cmd {
71 -re "\r\n\\\$(\\d+) = \\(\\(1, 5, 9\\) \\(41, 45, 49\\) \\(81, 85, 89\\)\\)\r\n$gdb_prompt $" {
72 set varname "\$$expect_out(1,string)"
73 pass $gdb_test_name
77 # Now take a slice from the slice, of a slice!
78 set cmd "print ${varname} (1:3:2, 1:3:2)"
79 gdb_test_multiple $cmd $cmd {
80 -re "\r\n\\\$(\\d+) = \\(\\(1, 9\\) \\(81, 89\\)\\)\r\n$gdb_prompt $" {
81 set varname "\$$expect_out(1,string)"
82 pass $gdb_test_name
86 # And again!
87 set cmd "print ${varname} (1:2:2, 1:2:2)"
88 gdb_test_multiple $cmd $cmd {
89 -re "\r\n\\\$(\\d+) = \\(\\(1\\)\\)\r\n$gdb_prompt $" {
90 set varname "\$$expect_out(1,string)"
91 pass $gdb_test_name
95 # Test taking a slice with stride of a string. This isn't actually
96 # supported within gfortran (at least), but naturally drops out of how
97 # GDB models arrays and strings in a similar way, so we may as well
98 # test that this is still working.
99 gdb_test "print str (1:26:2)" " = 'acegikmoqsuwy'"
100 gdb_test "print str (26:1:-1)" " = 'zyxwvutsrqponmlkjihgfedcba'"
101 gdb_test "print str (26:1:-2)" " = 'zxvtrpnljhfdb'"
103 # Now test the memory requirements of taking a slice from an array.
104 # The idea is that we shouldn't require more memory to extract a slice
105 # than the size of the slice.
107 # This will only work if array repacking is turned on, otherwise GDB
108 # will create the slice by generating a new type that sits over the
109 # existing value in memory.
110 gdb_test_no_output "set fortran repack-array-slices on"
111 set element_size [get_integer_valueof "sizeof (array (1,1))" "unknown"]
112 set slice_size [expr $element_size * 4]
113 gdb_test_no_output "set max-value-size $slice_size"
114 gdb_test "print array (1:2, 1:2)" "= \\(\\(1, 2\\) \\(11, 12\\)\\)"
115 gdb_test "print array (2:3, 2:3)" "= \\(\\(12, 13\\) \\(22, 23\\)\\)"
116 gdb_test "print array (2:5:2, 2:5:2)" "= \\(\\(12, 14\\) \\(32, 34\\)\\)"