]>
Commit | Line | Data |
---|---|---|
213516ef | 1 | # Copyright 2020-2023 Free Software Foundation, Inc. |
a5c641b5 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 | # Create a slice of an array, then take a slice of that slice. | |
17 | ||
18 | if {[skip_fortran_tests]} { return -1 } | |
19 | ||
20 | standard_testfile ".f90" | |
21 | load_lib fortran.exp | |
22 | ||
23 | if {[prepare_for_testing ${testfile}.exp ${testfile} ${srcfile} \ | |
24 | {debug f90}]} { | |
25 | return -1 | |
26 | } | |
27 | ||
c8ed8c8a TV |
28 | # Avoid shared lib symbols. |
29 | gdb_test_no_output "set auto-solib-add off" | |
30 | ||
a5c641b5 | 31 | if ![fortran_runto_main] { |
a5c641b5 AB |
32 | return -1 |
33 | } | |
34 | ||
c8ed8c8a TV |
35 | # Avoid libc symbols, in particular the 'array' type. |
36 | gdb_test_no_output "nosharedlibrary" | |
37 | ||
a5c641b5 AB |
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"] | |
41 | ||
42 | # We're going to print some reasonably large arrays. | |
43 | gdb_test_no_output "set print elements unlimited" | |
44 | ||
45 | gdb_continue_to_breakpoint "Stop Here" | |
46 | ||
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)" | |
52 | } | |
53 | } | |
54 | ||
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" | |
61 | } | |
62 | } | |
63 | ||
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\\)\\)" | |
67 | ||
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 | |
74 | } | |
75 | } | |
76 | ||
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 | |
83 | } | |
84 | } | |
85 | ||
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 | |
92 | } | |
93 | } | |
94 | ||
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'" | |
102 | ||
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. | |
106 | # | |
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\\)\\)" |