Only support interworking and pic for ELF or COFF targets
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.c++ / misc.exp
CommitLineData
c906108c
SS
1# Copyright (C) 1992, 1994, 1997 Free Software Foundation, Inc.
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
5# the Free Software Foundation; either version 2 of the License, or
6# (at your option) any later version.
7#
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.
12#
13# You should have received a copy of the GNU General Public License
14# along with this program; if not, write to the Free Software
15# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16
17# Please email any bugs, comments, and/or additions to this file to:
18# bug-gdb@prep.ai.mit.edu
19
20# This file was written by Fred Fish. (fnf@cygnus.com)
21
22if $tracelevel then {
23 strace $tracelevel
24}
25
26# Check to see if we have an executable to test. If not, then either we
27# haven't tried to compile one, or the compilation failed for some reason.
28# In either case, just notify the user and skip the tests in this file.
29
30set testfile "misc"
31set srcfile ${testfile}.cc
32set binfile ${objdir}/${subdir}/${testfile}
33if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
34 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
35}
36
37#
38# Deduce language of main()
39#
40
41proc deduce_language_of_main {} {
42 global gdb_prompt
43
44 # See what language gdb thinks main() is, prior to reading full symbols.
45 # I think this fails for COFF targets.
46 setup_xfail "a29k-*-udi"
47 send_gdb "show language\n"
48 gdb_expect {
49 -re ".* source language is \"auto; currently c\[+\]+\".*$gdb_prompt $" {
50 pass "deduced language is C++, before full symbols"
51 }
52 -re ".*$gdb_prompt $" {
53 fail "source language not correct for C++ (psymtabs only)"
54 return
55 }
56 timeout {
57 fail "can't show language (timeout)"
58 return
59 }
60 }
61
62 runto_main
63
64 # See if our idea of the language has changed.
65
66 send_gdb "show language\n"
67 gdb_expect {
68 -re ".* source language is \"auto; currently c\[+\]+\".*$gdb_prompt $" {
69 pass "deduced language is C++, after full symbols"
70 }
71 -re ".*$gdb_prompt $" {
72 fail "source language not correct for C++ (full symbols)"
73 return
74 }
75 timeout {
76 fail "can't show language (timeout)"
77 return
78 }
79 }
80}
81
a0b3c4fd
JM
82proc test_expr { args } {
83 if { [llength $args] % 2 } {
84 warning "an even # of arguments should be passed to test_expr"
85 }
86 set last_ent [expr [llength $args] - 1];
87 set testname [lindex $args $last_ent];
88 if [gdb_test [lindex $args 0] "" "$testname (setup)"] {
89 gdb_suppress_tests;
90 }
91 for {set x 1} {$x < $last_ent} {set x [expr $x + 2]} {
92 if [gdb_test [lindex $args $x] [lindex $args [expr $x + 1]] "$testname ([lindex $args $x])"] {
93 gdb_suppress_tests;
94 }
95 }
96 gdb_stop_suppressing_tests;
97}
98
c906108c
SS
99proc do_tests {} {
100 global prms_id
101 global bug_id
102 global subdir
103 global objdir
104 global srcdir
105 global binfile
106 global gdb_prompt
107
108 set prms_id 0
109 set bug_id 0
110
111 # Start with a fresh gdb.
112
113 gdb_exit
114 gdb_start
115 gdb_reinitialize_dir $srcdir/$subdir
116 gdb_load $binfile
117
118 deduce_language_of_main
119 # Check for fixes for PRs 8916 and 8630
120 gdb_test "print s.a" ".* = 0" "print s.a for foo struct (known gcc 2.7.2 and earlier bug)"
121}
122
123do_tests
a0b3c4fd
JM
124
125test_expr "set language c++" \
126 "print 1 == 1" "print.*\\$\[0-9\]* = true" \
127 "print 1 == 2" "print.*\\$\[0-9\]* = false" \
128 "print as bool"
129
130# Test bool type printing, etc.
131# Note: Language is already set to C++ above!
132gdb_test "print v_bool" "\\$\[0-9\]* = false" "print a bool var"
133
134# set a bool variable
135test_expr "set variable v_bool = true" \
136 "print v_bool" "\\$\[0-9\]* = true" \
137 "set a bool var"
138
139# next print an array of bool
140gdb_test "print v_bool_array" "\\$\[0-9\]* = \\{false, false\\}" "print a bool array"
141
142# set elements of a bool array
143test_expr "set variable v_bool_array\[1\] = true" \
144 "print v_bool_array" "\\$\[0-9\]* = \\{false, true\\}" \
145 "set a bool array elem"
146
147# bool constants
148gdb_test "print true" "\\$\[0-9\]* = true" "print true"
149gdb_test "print false" "\\$\[0-9\]* = false" "print false"
150
151# arithmetic conversions
152gdb_test "print 1 + true" "\\$\[0-9\]* = 2" "1 + true"
153gdb_test "print 3 + false" "\\$\[0-9\]* = 3" "3 + false"
154gdb_test "print 1 < 2 < 3" "\\$\[0-9\]* = true" "1 < 2 < 3"
155gdb_test "print 2 < 1 > 4" "\\$\[0-9\]* = false" "2 < 1 > 4"
156gdb_test "print (bool)43" "\\$\[0-9\]* = true" "(bool)43"
157gdb_test "print (bool)0" "\\$\[0-9\]* = false" "(bool)0"
158gdb_test "print (bool)17.93" "\\$\[0-9\]* = true" "(bool)17.93"
159gdb_test "print (bool)0.0" "\\$\[0-9\]* = false" "(bool)0.0"
160gdb_test "print (int)true" "\\$\[0-9\]* = 1" "(int)true"
161gdb_test "print (int)false" "\\$\[0-9\]* = 0" "(int)false"
This page took 0.038571 seconds and 4 git commands to generate.