xref: /netbsd-src/external/gpl3/gdb.old/dist/gdb/testsuite/gdb.ada/operator_call.exp (revision c9055873d0546e63388f027d3d7f85381cde0545)
1# Copyright 2021-2023 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
16load_lib "ada.exp"
17
18if { [skip_ada_tests] } { return -1 }
19
20standard_ada_testfile opcall
21
22if {[gdb_compile_ada "${srcfile}" "${binfile}" executable {debug}] != ""} {
23    return -1
24}
25
26clean_restart ${testfile}
27
28set bp_location [gdb_get_line_number "STOP" ${testdir}/opcall.adb]
29runto "opcall.adb:$bp_location"
30
31gdb_test "print p" " = \\(x => 4, y => 5\\)"
32
33proc test_with_menu {command result} {
34    global expect_out
35
36    set rxcmd [string_to_regexp $command]
37
38    set num {}
39    send_gdb "$command\n"
40    gdb_expect 30 {
41	-re "^$rxcmd\r\n" {
42	    exp_continue
43	}
44	-re "Multiple matches for \[^\r\n\]*\r\n" {
45	    exp_continue
46	}
47	-re "^\\\[(\[0-9\]+)\\\] twovecs\\.*\[^\r\n\]*\r\n" {
48	    set num $expect_out(1,string)
49	    exp_continue
50	}
51	-re "^\\\[\[0-9\]+\\\] \[^\r\n\]*\r\n" {
52	    # Any other match, we don't want.
53	    exp_continue
54	}
55	-re "^> " {
56	    if {$num == ""} {
57		fail $command
58		set num 0
59	    }
60	    send_gdb "$num\n"
61	    exp_continue
62	}
63	-re "^\[0-9\]+\r\n" {
64	    # The number we just sent, ignore.
65	    exp_continue
66	}
67	-re "\\\$\[0-9\]+ = (\[^\r\n\]+)\r\n" {
68	    if {[regexp $result $expect_out(1,string)]} {
69		pass $command
70	    } else {
71		fail $command
72	    }
73	}
74	timeout {
75	    fail "$command (timeout)"
76	}
77    }
78}
79
80test_with_menu "print p + p" "\\(x => 8, y => 10\\)"
81test_with_menu "print p - p" "\\(x => 0, y => 0\\)"
82test_with_menu "print p * p" "\\(x => 16, y => 25\\)"
83test_with_menu "print p / p" "\\(x => 1, y => 1\\)"
84
85# See the code to understand the weird numbers here.
86test_with_menu "print p mod p" "\\(x => 17, y => 18\\)"
87test_with_menu "print p rem p" "\\(x => 38, y => 39\\)"
88test_with_menu "print p ** p" "\\(x => 84, y => 105\\)"
89
90test_with_menu "print p < p" "false"
91test_with_menu "print p < p2" "true"
92test_with_menu "print p <= p" "true"
93test_with_menu "print p <= p2" "true"
94test_with_menu "print p > p" "false"
95test_with_menu "print p2 > p" "true"
96test_with_menu "print p >= p" "true"
97test_with_menu "print p2 >= p" "true"
98test_with_menu "print p = p" "true"
99test_with_menu "print p = p2" "false"
100test_with_menu "print p /= p" "false"
101test_with_menu "print p /= p2" "true"
102
103test_with_menu "print p and p2" "\\(x => 4, y => 4\\)"
104test_with_menu "print p or p2" "\\(x => 12, y => 13\\)"
105test_with_menu "print p xor p2" "\\(x => 8, y => 9\\)"
106
107# See the code to understand the weird numbers here.
108test_with_menu "print p & p" "\\(x => 44, y => 55\\)"
109
110test_with_menu "print -p" "\\(x => 65532, y => 65531\\)"
111test_with_menu "print abs(-p)" "\\(x => 65532, y => 65531\\)"
112test_with_menu "print not(p)" "\\(x => 65531, y => 65530\\)"
113
114# See the code to understand the weird numbers here.
115test_with_menu "print +(p)" "\\(x => 5, y => 4\\)"
116