include/
[external/binutils.git] / gdb / testsuite / gdb.cp / cplusfuncs.exp
index a509afb..092c0ff 100644 (file)
@@ -1,19 +1,18 @@
-# Copyright 1992, 1997, 1999, 2001, 2002, 2003, 2004
+# Copyright 1992, 1997, 1999, 2001, 2002, 2003, 2004, 2007, 2008, 2009
 # Free Software Foundation, Inc.
 
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
+# the Free Software Foundation; either version 3 of the License, or
 # (at your option) any later version.
-# 
+#
 # This program is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU General Public License for more details.
-# 
+#
 # You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 # This file was written by Fred Fish. (fnf@cygnus.com)
 # Adapted for g++ 3.0 ABI by Michael Chastain. (chastain@redhat.com)
@@ -33,7 +32,8 @@ if { [get_compiler_info $binfile "c++"] } {
 }
 
 if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
-     gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
+     untested cplusfuncs.exp
+     return -1
 }
 
 #
@@ -63,7 +63,7 @@ set dm_type_foo_ref           "foo&"
 set dm_type_int_star           "int*"
 set dm_type_long_star          "long*"
 set dm_type_unsigned_int       "unsigned"
-set dm_type_void               ""
+set dm_type_void               "void"
 set dm_type_void_star          "void*"
 
 proc probe_demangler { } {
@@ -78,7 +78,7 @@ proc probe_demangler { } {
     global dm_type_void
     global dm_type_void_star
 
-    send_gdb "print &'foo::operator,(foo&)'\n"
+    send_gdb "print &foo::operator,(foo&)\n"
     gdb_expect {
        -re ".*foo::operator, \\(.*foo.*&.*\\).*\r\n$gdb_prompt $" {
            # v2 demangler
@@ -97,7 +97,7 @@ proc probe_demangler { } {
        }
     }
 
-    send_gdb "print &'dm_type_char_star'\n"
+    send_gdb "print &dm_type_char_star\n"
     gdb_expect {
        -re ".*dm_type_char_star\\(char \\*\\).*\r\n$gdb_prompt $" {
            # v2 demangler
@@ -117,7 +117,7 @@ proc probe_demangler { } {
        }
     }
 
-    send_gdb "print &'dm_type_foo_ref'\n"
+    send_gdb "print &dm_type_foo_ref\n"
     gdb_expect {
        -re ".*dm_type_foo_ref\\(foo &\\).*\r\n$gdb_prompt $" {
            # v2 demangler
@@ -136,7 +136,7 @@ proc probe_demangler { } {
        }
     }
 
-    send_gdb "print &'dm_type_int_star'\n"
+    send_gdb "print &dm_type_int_star\n"
     gdb_expect {
        -re ".*dm_type_int_star\\(int \\*\\).*\r\n$gdb_prompt $" {
            # v2 demangler
@@ -155,7 +155,7 @@ proc probe_demangler { } {
        }
     }
 
-    send_gdb "print &'dm_type_long_star'\n"
+    send_gdb "print &dm_type_long_star\n"
     gdb_expect {
        -re ".*dm_type_long_star\\(long \\*\\).*\r\n$gdb_prompt $" {
            # v2 demangler
@@ -174,7 +174,7 @@ proc probe_demangler { } {
        }
     }
 
-    send_gdb "print &'dm_type_unsigned_int'\n"
+    send_gdb "print &dm_type_unsigned_int\n"
     gdb_expect {
        -re ".*dm_type_unsigned_int\\(unsigned int\\).*\r\n$gdb_prompt $" {
            # v2 demangler
@@ -193,7 +193,7 @@ proc probe_demangler { } {
        }
     }
 
-    send_gdb "print &'dm_type_void'\n"
+    send_gdb "print &dm_type_void\n"
     gdb_expect {
        -re ".*dm_type_void\\(void\\).*\r\n$gdb_prompt $" {
            # v2 demangler
@@ -212,7 +212,7 @@ proc probe_demangler { } {
        }
     }
 
-    send_gdb "print &'dm_type_void_star'\n"
+    send_gdb "print &dm_type_void_star\n"
     gdb_expect {
        -re ".*dm_type_void_star\\(void \\*\\).*\r\n$gdb_prompt $" {
            # v2 demangler
@@ -241,6 +241,7 @@ proc info_func_regexp { name demangled } {
     global gdb_prompt
 
     send_gdb "info function $name\n"
+    regsub {\\\(void\\\)} $demangled {\(\)} demangled
     gdb_expect {
        -re ".*File .*:\r\n(class |)$demangled\r\n.*$gdb_prompt $" {
            pass "info function for \"$name\""
@@ -277,16 +278,16 @@ proc print_addr_2 { name good } {
 
     set good_pattern [string_to_regexp $good]
 
-    send_gdb "print &'$name'\n"
+    send_gdb "print &$name\n"
     gdb_expect {
        -re ".* = .* $hex <$good_pattern>\r\n$gdb_prompt $" {
-           pass "print &'$name'"
+           pass "print &$name"
        }
        -re ".*$gdb_prompt $" {
-           fail "print &'$name'"
+           fail "print &$name"
        }
        timeout {
-           fail "print &'$name' (timeout)"
+           fail "print &$name (timeout)"
        }
     }
 }
@@ -305,19 +306,19 @@ proc print_addr_2_kfail { name good bad bugid } {
     set good_pattern [string_to_regexp $good]
     set bad_pattern [string_to_regexp $bad]
 
-    send_gdb "print &'$name'\n"
+    send_gdb "print &$name\n"
     gdb_expect {
        -re ".* = .* $hex <$good_pattern>\r\n$gdb_prompt $" {
-           pass "print &'$name'"
+           pass "print &$name"
        }
        -re ".* = .* $hex <$bad_pattern>\r\n$gdb_prompt $" {
-           kfail $bugid "print &'$name'"
+           kfail $bugid "print &$name"
        }
        -re ".*$gdb_prompt $" {
-           fail "print &'$name'"
+           fail "print &$name"
        }
        timeout {
-           fail "print &'$name' (timeout)"
+           fail "print &$name (timeout)"
        }
     }
 }
@@ -327,7 +328,12 @@ proc print_addr_2_kfail { name good bad bugid } {
 #
 
 proc print_addr { name } {
-    print_addr_2 "$name" "$name"
+    regsub {\(void\)} $name {()} expected
+    if {[string first "::" $name] == -1} {
+       # C function -- must be qutoed
+       set name "'$name'"
+    }
+    print_addr_2 "$name" $expected
 }
 
 #
@@ -460,10 +466,13 @@ proc test_paddr_operator_functions {} {
     print_addr "foo::operator\[\]($dm_type_foo_ref)"
     print_addr "foo::operator()($dm_type_foo_ref)"
 
-    gdb_test "print &'foo::operator new'" \
+    gdb_test "print &foo::operator new" \
        " = .* $hex <foo::operator new\\(.*\\)(| static)>"
+    gdb_test "print &foo::operator new\[\]" \
+       " = .* $hex <foo::operator new\\\[\\\]\\(.*\\)(| static)>"    
     if { !$hp_aCC_compiler } {
        print_addr "foo::operator delete($dm_type_void_star)"
+       print_addr "foo::operator delete[]($dm_type_void_star)"
     } else {
        gdb_test "print &'foo::operator delete($dm_type_void_star) static'" \
            " = .*(0x\[0-9a-f\]+|) <foo::operator delete.*>"
@@ -534,6 +543,7 @@ proc do_tests {} {
     global srcdir
     global binfile
     global gdb_prompt
+    global dm_type_int_star
 
     set prms_id 0
     set bug_id 0
@@ -557,6 +567,10 @@ proc do_tests {} {
     test_paddr_operator_functions
     test_paddr_hairy_functions
     test_lookup_operator_functions
+
+    # A regression test on errors involving operators
+    gdb_test "list foo::operator $dm_type_int_star" \
+       ".*the class foo does not have any method named operator $dm_type_int_star.*"
 }
 
 do_tests