Commit | Line | Data |
---|---|---|
9b254dd1 | 1 | # Copyright 1992, 1994, 1995, 1996, 1997, 1999, 2002, 2007, 2008 |
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 | ||
19 | if $tracelevel then { | |
20 | strace $tracelevel | |
21 | } | |
22 | ||
d4f3574e | 23 | if { [skip_cplus_tests] } { continue } |
c906108c SS |
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++}] != "" } { | |
b60f0898 JB |
29 | untested misc.exp |
30 | return -1 | |
c906108c SS |
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. | |
c906108c SS |
42 | send_gdb "show language\n" |
43 | gdb_expect { | |
44 | -re ".* source language is \"auto; currently c\[+\]+\".*$gdb_prompt $" { | |
45 | pass "deduced language is C++, before full symbols" | |
46 | } | |
47 | -re ".*$gdb_prompt $" { | |
48 | fail "source language not correct for C++ (psymtabs only)" | |
49 | return | |
50 | } | |
51 | timeout { | |
52 | fail "can't show language (timeout)" | |
53 | return | |
54 | } | |
55 | } | |
56 | ||
57 | runto_main | |
58 | ||
59 | # See if our idea of the language has changed. | |
60 | ||
61 | send_gdb "show language\n" | |
62 | gdb_expect { | |
63 | -re ".* source language is \"auto; currently c\[+\]+\".*$gdb_prompt $" { | |
64 | pass "deduced language is C++, after full symbols" | |
65 | } | |
66 | -re ".*$gdb_prompt $" { | |
67 | fail "source language not correct for C++ (full symbols)" | |
68 | return | |
69 | } | |
70 | timeout { | |
71 | fail "can't show language (timeout)" | |
72 | return | |
73 | } | |
74 | } | |
75 | } | |
76 | ||
a0b3c4fd JM |
77 | proc test_expr { args } { |
78 | if { [llength $args] % 2 } { | |
79 | warning "an even # of arguments should be passed to test_expr" | |
80 | } | |
81 | set last_ent [expr [llength $args] - 1]; | |
82 | set testname [lindex $args $last_ent]; | |
83 | if [gdb_test [lindex $args 0] "" "$testname (setup)"] { | |
84 | gdb_suppress_tests; | |
85 | } | |
86 | for {set x 1} {$x < $last_ent} {set x [expr $x + 2]} { | |
87 | if [gdb_test [lindex $args $x] [lindex $args [expr $x + 1]] "$testname ([lindex $args $x])"] { | |
88 | gdb_suppress_tests; | |
89 | } | |
90 | } | |
91 | gdb_stop_suppressing_tests; | |
92 | } | |
93 | ||
c906108c SS |
94 | proc do_tests {} { |
95 | global prms_id | |
96 | global bug_id | |
97 | global subdir | |
98 | global objdir | |
99 | global srcdir | |
100 | global binfile | |
101 | global gdb_prompt | |
102 | ||
103 | set prms_id 0 | |
104 | set bug_id 0 | |
105 | ||
106 | # Start with a fresh gdb. | |
107 | ||
108 | gdb_exit | |
109 | gdb_start | |
110 | gdb_reinitialize_dir $srcdir/$subdir | |
111 | gdb_load $binfile | |
112 | ||
113 | deduce_language_of_main | |
114 | # Check for fixes for PRs 8916 and 8630 | |
115 | gdb_test "print s.a" ".* = 0" "print s.a for foo struct (known gcc 2.7.2 and earlier bug)" | |
116 | } | |
117 | ||
118 | do_tests | |
a0b3c4fd JM |
119 | |
120 | test_expr "set language c++" \ | |
121 | "print 1 == 1" "print.*\\$\[0-9\]* = true" \ | |
122 | "print 1 == 2" "print.*\\$\[0-9\]* = false" \ | |
123 | "print as bool" | |
124 | ||
125 | # Test bool type printing, etc. | |
126 | # Note: Language is already set to C++ above! | |
127 | gdb_test "print v_bool" "\\$\[0-9\]* = false" "print a bool var" | |
128 | ||
129 | # set a bool variable | |
130 | test_expr "set variable v_bool = true" \ | |
131 | "print v_bool" "\\$\[0-9\]* = true" \ | |
132 | "set a bool var" | |
133 | ||
134 | # next print an array of bool | |
135 | gdb_test "print v_bool_array" "\\$\[0-9\]* = \\{false, false\\}" "print a bool array" | |
136 | ||
137 | # set elements of a bool array | |
138 | test_expr "set variable v_bool_array\[1\] = true" \ | |
139 | "print v_bool_array" "\\$\[0-9\]* = \\{false, true\\}" \ | |
140 | "set a bool array elem" | |
141 | ||
142 | # bool constants | |
143 | gdb_test "print true" "\\$\[0-9\]* = true" "print true" | |
144 | gdb_test "print false" "\\$\[0-9\]* = false" "print false" | |
145 | ||
146 | # arithmetic conversions | |
147 | gdb_test "print 1 + true" "\\$\[0-9\]* = 2" "1 + true" | |
148 | gdb_test "print 3 + false" "\\$\[0-9\]* = 3" "3 + false" | |
149 | gdb_test "print 1 < 2 < 3" "\\$\[0-9\]* = true" "1 < 2 < 3" | |
150 | gdb_test "print 2 < 1 > 4" "\\$\[0-9\]* = false" "2 < 1 > 4" | |
151 | gdb_test "print (bool)43" "\\$\[0-9\]* = true" "(bool)43" | |
152 | gdb_test "print (bool)0" "\\$\[0-9\]* = false" "(bool)0" | |
153 | gdb_test "print (bool)17.93" "\\$\[0-9\]* = true" "(bool)17.93" | |
154 | gdb_test "print (bool)0.0" "\\$\[0-9\]* = false" "(bool)0.0" | |
155 | gdb_test "print (int)true" "\\$\[0-9\]* = 1" "(int)true" | |
156 | gdb_test "print (int)false" "\\$\[0-9\]* = 0" "(int)false" |