Commit | Line | Data |
---|---|---|
e2882c85 | 1 | # Copyright 1992-2018 Free Software Foundation, Inc. |
c906108c SS |
2 | |
3 | # This program is free software; you can redistribute it and/or modify | |
4 | # it under the terms of the GNU General Public License as published by | |
e22f8b7c | 5 | # the Free Software Foundation; either version 3 of the License, or |
c906108c | 6 | # (at your option) any later version. |
e22f8b7c | 7 | # |
c906108c SS |
8 | # This program is distributed in the hope that it will be useful, |
9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 | # GNU General Public License for more details. | |
e22f8b7c | 12 | # |
c906108c | 13 | # You should have received a copy of the GNU General Public License |
e22f8b7c | 14 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
c906108c | 15 | |
c906108c SS |
16 | # This file was written by Fred Fish. (fnf@cygnus.com) |
17 | ||
d4f3574e | 18 | if { [skip_cplus_tests] } { continue } |
c906108c | 19 | |
f5f3a911 TT |
20 | standard_testfile .cc |
21 | ||
5b362f04 | 22 | if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug c++}]} { |
f5f3a911 | 23 | return -1 |
c906108c SS |
24 | } |
25 | ||
26 | # | |
27 | # Deduce language of main() | |
28 | # | |
29 | ||
30 | proc deduce_language_of_main {} { | |
31 | global gdb_prompt | |
32 | ||
33 | # See what language gdb thinks main() is, prior to reading full symbols. | |
34 | # I think this fails for COFF targets. | |
f8d3bf8f MS |
35 | gdb_test "show language" \ |
36 | "source language is \"auto; currently c\[+\]+\".*" \ | |
37 | "deduced language is C++, before full symbols" | |
c906108c SS |
38 | |
39 | runto_main | |
40 | ||
41 | # See if our idea of the language has changed. | |
42 | ||
f8d3bf8f MS |
43 | gdb_test "show language" \ |
44 | "source language is \"auto; currently c\[+\]+\".*" \ | |
45 | "deduced language is C++, after full symbols" | |
c906108c SS |
46 | } |
47 | ||
a0b3c4fd JM |
48 | proc test_expr { args } { |
49 | if { [llength $args] % 2 } { | |
50 | warning "an even # of arguments should be passed to test_expr" | |
51 | } | |
4ec70201 PA |
52 | set last_ent [expr [llength $args] - 1] |
53 | set testname [lindex $args $last_ent] | |
a8d52276 | 54 | if [gdb_test_no_output [lindex $args 0] "$testname (setup)"] { |
4ec70201 | 55 | gdb_suppress_tests |
a0b3c4fd JM |
56 | } |
57 | for {set x 1} {$x < $last_ent} {set x [expr $x + 2]} { | |
58 | if [gdb_test [lindex $args $x] [lindex $args [expr $x + 1]] "$testname ([lindex $args $x])"] { | |
4ec70201 | 59 | gdb_suppress_tests |
a0b3c4fd JM |
60 | } |
61 | } | |
4ec70201 | 62 | gdb_stop_suppressing_tests |
a0b3c4fd JM |
63 | } |
64 | ||
c906108c | 65 | proc do_tests {} { |
c906108c SS |
66 | deduce_language_of_main |
67 | # Check for fixes for PRs 8916 and 8630 | |
68 | gdb_test "print s.a" ".* = 0" "print s.a for foo struct (known gcc 2.7.2 and earlier bug)" | |
69 | } | |
70 | ||
71 | do_tests | |
a0b3c4fd JM |
72 | |
73 | test_expr "set language c++" \ | |
74 | "print 1 == 1" "print.*\\$\[0-9\]* = true" \ | |
75 | "print 1 == 2" "print.*\\$\[0-9\]* = false" \ | |
76 | "print as bool" | |
77 | ||
78 | # Test bool type printing, etc. | |
79 | # Note: Language is already set to C++ above! | |
80 | gdb_test "print v_bool" "\\$\[0-9\]* = false" "print a bool var" | |
81 | ||
82 | # set a bool variable | |
83 | test_expr "set variable v_bool = true" \ | |
84 | "print v_bool" "\\$\[0-9\]* = true" \ | |
85 | "set a bool var" | |
86 | ||
87 | # next print an array of bool | |
88 | gdb_test "print v_bool_array" "\\$\[0-9\]* = \\{false, false\\}" "print a bool array" | |
89 | ||
90 | # set elements of a bool array | |
91 | test_expr "set variable v_bool_array\[1\] = true" \ | |
92 | "print v_bool_array" "\\$\[0-9\]* = \\{false, true\\}" \ | |
93 | "set a bool array elem" | |
94 | ||
95 | # bool constants | |
96 | gdb_test "print true" "\\$\[0-9\]* = true" "print true" | |
97 | gdb_test "print false" "\\$\[0-9\]* = false" "print false" | |
98 | ||
99 | # arithmetic conversions | |
100 | gdb_test "print 1 + true" "\\$\[0-9\]* = 2" "1 + true" | |
101 | gdb_test "print 3 + false" "\\$\[0-9\]* = 3" "3 + false" | |
102 | gdb_test "print 1 < 2 < 3" "\\$\[0-9\]* = true" "1 < 2 < 3" | |
103 | gdb_test "print 2 < 1 > 4" "\\$\[0-9\]* = false" "2 < 1 > 4" | |
104 | gdb_test "print (bool)43" "\\$\[0-9\]* = true" "(bool)43" | |
105 | gdb_test "print (bool)0" "\\$\[0-9\]* = false" "(bool)0" | |
106 | gdb_test "print (bool)17.93" "\\$\[0-9\]* = true" "(bool)17.93" | |
107 | gdb_test "print (bool)0.0" "\\$\[0-9\]* = false" "(bool)0.0" | |
108 | gdb_test "print (int)true" "\\$\[0-9\]* = 1" "(int)true" | |
109 | gdb_test "print (int)false" "\\$\[0-9\]* = 0" "(int)false" | |
b2f83c08 TT |
110 | |
111 | gdb_test "print 'misc.cc'::v_bool" " = true" \ | |
112 | "expression using block qualifier" |