Commit | Line | Data |
---|---|---|
0b302171 JB |
1 | # Copyright 1992, 1994-1997, 1999, 2002, 2007-2012 Free Software |
2 | # 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 | ||
d4f3574e | 19 | if { [skip_cplus_tests] } { continue } |
c906108c SS |
20 | |
21 | set testfile "misc" | |
22 | set srcfile ${testfile}.cc | |
23 | set binfile ${objdir}/${subdir}/${testfile} | |
24 | if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } { | |
b60f0898 JB |
25 | untested misc.exp |
26 | return -1 | |
c906108c SS |
27 | } |
28 | ||
29 | # | |
30 | # Deduce language of main() | |
31 | # | |
32 | ||
33 | proc deduce_language_of_main {} { | |
34 | global gdb_prompt | |
35 | ||
36 | # See what language gdb thinks main() is, prior to reading full symbols. | |
37 | # I think this fails for COFF targets. | |
f8d3bf8f MS |
38 | gdb_test "show language" \ |
39 | "source language is \"auto; currently c\[+\]+\".*" \ | |
40 | "deduced language is C++, before full symbols" | |
c906108c SS |
41 | |
42 | runto_main | |
43 | ||
44 | # See if our idea of the language has changed. | |
45 | ||
f8d3bf8f MS |
46 | gdb_test "show language" \ |
47 | "source language is \"auto; currently c\[+\]+\".*" \ | |
48 | "deduced language is C++, after full symbols" | |
c906108c SS |
49 | } |
50 | ||
a0b3c4fd JM |
51 | proc test_expr { args } { |
52 | if { [llength $args] % 2 } { | |
53 | warning "an even # of arguments should be passed to test_expr" | |
54 | } | |
55 | set last_ent [expr [llength $args] - 1]; | |
56 | set testname [lindex $args $last_ent]; | |
a8d52276 | 57 | if [gdb_test_no_output [lindex $args 0] "$testname (setup)"] { |
a0b3c4fd JM |
58 | gdb_suppress_tests; |
59 | } | |
60 | for {set x 1} {$x < $last_ent} {set x [expr $x + 2]} { | |
61 | if [gdb_test [lindex $args $x] [lindex $args [expr $x + 1]] "$testname ([lindex $args $x])"] { | |
62 | gdb_suppress_tests; | |
63 | } | |
64 | } | |
65 | gdb_stop_suppressing_tests; | |
66 | } | |
67 | ||
c906108c | 68 | proc do_tests {} { |
c906108c SS |
69 | global subdir |
70 | global objdir | |
71 | global srcdir | |
72 | global binfile | |
73 | global gdb_prompt | |
74 | ||
c906108c SS |
75 | |
76 | # Start with a fresh gdb. | |
77 | ||
78 | gdb_exit | |
79 | gdb_start | |
80 | gdb_reinitialize_dir $srcdir/$subdir | |
81 | gdb_load $binfile | |
82 | ||
83 | deduce_language_of_main | |
84 | # Check for fixes for PRs 8916 and 8630 | |
85 | gdb_test "print s.a" ".* = 0" "print s.a for foo struct (known gcc 2.7.2 and earlier bug)" | |
86 | } | |
87 | ||
88 | do_tests | |
a0b3c4fd JM |
89 | |
90 | test_expr "set language c++" \ | |
91 | "print 1 == 1" "print.*\\$\[0-9\]* = true" \ | |
92 | "print 1 == 2" "print.*\\$\[0-9\]* = false" \ | |
93 | "print as bool" | |
94 | ||
95 | # Test bool type printing, etc. | |
96 | # Note: Language is already set to C++ above! | |
97 | gdb_test "print v_bool" "\\$\[0-9\]* = false" "print a bool var" | |
98 | ||
99 | # set a bool variable | |
100 | test_expr "set variable v_bool = true" \ | |
101 | "print v_bool" "\\$\[0-9\]* = true" \ | |
102 | "set a bool var" | |
103 | ||
104 | # next print an array of bool | |
105 | gdb_test "print v_bool_array" "\\$\[0-9\]* = \\{false, false\\}" "print a bool array" | |
106 | ||
107 | # set elements of a bool array | |
108 | test_expr "set variable v_bool_array\[1\] = true" \ | |
109 | "print v_bool_array" "\\$\[0-9\]* = \\{false, true\\}" \ | |
110 | "set a bool array elem" | |
111 | ||
112 | # bool constants | |
113 | gdb_test "print true" "\\$\[0-9\]* = true" "print true" | |
114 | gdb_test "print false" "\\$\[0-9\]* = false" "print false" | |
115 | ||
116 | # arithmetic conversions | |
117 | gdb_test "print 1 + true" "\\$\[0-9\]* = 2" "1 + true" | |
118 | gdb_test "print 3 + false" "\\$\[0-9\]* = 3" "3 + false" | |
119 | gdb_test "print 1 < 2 < 3" "\\$\[0-9\]* = true" "1 < 2 < 3" | |
120 | gdb_test "print 2 < 1 > 4" "\\$\[0-9\]* = false" "2 < 1 > 4" | |
121 | gdb_test "print (bool)43" "\\$\[0-9\]* = true" "(bool)43" | |
122 | gdb_test "print (bool)0" "\\$\[0-9\]* = false" "(bool)0" | |
123 | gdb_test "print (bool)17.93" "\\$\[0-9\]* = true" "(bool)17.93" | |
124 | gdb_test "print (bool)0.0" "\\$\[0-9\]* = false" "(bool)0.0" | |
125 | gdb_test "print (int)true" "\\$\[0-9\]* = 1" "(int)true" | |
126 | gdb_test "print (int)false" "\\$\[0-9\]* = 0" "(int)false" |