| 1 | # Copyright (C) 1992, 1996, 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 | |
| 22 | set ws "\[\r\n\t \]+" |
| 23 | |
| 24 | if $tracelevel then { |
| 25 | strace $tracelevel |
| 26 | } |
| 27 | |
| 28 | set testfile "templates" |
| 29 | set srcfile ${testfile}.cc |
| 30 | set binfile ${objdir}/${subdir}/${testfile} |
| 31 | |
| 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++"] { |
| 35 | return -1 |
| 36 | } |
| 37 | source ${binfile}.ci |
| 38 | |
| 39 | # if we are on HPUX and we are not compiled with gcc, then skip these tests. |
| 40 | |
| 41 | if [istarget hppa*-*-hpux*] { |
| 42 | if {!$gcc_compiled} { |
| 43 | continue |
| 44 | } |
| 45 | } |
| 46 | |
| 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." |
| 49 | } |
| 50 | |
| 51 | source ${binfile}.ci |
| 52 | |
| 53 | # |
| 54 | # Test printing of the types of templates. |
| 55 | # |
| 56 | |
| 57 | proc test_ptype_of_templates {} { |
| 58 | global gdb_prompt |
| 59 | global ws |
| 60 | |
| 61 | send_gdb "ptype T5<int>\n" |
| 62 | gdb_expect { |
| 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 $" { |
| 64 | pass "ptype T5<int>" |
| 65 | } |
| 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)" |
| 68 | } |
| 69 | -re ".*$gdb_prompt $" { |
| 70 | fail "ptype T5<int>" |
| 71 | } |
| 72 | timeout { |
| 73 | fail "ptype T5<int> (timeout)" |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | send_gdb "ptype t5i\n" |
| 78 | gdb_expect { |
| 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 $" { |
| 80 | pass "ptype t5i" |
| 81 | } |
| 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)" |
| 84 | } |
| 85 | -re ".*$gdb_prompt $" { |
| 86 | fail "ptype t5i" |
| 87 | } |
| 88 | timeout { |
| 89 | fail "ptype t5i (timeout)" |
| 90 | } |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | # |
| 95 | # Test breakpoint setting on template methods. |
| 96 | # |
| 97 | |
| 98 | proc test_template_breakpoints {} { |
| 99 | global gdb_prompt |
| 100 | global testfile |
| 101 | global srcdir |
| 102 | |
| 103 | send_gdb "break T5<int>::T5\n" |
| 104 | gdb_expect { |
| 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\]*> $" { |
| 106 | gdb_test "0" \ |
| 107 | "cancelled" \ |
| 108 | "constructor breakpoint (obsolete format!)" |
| 109 | } |
| 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\]*> $" { |
| 111 | gdb_test "0" \ |
| 112 | "cancelled" \ |
| 113 | "constructor breakpoint" |
| 114 | } |
| 115 | -re ".*$gdb_prompt $" { fail "constructor breakpoint" } |
| 116 | default { fail "constructor breakpoint (timeout)" } |
| 117 | } |
| 118 | |
| 119 | gdb_test "break T5<int>::~T5" \ |
| 120 | "Breakpoint.*at.* file .*${testfile}.cc, line.*" \ |
| 121 | "destructor breakpoint" |
| 122 | |
| 123 | gdb_test "break T5<int>::value" \ |
| 124 | "Breakpoint.*at.* file .*${testfile}.cc, line.*" \ |
| 125 | "value method breakpoint" |
| 126 | |
| 127 | delete_breakpoints |
| 128 | } |
| 129 | |
| 130 | # |
| 131 | # Test calling of template methods. |
| 132 | # |
| 133 | |
| 134 | proc test_template_calls {} { |
| 135 | global gdb_prompt |
| 136 | |
| 137 | if [target_info exists gdb,cannot_call_functions] { |
| 138 | setup_xfail "*-*-*" 2416 |
| 139 | fail "This target can not call functions" |
| 140 | return |
| 141 | } |
| 142 | |
| 143 | send_gdb "print t5i.value()\n" |
| 144 | gdb_expect { |
| 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()" |
| 148 | } |
| 149 | -re ".*$gdb_prompt $" { fail "print t5i.value()" } |
| 150 | default { fail "print t5i.value() (timeout)" } |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | |
| 155 | proc do_tests {} { |
| 156 | global prms_id |
| 157 | global bug_id |
| 158 | global subdir |
| 159 | global objdir |
| 160 | global srcdir |
| 161 | global binfile |
| 162 | global gdb_prompt |
| 163 | global supports_template_debugging |
| 164 | |
| 165 | set prms_id 0 |
| 166 | set bug_id 0 |
| 167 | |
| 168 | # Start with a fresh gdb. |
| 169 | |
| 170 | gdb_exit |
| 171 | gdb_start |
| 172 | gdb_reinitialize_dir $srcdir/$subdir |
| 173 | gdb_load $binfile |
| 174 | |
| 175 | if { !$supports_template_debugging } { |
| 176 | warning "compiler lacks debugging info for templates; tests suppressed." 0 |
| 177 | return |
| 178 | } |
| 179 | |
| 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 |
| 182 | # them will pass. |
| 183 | |
| 184 | if [ runto_main] then { |
| 185 | get_debug_format |
| 186 | if [ setup_xfail_format "DWARF 1" ] then { |
| 187 | fail "C++ tests skipped due to limited C++ support in DWARF 1 debug format" |
| 188 | return |
| 189 | } |
| 190 | clear_xfail "*-*-*" |
| 191 | } |
| 192 | |
| 193 | test_ptype_of_templates |
| 194 | test_template_breakpoints |
| 195 | |
| 196 | if [ runto_main] { |
| 197 | test_template_calls |
| 198 | } |
| 199 | } |
| 200 | |
| 201 | do_tests |
| 202 | |