Automatic Copyright Year update after running gdb/copyright.py
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.cp / cplusfuncs.exp
index 443af7a3b6765a8e025f673560863993ac2b1a6b..01cdfb68bf392cf5eaa1e905dd214a8b5e4c29ff 100644 (file)
@@ -1,5 +1,4 @@
-# Copyright 1992, 1997, 1999, 2001, 2002, 2003, 2004, 2007, 2008, 2009, 2010
-# Free Software Foundation, Inc.
+# Copyright 1992-2022 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
 # This file was written by Fred Fish. (fnf@cygnus.com)
 # Adapted for g++ 3.0 ABI by Michael Chastain. (chastain@redhat.com)
 
-if $tracelevel then {
-       strace $tracelevel
-}
-
 if { [skip_cplus_tests] } { continue }
 
-set testfile "cplusfuncs"
-set srcfile ${testfile}.cc
-set binfile ${objdir}/${subdir}/${testfile}
+standard_testfile .cc
 
-if { [get_compiler_info $binfile "c++"] } {
+if { [get_compiler_info "c++"] } {
     return -1
 }
 
-if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
-     untested cplusfuncs.exp
-     return -1
+if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug c++}]} {
+    return -1
 }
 
 #
@@ -99,278 +91,194 @@ proc probe_demangler { } {
     global dm_type_unsigned_long
     global dm_type_typedef
 
-    send_gdb "print &foo::operator,(foo&)\n"
-    gdb_expect {
-       -re ".*foo::operator, \\(.*foo.*&.*\\).*\r\n$gdb_prompt $" {
-           # v2 demangler
-           set dm_operator_comma ", "
-           pass "detect dm_operator_comma"
-       }
-       -re ".*foo::operator,\\(.*foo.*&.*\\).*\r\n$gdb_prompt $" {
-           # v3 demangler
-           pass "detect dm_operator_comma"
-       }
-       -re ".*$gdb_prompt $" {
-           fail "detect dm_operator_comma"
-       }
-       timeout {
-           fail "detect dm_operator_comma"
-       }
-    }
-
-    send_gdb "print &foo::operator char*($dm_type_void)\n"
-    gdb_expect {
-       -re ".*foo::operator char \\*\\(void\\).*\r\n$gdb_prompt $" {
-           # v2 demangler or GDB type printer
-           set dm_operator_char_star "char *"
-           set dm_operator_char_star_quoted "char \\*"
-           pass "detect dm_operator_char_star"
-       }
-       -re ".*foo::operator char\\*\\(\\).*\r\n$gdb_prompt $" {
-           # v3 demangler
-           pass "detect dm_operator_char_star"
-       }
-       -re ".*$gdb_prompt $" {
-           fail "detect dm_operator_char_star"
-       }
-       timeout {
-           fail "detect dm_operator_char_star"
-       }
-    }
-
-    send_gdb "print &dm_type_char_star\n"
-    gdb_expect {
-       -re ".*dm_type_char_star\\(char \\*\\).*\r\n$gdb_prompt $" {
-           # v2 demangler
-           set dm_type_char_star "char *"
-           set dm_type_char_star_quoted "char \\*"
-           pass "detect dm_type_char_star"
-       }
-       -re ".*dm_type_char_star\\(char\\*\\).*\r\n$gdb_prompt $" {
-           # v3 demangler
-           pass "detect dm_type_char_star"
-       }
-       -re ".*$gdb_prompt $" {
-           fail "detect dm_type_char_star"
-       }
-       timeout {
-           fail "detect dm_type_char_star (timeout)"
-       }
-    }
-
-    send_gdb "print &dm_type_foo_ref\n"
-    gdb_expect {
-       -re ".*dm_type_foo_ref\\(foo &\\).*\r\n$gdb_prompt $" {
-           # v2 demangler
-           set dm_type_foo_ref "foo &"
-           pass "detect dm_type_foo_ref"
-       }
-       -re ".*dm_type_foo_ref\\(foo&\\).*\r\n$gdb_prompt $" {
-           # v3 demangler
-           pass "detect dm_type_foo_ref"
-       }
-       -re ".*$gdb_prompt $" {
-           fail "detect dm_type_foo_ref"
-       }
-       timeout {
-           fail "detect dm_type_foo_ref (timeout)"
-       }
-    }
-
-    send_gdb "print &dm_type_int_star\n"
-    gdb_expect {
-       -re ".*dm_type_int_star\\(int \\*\\).*\r\n$gdb_prompt $" {
-           # v2 demangler
-           set dm_type_int_star "int *"
-           pass "detect dm_type_int_star"
-       }
-       -re ".*dm_type_int_star\\(int\\*\\).*\r\n$gdb_prompt $" {
-           # v3 demangler
-           pass "detect dm_type_int_star"
-       }
-       -re ".*$gdb_prompt $" {
-           fail "detect dm_type_int_star"
-       }
-       timeout {
-           fail "detect dm_type_int_star (timeout)"
-       }
-    }
-
-    send_gdb "print &dm_type_long_star\n"
-    gdb_expect {
-       -re ".*dm_type_long_star\\(long \\*\\).*\r\n$gdb_prompt $" {
-           # v2 demangler
-           set dm_type_long_star "long *"
-           pass "detect dm_type_long_star"
-       }
-       -re ".*dm_type_long_star\\(long\\*\\).*\r\n$gdb_prompt $" {
-           # v3 demangler
-           pass "detect dm_type_long_star"
-       }
-       -re ".*dm_type_long_star\\(long int \\*\\).*\r\n$gdb_prompt $" {
-           # GCC v3 and GDB's type printer
-           set dm_type_long_star "long int *"
-           pass "detect dm_type_long_star"
-       }
-       -re ".*$gdb_prompt $" {
-           fail "detect dm_type_long_star"
-       }
-       timeout {
-           fail "detect dm_type_long_star (timeout)"
-       }
-    }
-
-    send_gdb "print &dm_type_unsigned_int\n"
-    gdb_expect {
-       -re ".*dm_type_unsigned_int\\(unsigned int\\).*\r\n$gdb_prompt $" {
-           # v2 demangler
-           set dm_type_unsigned_int "unsigned int"
-           pass "detect dm_type_unsigned_int"
-       }
-       -re ".*dm_type_unsigned_int\\(unsigned\\).*\r\n$gdb_prompt $" {
-           # v3 demangler
-           pass "detect dm_type_unsigned_int"
-       }
-       -re ".*$gdb_prompt $" {
-           fail "detect dm_type_unsigned_int"
-       }
-       timeout {
-           fail "detect dm_unsigned int (timeout)"
-       }
-    }
-
-    send_gdb "print &dm_type_void\n"
-    gdb_expect {
-       -re ".*dm_type_void\\(void\\).*\r\n$gdb_prompt $" {
-           # v2 demangler
-           set dm_type_void "void"
-           pass "detect dm_type_void"
-       }
-       -re ".*dm_type_void\\(\\).*\r\n$gdb_prompt $" {
-           # v3 demangler
-           pass "detect dm_type_void"
-       }
-       -re ".*$gdb_prompt $" {
-           fail "detect dm_type_void"
-       }
-       timeout {
-           fail "detect dm_type_void (timeout)"
-       }
-    }
-
-    send_gdb "print &dm_type_void_star\n"
-    gdb_expect {
-       -re ".*dm_type_void_star\\(void \\*\\).*\r\n$gdb_prompt $" {
-           # v2 demangler
-           set dm_type_void_star "void *"
-           pass "detect dm_type_void_star"
-       }
-       -re ".*dm_type_void_star\\(void\\*\\).*\r\n$gdb_prompt $" {
-           # v3 demangler
-           pass "detect dm_type_void_star"
-       }
-       -re ".*$gdb_prompt $" {
-           fail "detect dm_type_void_star"
+    gdb_test_multiple "print &foo::operator,(foo&)" \
+       "detect dm_operator_comma" {
+           -re ".*foo::operator, \\(.*foo.*&.*\\).*\r\n$gdb_prompt $" {
+               # v2 demangler
+               set dm_operator_comma ", "
+               pass "detect dm_operator_comma"
+           }
+           -re ".*foo::operator,\\(.*foo.*&.*\\).*\r\n$gdb_prompt $" {
+               # v3 demangler
+               pass "detect dm_operator_comma"
+           }
+       }
+
+    gdb_test_multiple "print &foo::operator char*($dm_type_void)" \
+       "detect dm_operator_char_star" {
+           -re ".*foo::operator char \\*\\(void\\).*\r\n$gdb_prompt $" {
+               # v2 demangler or GDB type printer
+               set dm_operator_char_star "char *"
+               set dm_operator_char_star_quoted "char \\*"
+               pass "detect dm_operator_char_star"
+           }
+           -re ".*foo::operator char\\*\\(\\).*\r\n$gdb_prompt $" {
+               # v3 demangler
+               pass "detect dm_operator_char_star"
+           }
+       }
+
+    gdb_test_multiple "print &dm_type_char_star" \
+       "detect dm_type_char_star" {
+           -re ".*dm_type_char_star\\(char \\*\\).*\r\n$gdb_prompt $" {
+               # v2 demangler
+               set dm_type_char_star "char *"
+               set dm_type_char_star_quoted "char \\*"
+               pass "detect dm_type_char_star"
+           }
+           -re ".*dm_type_char_star\\(char\\*\\).*\r\n$gdb_prompt $" {
+               # v3 demangler
+               pass "detect dm_type_char_star"
+           }
+       }
+
+    gdb_test_multiple "print &dm_type_foo_ref" \
+       "detect dm_type_foo_ref" {
+           -re ".*dm_type_foo_ref\\(foo &\\).*\r\n$gdb_prompt $" {
+               # v2 demangler
+               set dm_type_foo_ref "foo &"
+               pass "detect dm_type_foo_ref"
+           }
+           -re ".*dm_type_foo_ref\\(foo&\\).*\r\n$gdb_prompt $" {
+               # v3 demangler
+               pass "detect dm_type_foo_ref"
+           }
+       }
+
+    gdb_test_multiple "print &dm_type_int_star" \
+       "detect dm_type_int_star" {
+           -re ".*dm_type_int_star\\(int \\*\\).*\r\n$gdb_prompt $" {
+               # v2 demangler
+               set dm_type_int_star "int *"
+               pass "detect dm_type_int_star"
+           }
+           -re ".*dm_type_int_star\\(int\\*\\).*\r\n$gdb_prompt $" {
+               # v3 demangler
+               pass "detect dm_type_int_star"
+           }
+       }
+
+    gdb_test_multiple "print &dm_type_long_star" \
+       "detect dm_type_long_star" {
+           -re ".*dm_type_long_star\\(long \\*\\).*\r\n$gdb_prompt $" {
+               # v2 demangler
+               set dm_type_long_star "long *"
+               pass "detect dm_type_long_star"
+           }
+           -re ".*dm_type_long_star\\(long\\*\\).*\r\n$gdb_prompt $" {
+               # v3 demangler
+               pass "detect dm_type_long_star"
+           }
+           -re ".*dm_type_long_star\\(long int \\*\\).*\r\n$gdb_prompt $" {
+               # GCC v3 and GDB's type printer
+               set dm_type_long_star "long int *"
+               pass "detect dm_type_long_star"
+           }
+       }
+
+    gdb_test_multiple "print &dm_type_unsigned_int" \
+       "detect dm_type_unsigned_int" {
+           -re ".*dm_type_unsigned_int\\(unsigned int\\).*\r\n$gdb_prompt $" {
+               # v2 demangler
+               set dm_type_unsigned_int "unsigned int"
+               pass "detect dm_type_unsigned_int"
+           }
+           -re ".*dm_type_unsigned_int\\(unsigned\\).*\r\n$gdb_prompt $" {
+               # v3 demangler
+               pass "detect dm_type_unsigned_int"
+           }
+       }
+
+    gdb_test_multiple "print &dm_type_void" \
+       "detect dm_type_void" {
+           -re ".*dm_type_void\\(void\\).*\r\n$gdb_prompt $" {
+               # v2 demangler
+               set dm_type_void "void"
+               pass "detect dm_type_void"
+           }
+           -re ".*dm_type_void\\(\\).*\r\n$gdb_prompt $" {
+               # v3 demangler
+               pass "detect dm_type_void"
+           }
+       }
+
+    gdb_test_multiple "print &dm_type_void_star" \
+       "detect dm_type_void_star" {
+           -re ".*dm_type_void_star\\(void \\*\\).*\r\n$gdb_prompt $" {
+               # v2 demangler
+               set dm_type_void_star "void *"
+               pass "detect dm_type_void_star"
+           }
+           -re ".*dm_type_void_star\\(void\\*\\).*\r\n$gdb_prompt $" {
+               # v3 demangler
+               pass "detect dm_type_void_star"
+           }
+       }
+
+    gdb_test_multiple "print &dm_type_short" \
+       "detect dm_type_short" {
+           -re ".*dm_type_short\\(short\\).*\r\n$gdb_prompt $" {
+               # v2 and v3 demanglers
+               pass "detect dm_type_short"
+           }
+           -re ".*dm_type_short\\(short int\\).*\r\n$gdb_prompt $" {
+               # GDB type printer
+               set dm_type_short "short int"
+               pass "detect dm_type_short"
+           }
+       }
+
+    gdb_test_multiple "print &dm_type_unsigned_short" \
+       "detect dm_type_unsigned_short" {
+           -re ".*dm_type_unsigned_short\\(unsigned short\\).*\r\n$gdb_prompt $" {
+               # v2 and v3 demanglers
+               pass "detect dm_type_unsigned_short"
+           }
+           -re ".*dm_type_unsigned_short\\(short unsigned int\\).*\r\n$gdb_prompt $" {
+               # GDB type printer
+               set dm_type_unsigned_short "short unsigned int"
+               pass "detect dm_type_unsigned_short"
+           }
+       }
+
+    gdb_test_multiple "print &dm_type_long" \
+       "detect dm_type_long" {
+           -re ".*dm_type_long\\(long\\).*\r\n$gdb_prompt $" {
+               # v2 and v3 demanglers
+               pass "detect dm_type_long"
+           }
+           -re ".*dm_type_long\\(long int\\).*\r\n$gdb_prompt $" {
+               # GDB type printer
+               set dm_type_long "long int"
+               pass "detect dm_type_long"
+           }
+       }
+
+    gdb_test_multiple "print &dm_type_unsigned_long" \
+       "detect dm_type_unsigned_long" {
+           -re ".*dm_type_unsigned_long\\(unsigned long\\).*\r\n$gdb_prompt $" {
+               # v2 and v3 demanglers
+               pass "detect dm_type_unsigned_long"
+           }
+           -re ".*dm_type_unsigned_long\\(long unsigned int\\).*\r\n$gdb_prompt $" {
+               # GDB type printer
+               set dm_type_unsigned_long "long unsigned int"
+               pass "detect dm_type_unsigned_long"
+           }
+       }
+
+    gdb_test_multiple "print &dm_type_typedef" \
+       "detect dm_type_typedef" {
+           -re ".*dm_type_typedef\\(int\\).*\r\n$gdb_prompt $" {
+               # v2 and v3 demanglers
+               pass "detect dm_type_typedef"
+           }
+           -re ".*dm_type_typedef\\(myint\\).*\r\n$gdb_prompt $" {
+               # GDB type printer
+               set dm_type_typedef 1
+               pass "detect dm_type_typedef"
+           }
        }
-       timeout {
-           fail "detect dm_type_void_star (timeout)"
-       }
-    }
-
-    send_gdb "print &dm_type_short\n"
-    gdb_expect {
-       -re ".*dm_type_short\\(short\\).*\r\n$gdb_prompt $" {
-           # v2 and v3 demanglers
-           pass "detect dm_type_short"
-       }
-       -re ".*dm_type_short\\(short int\\).*\r\n$gdb_prompt $" {
-           # GDB type printer
-           set dm_type_short "short int"
-           pass "detect dm_type_short"
-       }
-       -re ".*$gdb_prompt $" {
-           fail "detect dm_type_short"
-       }
-       timeout {
-           fail "detect dm_type_short (timeout)"
-       }
-    }
-
-    send_gdb "print &dm_type_unsigned_short\n"
-    gdb_expect {
-       -re ".*dm_type_unsigned_short\\(unsigned short\\).*\r\n$gdb_prompt $" {
-           # v2 and v3 demanglers
-           pass "detect dm_type_unsigned_short"
-       }
-       -re ".*dm_type_unsigned_short\\(short unsigned int\\).*\r\n$gdb_prompt $" {
-           # GDB type printer
-           set dm_type_unsigned_short "short unsigned int"
-           pass "detect dm_type_unsigned_short"
-       }
-       -re ".*$gdb_prompt $" {
-           fail "detect dm_type_unsigned_short"
-       }
-       timeout {
-           fail "detect dm_type_unsigned_short (timeout)"
-       }
-    }
-
-    send_gdb "print &dm_type_long\n"
-    gdb_expect {
-       -re ".*dm_type_long\\(long\\).*\r\n$gdb_prompt $" {
-           # v2 and v3 demanglers
-           pass "detect dm_type_long"
-       }
-       -re ".*dm_type_long\\(long int\\).*\r\n$gdb_prompt $" {
-           # GDB type printer
-           set dm_type_long "long int"
-           pass "detect dm_type_long"
-       }
-       -re ".*$gdb_prompt $" {
-           fail "detect dm_type_long"
-       }
-       timeout {
-           fail "detect dm_type_long (timeout)"
-       }
-    }
-
-    send_gdb "print &dm_type_unsigned_long\n"
-    gdb_expect {
-       -re ".*dm_type_unsigned_long\\(unsigned long\\).*\r\n$gdb_prompt $" {
-           # v2 and v3 demanglers
-           pass "detect dm_type_unsigned_long"
-       }
-       -re ".*dm_type_unsigned_long\\(long unsigned int\\).*\r\n$gdb_prompt $" {
-           # GDB type printer
-           set dm_type_unsigned_long "long unsigned int"
-           pass "detect dm_type_unsigned_long"
-       }
-       -re ".*$gdb_prompt $" {
-           fail "detect dm_type_unsigned_long"
-       }
-       timeout {
-           fail "detect dm_type_unsigned_long (timeout)"
-       }
-    }
-
-    send_gdb "print &dm_type_typedef\n"
-    gdb_expect {
-       -re ".*dm_type_typedef\\(int\\).*\r\n$gdb_prompt $" {
-           # v2 and v3 demanglers
-           pass "detect dm_type_typedef"
-       }
-       -re ".*dm_type_typedef\\(myint\\).*\r\n$gdb_prompt $" {
-           # GDB type printer
-           set dm_type_typedef 1
-           pass "detect dm_type_typedef"
-       }
-       -re ".*$gdb_prompt $" {
-           fail "detect dm_type_typedef"
-       }
-       timeout {
-           fail "detect dm_type_typedef (timeout)"
-       }
-    }
 }
 
 #
@@ -379,21 +287,16 @@ proc probe_demangler { } {
 #
 
 proc info_func_regexp { name demangled } {
-    global gdb_prompt
+    global srcfile decimal
 
-    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\""
-       }
-       -re ".*$gdb_prompt $" {
-           fail "info function for \"$name\""
-       }
-       timeout {
-           fail "info function for \"$name\" (timeout)"
-       }
-    }
+
+    set file_re "File .*[string_to_regexp $srcfile]:"
+
+    gdb_test_lines "info function $name" "info function for \"$name\"" \
+       [multi_line \
+            "$file_re" \
+            "$decimal:\t(class|)${demangled}.*"]
 }
 
 #
@@ -419,18 +322,8 @@ proc print_addr_2 { name good } {
 
     set good_pattern [string_to_regexp $good]
 
-    send_gdb "print &$name\n"
-    gdb_expect {
-       -re ".* = .* $hex <$good_pattern>\r\n$gdb_prompt $" {
-           pass "print &$name"
-       }
-       -re ".*$gdb_prompt $" {
-           fail "print &$name"
-       }
-       timeout {
-           fail "print &$name (timeout)"
-       }
-    }
+    gdb_test "print &$name" \
+       ".* = .* $hex <$good_pattern>"
 }
 
 # NOTE: carlton/2003-01-16: hairyfunc5-6 fail on GCC 3.x (for at least
@@ -447,20 +340,13 @@ 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"
-    gdb_expect {
+    gdb_test_multiple "print &$name" "print &$name" {
        -re ".* = .* $hex <$good_pattern>\r\n$gdb_prompt $" {
            pass "print &$name"
        }
        -re ".* = .* $hex <$bad_pattern>\r\n$gdb_prompt $" {
            kfail $bugid "print &$name"
        }
-       -re ".*$gdb_prompt $" {
-           fail "print &$name"
-       }
-       timeout {
-           fail "print &$name (timeout)"
-       }
     }
 }
 
@@ -560,7 +446,6 @@ proc test_lookup_operator_functions {} {
 
 proc test_paddr_operator_functions {} {
     global hex
-    global hp_aCC_compiler
     global dm_operator_comma
     global dm_type_char_star
     global dm_type_foo_ref
@@ -613,13 +498,9 @@ proc test_paddr_operator_functions {} {
        " = .* $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.*>"
-    }
+
+    print_addr "foo::operator delete($dm_type_void_star)"
+    print_addr "foo::operator delete\[\]($dm_type_void_star)"
 
     print_addr "foo::operator int($dm_type_void)"
     print_addr "foo::operator $dm_operator_char_star\($dm_type_void)"
@@ -697,32 +578,16 @@ proc test_paddr_hairy_functions {} {
 }
 
 proc do_tests {} {
-    global prms_id
-    global bug_id
-    global subdir
-    global objdir
-    global srcdir
     global binfile
-    global gdb_prompt
     global dm_type_int_star
 
-    set prms_id 0
-    set bug_id 0
-
-    # Start with a fresh gdb.
-
-    gdb_exit
-    gdb_start
-    gdb_reinitialize_dir $srcdir/$subdir
-    gdb_load $binfile
+    clean_restart $binfile
 
-    send_gdb "set language c++\n"
-    gdb_expect -re "$gdb_prompt $"
-    send_gdb "set width 0\n"
-    gdb_expect -re "$gdb_prompt $"
+    gdb_test_no_output "set width 0"
 
     runto_main
 
+    gdb_test_no_output "set language c++"
     probe_demangler
     test_paddr_overloaded_functions
     test_paddr_operator_functions
@@ -731,7 +596,7 @@ proc do_tests {} {
 
     # 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.*"
+       "Function \"foo::operator [string_to_regexp $dm_type_int_star]\" not defined\\."
 }
 
 do_tests
This page took 0.031706 seconds and 4 git commands to generate.