1 # Copyright 1992, 1994-1997, 1999, 2002, 2007-2012 Free Software
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 3 of the License, or
7 # (at your option) any later version.
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.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 # This file was written by Fred Fish. (fnf@cygnus.com)
23 if { [skip_cplus_tests] } { continue }
26 set srcfile ${testfile}.cc
27 set binfile ${objdir}/${subdir}/${testfile}
28 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
34 # Deduce language of main()
37 proc deduce_language_of_main {} {
40 # See what language gdb thinks main() is, prior to reading full symbols.
41 # I think this fails for COFF targets.
42 gdb_test "show language" \
43 "source language is \"auto; currently c\[+\]+\".*" \
44 "deduced language is C++, before full symbols"
48 # See if our idea of the language has changed.
50 gdb_test "show language" \
51 "source language is \"auto; currently c\[+\]+\".*" \
52 "deduced language is C++, after full symbols"
55 proc test_expr { args } {
56 if { [llength $args] % 2 } {
57 warning "an even # of arguments should be passed to test_expr"
59 set last_ent [expr [llength $args] - 1];
60 set testname [lindex $args $last_ent];
61 if [gdb_test_no_output [lindex $args 0] "$testname (setup)"] {
64 for {set x 1} {$x < $last_ent} {set x [expr $x + 2]} {
65 if [gdb_test [lindex $args $x] [lindex $args [expr $x + 1]] "$testname ([lindex $args $x])"] {
69 gdb_stop_suppressing_tests;
80 # Start with a fresh gdb.
84 gdb_reinitialize_dir $srcdir/$subdir
87 deduce_language_of_main
88 # Check for fixes for PRs 8916 and 8630
89 gdb_test "print s.a" ".* = 0" "print s.a for foo struct (known gcc 2.7.2 and earlier bug)"
94 test_expr "set language c++" \
95 "print 1 == 1" "print.*\\$\[0-9\]* = true" \
96 "print 1 == 2" "print.*\\$\[0-9\]* = false" \
99 # Test bool type printing, etc.
100 # Note: Language is already set to C++ above!
101 gdb_test "print v_bool" "\\$\[0-9\]* = false" "print a bool var"
103 # set a bool variable
104 test_expr "set variable v_bool = true" \
105 "print v_bool" "\\$\[0-9\]* = true" \
108 # next print an array of bool
109 gdb_test "print v_bool_array" "\\$\[0-9\]* = \\{false, false\\}" "print a bool array"
111 # set elements of a bool array
112 test_expr "set variable v_bool_array\[1\] = true" \
113 "print v_bool_array" "\\$\[0-9\]* = \\{false, true\\}" \
114 "set a bool array elem"
117 gdb_test "print true" "\\$\[0-9\]* = true" "print true"
118 gdb_test "print false" "\\$\[0-9\]* = false" "print false"
120 # arithmetic conversions
121 gdb_test "print 1 + true" "\\$\[0-9\]* = 2" "1 + true"
122 gdb_test "print 3 + false" "\\$\[0-9\]* = 3" "3 + false"
123 gdb_test "print 1 < 2 < 3" "\\$\[0-9\]* = true" "1 < 2 < 3"
124 gdb_test "print 2 < 1 > 4" "\\$\[0-9\]* = false" "2 < 1 > 4"
125 gdb_test "print (bool)43" "\\$\[0-9\]* = true" "(bool)43"
126 gdb_test "print (bool)0" "\\$\[0-9\]* = false" "(bool)0"
127 gdb_test "print (bool)17.93" "\\$\[0-9\]* = true" "(bool)17.93"
128 gdb_test "print (bool)0.0" "\\$\[0-9\]* = false" "(bool)0.0"
129 gdb_test "print (int)true" "\\$\[0-9\]* = 1" "(int)true"
130 gdb_test "print (int)false" "\\$\[0-9\]* = 0" "(int)false"