Add translations for various sub-directories
[binutils-gdb.git] / gdb / testsuite / gdb.ada / array_of_variant.exp
blob8b83f4ed22adbc0bb06162348b7ba2e9fc6f2c51
1 # Copyright 2020-2024 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 load_lib "ada.exp"
17 load_lib "gdb-python.exp"
19 require allow_ada_tests
21 standard_ada_testfile p
23 set old_gcc [gnat_version_compare <= 7]
25 proc gdb_test_with_xfail { cmd re re_xfail msg } {
26     global scenario old_gcc
27     set have_xfail [expr $old_gcc && [string equal "$scenario" "minimal"]]
29     gdb_test_multiple $cmd $msg {
30         -re -wrap $re  {
31             pass $gdb_test_name
32         }
33         -re -wrap $re_xfail {
34             if { $have_xfail } {
35                 # gcc/101633
36                 setup_xfail *-*-*
37             }
38             fail $gdb_test_name
39         }
40     }
43 foreach_gnat_encoding scenario flags {all minimal} {
44     lappend flags debug
46     if {[gdb_compile_ada "${srcfile}" "${binfile}-${scenario}" executable $flags] != ""} {
47         return -1
48     }
50     clean_restart ${testfile}-${scenario}
52     set bp_location [gdb_get_line_number "START" ${testdir}/p.adb]
53     runto "p.adb:$bp_location"
55     set v1 "(tag => object, values => (2, 2, 2, 2, 2))"
56     set v1_xfail "(tag => object, values => ())"
57     set v2 "(tag => unused)"
59     set re [string_to_regexp " = ($v1, $v2)"]
60     set re_xfail [string_to_regexp " = ($v1_xfail, $v2)"]
61     gdb_test_with_xfail "print objects" $re $re_xfail "print entire array"
63     set re [string_to_regexp " = $v1"]
64     set re_xfail [string_to_regexp " = $v1_xfail"]
65     gdb_test_with_xfail "print objects(1)" $re $re_xfail \
66         "print first array element"
68     set re [string_to_regexp " = ($v1)"]
69     set re_xfail [string_to_regexp " = ($v1_xfail)"]
70     gdb_test_with_xfail "print objects(1 .. 1)" $re $re_xfail \
71         "print first array slice"
73     gdb_test "print objects(2)" \
74         [string_to_regexp " = $v2"] \
75         "print second array element"
76     gdb_test "print objects(2 .. 2)" \
77         [string_to_regexp " = (2 => $v2)"] \
78         "print second array slice"
80     # This is only supported for the DWARF encoding.
81     if {$scenario == "minimal" && [allow_python_tests]} {
82         gdb_test_no_output \
83             "python o = gdb.parse_and_eval('objects')" \
84             "fetch value for python"
85         set re [string_to_regexp "($v1, $v2)"]
86         set re_xfail [string_to_regexp "($v1_xfail, $v2)"]
87         gdb_test_with_xfail "python print(o)" $re $re_xfail \
88             "python print array"
89         set re [string_to_regexp "$v1"]
90         set re_xfail [string_to_regexp "$v1_xfail"]
91         gdb_test_with_xfail "python print(o\[1\])" $re $re_xfail \
92             "python print first array element"
93         gdb_test "python print(o\[2\])" \
94             [string_to_regexp "$v2"] \
95             "python print second array element"
96     }
98     set av1 "(initial => 0, rest => (tag => unused, cval => 88 'X'))"
99     set av2 "(initial => 0, rest => (tag => object, ival => 88))"
100     set full "($av1, $av2)"
102     gdb_test "print another_array(1)" " = [string_to_regexp $av1]" \
103         "print first element of another_array"
104     gdb_test "print another_array(2)" " = [string_to_regexp $av2]" \
105         "print second element of another_array"
106     gdb_test "print another_array" " = [string_to_regexp $full]" \
107         "print another_array"