2010-06-02 Michael Snyder <msnyder@msnyder-server.eng.vmware.com>
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.cp / misc.exp
CommitLineData
4c38e0a4 1# Copyright 1992, 1994, 1995, 1996, 1997, 1999, 2002, 2007, 2008, 2009, 2010
6aba47ca 2# Free Software Foundation, Inc.
c906108c
SS
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
e22f8b7c 6# the Free Software Foundation; either version 3 of the License, or
c906108c 7# (at your option) any later version.
e22f8b7c 8#
c906108c
SS
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.
e22f8b7c 13#
c906108c 14# You should have received a copy of the GNU General Public License
e22f8b7c 15# along with this program. If not, see <http://www.gnu.org/licenses/>.
c906108c 16
c906108c
SS
17# This file was written by Fred Fish. (fnf@cygnus.com)
18
19if $tracelevel then {
20 strace $tracelevel
21}
22
d4f3574e 23if { [skip_cplus_tests] } { continue }
c906108c
SS
24
25set testfile "misc"
26set srcfile ${testfile}.cc
27set binfile ${objdir}/${subdir}/${testfile}
28if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
b60f0898
JB
29 untested misc.exp
30 return -1
c906108c
SS
31}
32
33#
34# Deduce language of main()
35#
36
37proc deduce_language_of_main {} {
38 global gdb_prompt
39
40 # See what language gdb thinks main() is, prior to reading full symbols.
41 # I think this fails for COFF targets.
f8d3bf8f
MS
42 gdb_test "show language" \
43 "source language is \"auto; currently c\[+\]+\".*" \
44 "deduced language is C++, before full symbols"
c906108c
SS
45
46 runto_main
47
48 # See if our idea of the language has changed.
49
f8d3bf8f
MS
50 gdb_test "show language" \
51 "source language is \"auto; currently c\[+\]+\".*" \
52 "deduced language is C++, after full symbols"
c906108c
SS
53}
54
a0b3c4fd
JM
55proc test_expr { args } {
56 if { [llength $args] % 2 } {
57 warning "an even # of arguments should be passed to test_expr"
58 }
59 set last_ent [expr [llength $args] - 1];
60 set testname [lindex $args $last_ent];
61 if [gdb_test [lindex $args 0] "" "$testname (setup)"] {
62 gdb_suppress_tests;
63 }
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])"] {
66 gdb_suppress_tests;
67 }
68 }
69 gdb_stop_suppressing_tests;
70}
71
c906108c 72proc do_tests {} {
c906108c
SS
73 global subdir
74 global objdir
75 global srcdir
76 global binfile
77 global gdb_prompt
78
c906108c
SS
79
80 # Start with a fresh gdb.
81
82 gdb_exit
83 gdb_start
84 gdb_reinitialize_dir $srcdir/$subdir
85 gdb_load $binfile
86
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)"
90}
91
92do_tests
a0b3c4fd
JM
93
94test_expr "set language c++" \
95 "print 1 == 1" "print.*\\$\[0-9\]* = true" \
96 "print 1 == 2" "print.*\\$\[0-9\]* = false" \
97 "print as bool"
98
99# Test bool type printing, etc.
100# Note: Language is already set to C++ above!
101gdb_test "print v_bool" "\\$\[0-9\]* = false" "print a bool var"
102
103# set a bool variable
104test_expr "set variable v_bool = true" \
105 "print v_bool" "\\$\[0-9\]* = true" \
106 "set a bool var"
107
108# next print an array of bool
109gdb_test "print v_bool_array" "\\$\[0-9\]* = \\{false, false\\}" "print a bool array"
110
111# set elements of a bool array
112test_expr "set variable v_bool_array\[1\] = true" \
113 "print v_bool_array" "\\$\[0-9\]* = \\{false, true\\}" \
114 "set a bool array elem"
115
116# bool constants
117gdb_test "print true" "\\$\[0-9\]* = true" "print true"
118gdb_test "print false" "\\$\[0-9\]* = false" "print false"
119
120# arithmetic conversions
121gdb_test "print 1 + true" "\\$\[0-9\]* = 2" "1 + true"
122gdb_test "print 3 + false" "\\$\[0-9\]* = 3" "3 + false"
123gdb_test "print 1 < 2 < 3" "\\$\[0-9\]* = true" "1 < 2 < 3"
124gdb_test "print 2 < 1 > 4" "\\$\[0-9\]* = false" "2 < 1 > 4"
125gdb_test "print (bool)43" "\\$\[0-9\]* = true" "(bool)43"
126gdb_test "print (bool)0" "\\$\[0-9\]* = false" "(bool)0"
127gdb_test "print (bool)17.93" "\\$\[0-9\]* = true" "(bool)17.93"
128gdb_test "print (bool)0.0" "\\$\[0-9\]* = false" "(bool)0.0"
129gdb_test "print (int)true" "\\$\[0-9\]* = 1" "(int)true"
130gdb_test "print (int)false" "\\$\[0-9\]* = 0" "(int)false"
This page took 0.952349 seconds and 4 git commands to generate.