1 # Copyright (C) 1992, 1996, 1997 Free Software Foundation, Inc.
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.
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.
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.
17 # Please email any bugs, comments, and/or additions to this file to:
18 # bug-gdb@prep.ai.mit.edu
20 # This file was written by Fred Fish. (fnf@cygnus.com)
28 set testfile "templates"
29 set srcfile ${testfile}.cc
30 set binfile ${objdir}/${subdir}/${testfile}
32 # Create and source the file that provides information about the compiler
33 # used to compile the test case.
34 if [get_compiler_info ${binfile} "c++"] {
39 # if we are on HPUX and we are not compiled with gcc, then skip these tests.
41 if [istarget hppa*-*-hpux*] {
47 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
48 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
54 # Test printing of the types of templates.
57 proc test_ptype_of_templates {} {
61 send_gdb "ptype T5<int>\n"
63 -re "type = class T5<int> \{${ws}public:${ws}static int X;${ws}int x;${ws}int val;${ws}T5\\<int> & operator=\\(T5<int> const &\\);${ws}T5\\(int\\);${ws}T5\\(T5<int> const &\\);${ws}~T5\\(void\\);${ws}static void \\* operator new\\(unsigned (int|long)\\);${ws}static void operator delete\\(void \\*\\);${ws}int value\\(void\\);${ws}\}\r\n$gdb_prompt $" {
66 -re "type = class T5<int> \{${ws}public:${ws}static int X;${ws}int x;${ws}int val;((${ws}T5\\<int> & operator=\\(T5<int> const &\\);)|(${ws}T5\\(int\\);)|(${ws}T5\\(T5<int> const &\\);)|(${ws}~T5\\(void\\);)|(${ws}static void \\* operator new\\(unsigned (int|long)\\);)|(${ws}static void operator delete\\(void \\*\\);)|(${ws}int value\\(void\\);))*${ws}\}\r\n$gdb_prompt $" {
67 pass "ptype T5<int> (obsolescent gcc or gdb)"
69 -re ".*$gdb_prompt $" {
73 fail "ptype T5<int> (timeout)"
77 send_gdb "ptype t5i\n"
79 -re "type = class T5<int> \{${ws}public:${ws}static int X;${ws}int x;${ws}int val;${ws}T5<int> & operator=\\(T5<int> const &\\);${ws}T5\\(int\\);${ws}T5\\(T5<int> const &\\);${ws}~T5\\(void\\);${ws}static void \\* operator new\\(unsigned (int|long)\\);${ws}static void operator delete\\(void \\*\\);${ws}int value\\(void\\);${ws}\}\r\n$gdb_prompt $" {
82 -re "type = class T5<int> \{${ws}public:${ws}static int X;${ws}int x;${ws}int val;((${ws}T5<int> & operator=\\(T5<int> const &\\);)|(${ws}T5\\(int\\);)|(${ws}T5\\(T5<int> const &\\);)|(${ws}~T5\\(void\\);)|(${ws}static void \\* operator new\\(unsigned (int|long)\\);)|(${ws}static void operator delete\\(void \\*\\);)|(${ws}int value\\(void\\);))*${ws}\}\r\n$gdb_prompt $" {
83 pass "ptype t5i (obsolescent gcc or gdb)"
85 -re ".*$gdb_prompt $" {
89 fail "ptype t5i (timeout)"
95 # Test breakpoint setting on template methods.
98 proc test_template_breakpoints {} {
103 send_gdb "break T5<int>::T5\n"
105 -re "0. cancel.*\[\r\n\]*.1. all.*\[\r\n\]*.2. T5<int>::T5\\(int\\) at .*\[\r\n\]*.3. T5<int>::T5\\(T5<int> const &\\) at .*\[\r\n\]*> $" {
108 "constructor breakpoint (obsolete format!)"
110 -re ".0. cancel\[\r\n\]*.1. all\[\r\n\]*.2. T5<int>::T5\\(T5<int> const &\\) at .*templates.cc:.*\[\r\n\]*.3. T5<int>::T5\\(int\\) at .*templates.cc:.*\[\r\n\]*> $" {
113 "constructor breakpoint"
115 -re ".*$gdb_prompt $" { fail "constructor breakpoint" }
116 default { fail "constructor breakpoint (timeout)" }
119 gdb_test "break T5<int>::~T5" \
120 "Breakpoint.*at.* file .*${testfile}.cc, line.*" \
121 "destructor breakpoint"
123 gdb_test "break T5<int>::value" \
124 "Breakpoint.*at.* file .*${testfile}.cc, line.*" \
125 "value method breakpoint"
131 # Test calling of template methods.
134 proc test_template_calls {} {
137 if [target_info exists gdb,cannot_call_functions] {
138 setup_xfail "*-*-*" 2416
139 fail "This target can not call functions"
143 send_gdb "print t5i.value()\n"
145 -re ".* = 2\[\r\n\]*$gdb_prompt $" { pass "print t5i.value()" }
146 -re "Cannot invoke functions on this machine.*$gdb_prompt $" {
147 fail "print t5i.value()"
149 -re ".*$gdb_prompt $" { fail "print t5i.value()" }
150 default { fail "print t5i.value() (timeout)" }
163 global supports_template_debugging
168 # Start with a fresh gdb.
172 gdb_reinitialize_dir $srcdir/$subdir
175 if { !$supports_template_debugging } {
176 warning "compiler lacks debugging info for templates; tests suppressed." 0
180 # Get the debug format for the compiled test case. If that
181 # format is DWARF 1 then just skip all the tests since none of
184 if [ runto_main] then {
186 if [ setup_xfail_format "DWARF 1" ] then {
187 fail "C++ tests skipped due to limited C++ support in DWARF 1 debug format"
193 test_ptype_of_templates
194 test_template_breakpoints