2010-05-25 Michael Snyder <msnyder@vmware.com>
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.cp / misc.exp
1 # Copyright 1992, 1994, 1995, 1996, 1997, 1999, 2002, 2007, 2008, 2009, 2010
2 # Free Software 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 3 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, see <http://www.gnu.org/licenses/>.
16
17 # This file was written by Fred Fish. (fnf@cygnus.com)
18
19 if $tracelevel then {
20 strace $tracelevel
21 }
22
23 if { [skip_cplus_tests] } { continue }
24
25 set testfile "misc"
26 set srcfile ${testfile}.cc
27 set binfile ${objdir}/${subdir}/${testfile}
28 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
29 untested misc.exp
30 return -1
31 }
32
33 #
34 # Deduce language of main()
35 #
36
37 proc 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.
42 gdb_test "show language" \
43 "source language is \"auto; currently c\[+\]+\".*" \
44 "deduced language is C++, before full symbols"
45
46 runto_main
47
48 # See if our idea of the language has changed.
49
50 gdb_test "show language" \
51 "source language is \"auto; currently c\[+\]+\".*" \
52 "deduced language is C++, after full symbols"
53 }
54
55 proc 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
72 proc do_tests {} {
73 global subdir
74 global objdir
75 global srcdir
76 global binfile
77 global gdb_prompt
78
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
92 do_tests
93
94 test_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!
101 gdb_test "print v_bool" "\\$\[0-9\]* = false" "print a bool var"
102
103 # set a bool variable
104 test_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
109 gdb_test "print v_bool_array" "\\$\[0-9\]* = \\{false, false\\}" "print a bool array"
110
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"
115
116 # bool constants
117 gdb_test "print true" "\\$\[0-9\]* = true" "print true"
118 gdb_test "print false" "\\$\[0-9\]* = false" "print false"
119
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"
This page took 0.033546 seconds and 5 git commands to generate.