Handle void * conversions in FreeBSD/x86 native code to fix C++ build.
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.cp / classes.exp
index 397a14920f2754a03b18342d727c9f54f2869959..005548f11626290f7347cfae06f184183d5d73b4 100644 (file)
@@ -1,39 +1,31 @@
-# Copyright 1992, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
-# 2003, 2004 Free Software Foundation, Inc.
+# Copyright 1992-2016 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)
 # And rewritten by Michael Chastain <mec.gnu@mindspring.com>.
 
 set nl "\[\r\n\]+"
 
-if $tracelevel then {
-    strace $tracelevel
-}
-
 if { [skip_cplus_tests] } { continue }
 
 load_lib "cp-support.exp"
 
-set testfile "classes"
-set srcfile ${testfile}.cc
-set binfile ${objdir}/${subdir}/${testfile}
+standard_testfile .cc
 
-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."
+if {[prepare_for_testing $testfile.exp $testfile $srcfile {debug c++}]} {
+    return -1
 }
 
 # Test ptype of class objects.
@@ -43,7 +35,7 @@ proc test_ptype_class_objects {} {
     # Simple type.
 
     cp_test_ptype_class \
-       "ptype struct default_public_struct" "" "struct" "default_public_struct" \
+       "struct default_public_struct" "" "struct" "default_public_struct" \
        {
            { field public "int a;" }
            { field public "int b;" }
@@ -52,7 +44,7 @@ proc test_ptype_class_objects {} {
     # Another simple type.
 
     cp_test_ptype_class \
-       "ptype struct explicit_public_struct" "" "struct" "explicit_public_struct" \
+       "struct explicit_public_struct" "" "struct" "explicit_public_struct" \
        {
            { field public "int a;" }
            { field public "int b;" }
@@ -61,7 +53,7 @@ proc test_ptype_class_objects {} {
     # Another simple type.
 
     cp_test_ptype_class \
-       "ptype struct protected_struct" "" "struct" "protected_struct" \
+       "struct protected_struct" "" "struct" "protected_struct" \
        {
            { field protected "int a;" }
            { field protected "int b;" }
@@ -70,7 +62,7 @@ proc test_ptype_class_objects {} {
     # Another simple type.
 
     cp_test_ptype_class \
-       "ptype struct private_struct" "" "struct" "private_struct" \
+       "struct private_struct" "" "struct" "private_struct" \
        {
            { field private "int a;" }
            { field private "int b;" }
@@ -79,7 +71,7 @@ proc test_ptype_class_objects {} {
     # A bigger type.
 
     cp_test_ptype_class \
-       "ptype struct mixed_protection_struct" "" "struct" "mixed_protection_struct" \
+       "struct mixed_protection_struct" "" "struct" "mixed_protection_struct" \
        {
            { field public    "int a;" }
            { field public    "int b;" }
@@ -96,7 +88,7 @@ proc test_ptype_class_objects {} {
     # gdb does not care about the difference anyways.
 
     cp_test_ptype_class \
-       "ptype class public_class" "" "class" "public_class" \
+       "class public_class" "" "class" "public_class" \
        {
            { field public "int a;" }
            { field public "int b;" }
@@ -105,7 +97,7 @@ proc test_ptype_class_objects {} {
     # Another simple type.
 
     cp_test_ptype_class \
-       "ptype class protected_class" "" "class" "protected_class" \
+       "class protected_class" "" "class" "protected_class" \
        {
            { field protected "int a;" }
            { field protected "int b;" }
@@ -114,7 +106,7 @@ proc test_ptype_class_objects {} {
     # Another simple type.
 
     cp_test_ptype_class \
-       "ptype class default_private_class" "" "class" "default_private_class" \
+       "class default_private_class" "" "class" "default_private_class" \
        {
            { field private "int a;" }
            { field private "int b;" }
@@ -123,7 +115,7 @@ proc test_ptype_class_objects {} {
     # Another simple type.
 
     cp_test_ptype_class \
-       "ptype class explicit_private_class" "" "class" "explicit_private_class" \
+       "class explicit_private_class" "" "class" "explicit_private_class" \
        {
            { field private "int a;" }
            { field private "int b;" }
@@ -132,7 +124,7 @@ proc test_ptype_class_objects {} {
     # A bigger type.
 
     cp_test_ptype_class \
-       "ptype class mixed_protection_class" "" "class" "mixed_protection_class" \
+       "class mixed_protection_class" "" "class" "mixed_protection_class" \
        {
 
            { field public    "int a;" }
@@ -151,7 +143,7 @@ proc test_ptype_class_objects {} {
     # Base class.
 
     cp_test_ptype_class \
-       "ptype class A" "" "class" "A" \
+       "class A" "" "class" "A" \
        {
            { field public "int a;" }
            { field public "int x;" }
@@ -160,7 +152,7 @@ proc test_ptype_class_objects {} {
     # Derived class.
 
     cp_test_ptype_class \
-       "ptype class B" "" "class" "B" \
+       "class B" "" "class" "B" \
        {
            { base         "public A" }
            { field public "int b;" }
@@ -170,7 +162,7 @@ proc test_ptype_class_objects {} {
     # Derived class.
 
     cp_test_ptype_class \
-       "ptype class C" "" "class" "C" \
+       "class C" "" "class" "C" \
        {
            { base         "public A" }
            { field public "int c;" }
@@ -180,7 +172,7 @@ proc test_ptype_class_objects {} {
     # Derived class, multiple inheritance.
 
     cp_test_ptype_class \
-       "ptype class D" "" "class" "D" \
+       "class D" "" "class" "D" \
        {
            { base         "public B" }
            { base         "public C" }
@@ -191,7 +183,7 @@ proc test_ptype_class_objects {} {
     # Derived class.
 
     cp_test_ptype_class \
-       "ptype class E" "" "class" "E" \
+       "class E" "" "class" "E" \
        {
            { base         "public D" }
            { field public "int e;" }
@@ -204,7 +196,7 @@ proc test_ptype_class_objects {} {
     # static methods whose name is the same as their argument mangling.
  
     cp_test_ptype_class \
-       "ptype class Static" "" "class" "Static" \
+       "class Static" "" "class" "Static" \
        {
            { method public "static void ii(int, int);" }
        }
@@ -214,7 +206,7 @@ proc test_ptype_class_objects {} {
     # A virtual base class.
 
     cp_test_ptype_class \
-       "ptype class vA" "" "class" "vA" \
+       "class vA" "" "class" "vA" \
        {
            { field public "int va;" }
            { field public "int vx;" }
@@ -223,7 +215,7 @@ proc test_ptype_class_objects {} {
     # A derived class with a virtual base.
 
     cp_test_ptype_class \
-       "ptype class vB" "" "class" "vB" \
+       "class vB" "" "class" "vB" \
        {
            { base         "public virtual vA" }
            { vbase        "vA" }
@@ -234,7 +226,7 @@ proc test_ptype_class_objects {} {
     # Another derived class with a virtual base.
 
     cp_test_ptype_class \
-       "ptype class vC" "" "class" "vC" \
+       "class vC" "" "class" "vC" \
        {
            { base         "public virtual vA" }
            { vbase        "vA" }
@@ -245,7 +237,7 @@ proc test_ptype_class_objects {} {
     # A classic diamond class.
 
     cp_test_ptype_class \
-       "ptype class vD" "" "class" "vD" \
+       "class vD" "" "class" "vD" \
        {
            { base         "public virtual vB" }
            { base         "public virtual vC" }
@@ -258,7 +250,7 @@ proc test_ptype_class_objects {} {
     # A class derived from a diamond class.
 
     cp_test_ptype_class \
-       "ptype class vE" "" "class" "vE" \
+       "class vE" "" "class" "vE" \
        {
            { base         "public virtual vD" }
            { vbase        "vD" }
@@ -271,7 +263,7 @@ proc test_ptype_class_objects {} {
     # A base class.
 
     cp_test_ptype_class \
-       "ptype class Base1" "" "class" "Base1" \
+       "class Base1" "" "class" "Base1" \
        {
            { field  public "int x;" }
            { method public "Base1(int);" }
@@ -280,7 +272,7 @@ proc test_ptype_class_objects {} {
     # Another base class.
 
     cp_test_ptype_class \
-       "ptype class Foo" "" "class" "Foo" \
+       "class Foo" "" "class" "Foo" \
        {
            { field public "int x;" }
            { field public "int y;" }
@@ -307,7 +299,7 @@ proc test_ptype_class_objects {} {
     # A multiple inheritance derived class.
 
     cp_test_ptype_class \
-       "ptype class Bar" "" "class" "Bar" \
+       "class Bar" "" "class" "Bar" \
        {
            { base          "public Base1" }
            { base          "public Foo" }
@@ -315,6 +307,15 @@ proc test_ptype_class_objects {} {
            { method public "Bar(int, int, int);" }
        }
 
+    # Derived class with typedef'd baseclass with virtual methods.
+
+    cp_test_ptype_class \
+       "class DynamicBar" "" "class" "DynamicBar" \
+       {
+           { base          "public DynamicBase2" }
+           { field  public "int y;" }
+           { method public "DynamicBar(int, int);" }
+       }
 }
 
 # Test simple access to class members.
@@ -394,31 +395,34 @@ proc test_enums {} {
 
     # print the object
 
+    # We match the enum values with and without qualifiers.  As of
+    # 2008-08-21 we can output the qualifiers for DWARF-2.
+
     gdb_test "print obj_with_enum" \
-       "\\$\[0-9\]+ = \{priv_enum = red, x = 0\}" \
+       "\\$\[0-9\]+ = \{priv_enum = (ClassWithEnum::)?red, x = 0\}" \
        "print obj_with_enum (1)"
 
     # advance one line
 
-    gdb_test "next" ""
+    gdb_test "next" ".*"
 
     # print the object again
 
     gdb_test "print obj_with_enum" \
-       "\\$\[0-9\]+ = \{priv_enum = green, x = 0\}" \
+       "\\$\[0-9\]+ = \{priv_enum = (ClassWithEnum::)?green, x = 0\}" \
        "print obj_with_enum (2)"
 
     # print the enum member
 
-    gdb_test "print obj_with_enum.priv_enum" "\\$\[0-9\]+ = green"
+    gdb_test "print obj_with_enum.priv_enum" "\\$\[0-9\]+ = (ClassWithEnum::)?green"
 
     # ptype on the enum member
 
     gdb_test_multiple "ptype obj_with_enum.priv_enum" "ptype obj_with_enum.priv_enum" {
-        -re "type = enum ClassWithEnum::PrivEnum \{ ?red, green, blue, yellow = 42 ?\}$nl$gdb_prompt $" {
+        -re "type = enum ClassWithEnum::PrivEnum (: unsigned (int|short|char) )?\{ ?(ClassWithEnum::)?red, (ClassWithEnum::)?green, (ClassWithEnum::)?blue, (ClassWithEnum::)?yellow = 42 ?\}$nl$gdb_prompt $" {
            pass "ptype obj_with_enum.priv_enum"
         }
-       -re "type = enum PrivEnum \{ ?red, green, blue, yellow = 42 ?\}$nl$gdb_prompt $" {
+       -re "type = enum PrivEnum \{ ?(ClassWithEnum::)?red, (ClassWithEnum::)?green, (ClassWithEnum::)?blue, (ClassWithEnum::)?yellow = 42 ?\}$nl$gdb_prompt $" {
            # gcc 2.95.3 -gdwarf-2
            # gcc 3.3.2 -gdwarf-2
            pass "ptype obj_with_enum.priv_enum"
@@ -450,7 +454,7 @@ proc test_enums {} {
     # stabs, we probably can't get this right; under DWARF-2, we can.
 
     cp_test_ptype_class \
-       "ptype obj_with_enum" "" "class" "ClassWithEnum" \
+       "obj_with_enum" "" "class" "ClassWithEnum" \
        {
            { field public "ClassWithEnum::PrivEnum priv_enum;" }
            { field public "int x;" }
@@ -468,7 +472,7 @@ proc test_enums {} {
     # See PR gdb/1588.
 
     gdb_test_multiple "print (ClassWithEnum::PrivEnum) 42" "print (ClassWithEnum::PrivEnum) 42" {
-       -re "\\$\[0-9\]+ = yellow$nl$gdb_prompt $" {
+       -re "\\$\[0-9\]+ = (ClassWithEnum::)?yellow$nl$gdb_prompt $" {
            pass "print (ClassWithEnum::PrivEnum) 42"
        }
        -re "A (parse|syntax) error in expression, near `42'.$nl$gdb_prompt $" {
@@ -479,7 +483,7 @@ proc test_enums {} {
     }
 
     gdb_test_multiple "print ('ClassWithEnum::PrivEnum') 42" "print ('ClassWithEnum::PrivEnum') 42" {
-       -re "\\$\[0-9\]+ = yellow$nl$gdb_prompt $" {
+       -re "\\$\[0-9\]+ = (ClassWithEnum::)?yellow$nl$gdb_prompt $" {
            # gcc 3.3.2 -gstabs+
            # gcc HEAD 2003-12-28 21:08:30 UTC -gstabs+
            pass "print ('ClassWithEnum::PrivEnum') 42"
@@ -497,11 +501,14 @@ proc test_enums {} {
 # Pointers to class members
 
 proc test_pointers_to_class_members {} {
-    gdb_test "print Bar::z" "\\$\[0-9\]+ = \\(int ?\\( ?Bar::& ?\\) ?\\) ?Bar::z"
-    gdb_test "print &Foo::x" "\\$\[0-9\]+ = \\(int ?\\( ?Foo::\\* ?\\) ?\\) ?&Foo::x"
+    gdb_test "print Bar::z" "Cannot reference non-static field \"z\""
+    gdb_test "print &Foo::x" "\\$\[0-9\]+ = &Foo::x"
     gdb_test "print (int)&Foo::x" "\\$\[0-9\]+ = 0"
     gdb_test "print (int)&Bar::y == 2*sizeof(int)" "\\$\[0-9\]+ = true"
 
+    gdb_test "ptype Bar::z" "type = int"
+    gdb_test "ptype &Bar::z" "type = int Bar::\\*"
+
     # TODO: this is a bogus test.  It's looking at a variable that
     # has not even been declared yet, so it's accessing random junk
     # on the stack and comparing that it's NOT equal to a specific
@@ -516,13 +523,13 @@ proc test_static_members {} {
     global hex
 
     gdb_test "print Foo::st" "\\$\[0-9\]+ = 100"
-    gdb_test "set foo.st = 200" "" ""
+    gdb_test_no_output "set foo.st = 200" ""
     gdb_test "print bar.st" "\\$\[0-9\]+ = 200"
-    gdb_test "print &foo.st" "\\$\[0-9\]+ = \\(int ?\\*\\) $hex"
-    gdb_test "print &Bar::st" "\\$\[0-9\]+ = \\(int ?\\*\\) $hex"
+    gdb_test "print &foo.st" "\\$\[0-9\]+ = \\(int ?\\*\\) $hex <Foo::st>"
+    gdb_test "print &Bar::st" "\\$\[0-9\]+ = \\(int ?\\*\\) $hex <Foo::st>"
     gdb_test "print *\$" "\\$\[0-9\]+ = 200"
 
-    gdb_test "set print static-members off" ""
+    gdb_test_no_output "set print static-members off"
     gdb_test "print csi" \
        "{x = 10, y = 20}" \
        "print csi without static members"
@@ -530,7 +537,7 @@ proc test_static_members {} {
        "{x = 30, y = 40}" \
        "print cnsi without static members"
 
-    gdb_test "set print static-members on" ""
+    gdb_test_no_output "set print static-members on"
     gdb_test "print csi" \
        "{x = 10, y = 20, static null = {x = 0, y = 0, static null = <same as static member of an already seen type>}}" \
        "print csi with static members"
@@ -540,27 +547,12 @@ proc test_static_members {} {
 }
 
 proc do_tests {} {
-    global prms_id
-    global bug_id
-    global subdir
-    global objdir
-    global srcdir
-    global binfile
     global gdb_prompt
     global nl
 
-    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
-
-    gdb_test "set language c++" "" ""
-    gdb_test "set width 0" "" ""
+    gdb_test_no_output "set language c++" ""
+    gdb_test_no_output "set width 0" ""
 
     if ![runto_main ] then {
        perror "couldn't run to breakpoint"
@@ -578,10 +570,17 @@ proc do_tests {} {
 
     gdb_breakpoint enums2
     gdb_test "continue" ".*Breakpoint .* enums2.*" "continue to enums2(\\(\\)|)"
-    gdb_test "finish" "" ""
+    # Leave enums2.  Make sure we reach the next line, in case there
+    # are any more instructions to finish the function call.
+    gdb_test_multiple "finish" "" {
+       -re "enums2 \\(\\);.*$gdb_prompt $" {
+           gdb_test "next" ".*" ""
+       }
+       -re "$gdb_prompt $" { }
+    }
     test_enums
 
-    gdb_test "finish" "" ""
+    gdb_test "finish" ".*" ""
     test_pointers_to_class_members
     test_static_members
 
@@ -619,6 +618,12 @@ proc do_tests {} {
            fail "calling method for small class"
        }
     }
+
+    gdb_test "print base1::Base1" "<.*Base1.*>" "print ctor of typedef class"
+    gdb_test "print base1::~Base1" "<.*~Base1(\\(\\))?>" \
+       "print dtor of typedef class"
+
+    gdb_test "list ByAnyOtherName::times" ".*int Foo::times.*"
 }
 
 do_tests
This page took 0.030855 seconds and 4 git commands to generate.