* gdb.arch/altivec-abi.exp: Replace gdb_suppress_entire_file with
[external/binutils.git] / gdb / testsuite / gdb.cp / misc.exp
1 # Copyright 1992, 1994, 1995, 1996, 1997, 1999, 2002 Free Software
2 # Foundation, Inc.
3
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
8
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  
17
18 # This file was written by Fred Fish. (fnf@cygnus.com)
19
20 if $tracelevel then {
21         strace $tracelevel
22 }
23
24 if { [skip_cplus_tests] } { continue }
25
26 set testfile "misc"
27 set srcfile ${testfile}.cc
28 set binfile ${objdir}/${subdir}/${testfile}
29 if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
30      untested misc.exp
31      return -1
32 }
33
34 #
35 # Deduce language of main()
36 #
37
38 proc deduce_language_of_main {} {
39     global gdb_prompt
40
41     # See what language gdb thinks main() is, prior to reading full symbols.
42     # I think this fails for COFF targets.
43     send_gdb "show language\n"
44     gdb_expect {
45         -re ".* source language is \"auto; currently c\[+\]+\".*$gdb_prompt $" {
46             pass "deduced language is C++, before full symbols"
47         }
48         -re ".*$gdb_prompt $" {
49             fail "source language not correct for C++ (psymtabs only)"
50             return
51         }
52         timeout {
53             fail "can't show language (timeout)"
54             return
55         }
56     }
57
58     runto_main
59
60     # See if our idea of the language has changed.
61
62     send_gdb "show language\n"
63     gdb_expect {
64         -re ".* source language is \"auto; currently c\[+\]+\".*$gdb_prompt $" {
65             pass "deduced language is C++, after full symbols"
66         }
67         -re ".*$gdb_prompt $" {
68             fail "source language not correct for C++ (full symbols)"
69             return
70         }
71         timeout {
72             fail "can't show language (timeout)"
73             return
74         }
75     }
76 }
77
78 proc test_expr { args } {
79     if { [llength $args] % 2 } {
80         warning "an even # of arguments should be passed to test_expr"
81     }
82     set last_ent [expr [llength $args] - 1];
83     set testname [lindex $args $last_ent];
84     if [gdb_test [lindex $args 0] "" "$testname (setup)"] {
85         gdb_suppress_tests;
86     }
87     for {set x 1} {$x < $last_ent} {set x [expr $x + 2]} {
88         if [gdb_test [lindex $args $x] [lindex $args [expr $x + 1]] "$testname ([lindex $args $x])"] {
89             gdb_suppress_tests;
90         }
91     }
92     gdb_stop_suppressing_tests;
93 }
94
95 proc do_tests {} {
96     global prms_id
97     global bug_id
98     global subdir
99     global objdir
100     global srcdir
101     global binfile
102     global gdb_prompt
103
104     set prms_id 0
105     set bug_id 0
106
107     # Start with a fresh gdb.
108
109     gdb_exit
110     gdb_start
111     gdb_reinitialize_dir $srcdir/$subdir
112     gdb_load $binfile
113
114     deduce_language_of_main
115     # Check for fixes for PRs 8916 and 8630
116     gdb_test "print s.a" ".* = 0" "print s.a for foo struct (known gcc 2.7.2 and earlier bug)"
117 }
118
119 do_tests
120
121 test_expr "set language c++" \
122     "print 1 == 1" "print.*\\$\[0-9\]* = true" \
123     "print 1 == 2" "print.*\\$\[0-9\]* = false" \
124     "print as bool"
125
126 # Test bool type printing, etc.
127 # Note: Language is already set to C++ above! 
128 gdb_test "print v_bool" "\\$\[0-9\]* = false" "print a bool var"
129
130 # set a bool variable
131 test_expr "set variable v_bool = true" \
132     "print v_bool" "\\$\[0-9\]* = true" \
133     "set a bool var"
134
135 # next print an array of bool
136 gdb_test "print v_bool_array" "\\$\[0-9\]* = \\{false, false\\}" "print a bool array"
137
138 # set elements of a bool array
139 test_expr "set variable v_bool_array\[1\] = true" \
140     "print v_bool_array" "\\$\[0-9\]* = \\{false, true\\}" \
141     "set a bool array elem"
142
143 # bool constants
144 gdb_test "print true" "\\$\[0-9\]* = true" "print true"
145 gdb_test "print false" "\\$\[0-9\]* = false" "print false"
146
147 # arithmetic conversions
148 gdb_test "print 1 + true" "\\$\[0-9\]* = 2" "1 + true"
149 gdb_test "print 3 + false" "\\$\[0-9\]* = 3" "3 + false"
150 gdb_test "print 1 < 2 < 3" "\\$\[0-9\]* = true" "1 < 2 < 3"
151 gdb_test "print 2 < 1 > 4" "\\$\[0-9\]* = false" "2 < 1 > 4"
152 gdb_test "print (bool)43" "\\$\[0-9\]* = true" "(bool)43"
153 gdb_test "print (bool)0" "\\$\[0-9\]* = false" "(bool)0"
154 gdb_test "print (bool)17.93" "\\$\[0-9\]* = true" "(bool)17.93"
155 gdb_test "print (bool)0.0" "\\$\[0-9\]* = false" "(bool)0.0"
156 gdb_test "print (int)true" "\\$\[0-9\]* = 1" "(int)true"
157 gdb_test "print (int)false" "\\$\[0-9\]* = 0" "(int)false"