-# Copyright 1992, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
-# 2003 Free Software Foundation, Inc.
+# Copyright 1992-2015 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.
-
-# Please email any bugs, comments, and/or additions to this file to:
-# bug-gdb@prep.ai.mit.edu
+# 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 ws "\[\r\n\t \]+"
set nl "\[\r\n\]+"
-if $tracelevel then {
- strace $tracelevel
-}
-
if { [skip_cplus_tests] } { continue }
-set testfile "misc"
-set srcfile ${testfile}.cc
-set binfile ${objdir}/${subdir}/${testfile}
+load_lib "cp-support.exp"
-# Create and source the file that provides information about the compiler
-# used to compile the test case.
+standard_testfile .cc
-if [get_compiler_info ${binfile} "c++"] {
+if {[prepare_for_testing $testfile.exp $testfile $srcfile {debug c++}]} {
return -1
}
-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."
-}
-
-#
# Test ptype of class objects.
-#
proc test_ptype_class_objects {} {
- global gdb_prompt
- global ws
- global nl
- # Note that struct members are public by default, so we don't print
- # "public:" for the public members of structs.
- # Accept it if gdb just fails to distinguish between
- # class and struct, and everything else is OK.
+ # Simple type.
- send_gdb "ptype struct default_public_struct\n"
- gdb_expect {
- -re "type = struct default_public_struct \{${ws}int a;${ws}int b;$nl\}$nl$gdb_prompt $" {
- pass "ptype struct default_public_struct"
- }
- -re "type = class default_public_struct \{$nl.*int a;${ws}int b;$nl.*\}$nl$gdb_prompt $" {
- pass "ptype struct default_public_struct"
+ cp_test_ptype_class \
+ "struct default_public_struct" "" "struct" "default_public_struct" \
+ {
+ { field public "int a;" }
+ { field public "int b;" }
}
- -re ".*$gdb_prompt $" { fail "ptype struct default_public_struct" }
- timeout { fail "ptype struct default_public_struct (timeout)" ; return }
- }
- # Note that struct members are public by default, so we don't print
- # "public:" for the public members of structs.
- # Accept it if gdb just fails to distinguish between
- # class and struct, and everything else is OK.
+ # Another simple type.
- send_gdb "ptype struct explicit_public_struct\n"
- gdb_expect {
- -re "type = struct explicit_public_struct \{${ws}int a;${ws}int b;$nl.*\}$nl$gdb_prompt $" {
- pass "ptype struct explicit_public_struct"
- }
- -re "type = class explicit_public_struct \{$nl.*int a;${ws}int b;$nl.*\}$nl$gdb_prompt $" {
- pass "ptype struct explicit_public_struct"
+ cp_test_ptype_class \
+ "struct explicit_public_struct" "" "struct" "explicit_public_struct" \
+ {
+ { field public "int a;" }
+ { field public "int b;" }
}
- -re ".*$gdb_prompt $" { fail "ptype struct explicit_public_struct" }
- timeout { fail "ptype struct explicit_public_struct (timeout)" ; return }
- }
- # Accept it if gdb just fails to distinguish between
- # class and struct, and everything else is OK.
+ # Another simple type.
- send_gdb "ptype struct protected_struct\n"
- gdb_expect {
- -re "type = struct protected_struct \{${ws}protected:${ws}int a;${ws}int b;$nl\}$nl$gdb_prompt $" {
- pass "ptype struct protected_struct"
- }
- -re "type = class protected_struct \{${ws}protected:${ws}int a;${ws}int b;$nl.*\}$nl$gdb_prompt $" {
- pass "ptype struct protected_struct"
+ cp_test_ptype_class \
+ "struct protected_struct" "" "struct" "protected_struct" \
+ {
+ { field protected "int a;" }
+ { field protected "int b;" }
}
- -re ".*$gdb_prompt $" { fail "ptype struct protected_struct" }
- timeout { fail "ptype struct protected_struct (timeout)" ; return }
- }
- # Accept it if gdb just fails to distinguish between
- # class and struct, and everything else is OK.
+ # Another simple type.
- send_gdb "ptype struct private_struct\n"
- gdb_expect {
- -re "type = struct private_struct \{${ws}private:${ws}int a;${ws}int b;$nl\}$nl$gdb_prompt $" {
- pass "ptype struct private_struct"
- }
- -re "type = class private_struct \{${ws}private:${ws}int a;${ws}int b;$nl.*\}$nl$gdb_prompt $" {
- pass "ptype struct private_struct"
+ cp_test_ptype_class \
+ "struct private_struct" "" "struct" "private_struct" \
+ {
+ { field private "int a;" }
+ { field private "int b;" }
}
- -re ".*$gdb_prompt $" { fail "ptype struct private_struct" }
- timeout { fail "ptype struct private_struct (timeout)" ; return }
- }
- # Accept it if gdb just fails to distinguish between
- # class and struct, and everything else is OK.
+ # A bigger type.
- send_gdb "ptype struct mixed_protection_struct\n"
- gdb_expect {
- -re "type = struct mixed_protection_struct \{${ws}int a;${ws}int b;${ws}private:${ws}int c;${ws}int d;${ws}protected:${ws}int e;${ws}int f;${ws}public:${ws}int g;${ws}private:${ws}int h;${ws}protected:${ws}int i;$nl\}$nl$gdb_prompt $" {
- pass "ptype struct mixed_protection_struct"
- }
- -re "type = struct mixed_protection_struct \{${ws}public:${ws}int a;${ws}int b;${ws}private:${ws}int c;${ws}int d;${ws}protected:${ws}int e;${ws}int f;${ws}public:${ws}int g;${ws}private:${ws}int h;${ws}protected:${ws}int i;$nl.*\}$nl$gdb_prompt $" {
- pass "ptype struct mixed_protection_struct (extra public)"
- }
- -re "type = class mixed_protection_struct \{${ws}public:${ws}int a;${ws}int b;${ws}private:${ws}int c;${ws}int d;${ws}protected:${ws}int e;${ws}int f;${ws}public:${ws}int g;${ws}private:${ws}int h;${ws}protected:${ws}int i;$nl.*\}$nl$gdb_prompt $" {
- pass "ptype struct mixed_protection_struct"
+ cp_test_ptype_class \
+ "struct mixed_protection_struct" "" "struct" "mixed_protection_struct" \
+ {
+ { field public "int a;" }
+ { field public "int b;" }
+ { field private "int c;" }
+ { field private "int d;" }
+ { field protected "int e;" }
+ { field protected "int f;" }
+ { field public "int g;" }
+ { field private "int h;" }
+ { field protected "int i;" }
+ }
+
+ # All that again with "class" instead of "struct".
+ # gdb does not care about the difference anyways.
+
+ cp_test_ptype_class \
+ "class public_class" "" "class" "public_class" \
+ {
+ { field public "int a;" }
+ { field public "int b;" }
}
- -re ".*$gdb_prompt $" { fail "ptype struct mixed_protection_struct" }
- timeout { fail "ptype struct mixed_protection_struct (timeout)" ; return }
- }
- # Accept it if gdb just fails to distinguish between
- # class and struct, and everything else is OK.
+ # Another simple type.
- send_gdb "ptype class public_class\n"
- gdb_expect {
- -re "type = class public_class \{${ws}public:${ws}int a;${ws}int b;$nl.*\}$nl$gdb_prompt $" {
- pass "ptype class public_class"
- }
- -re "type = struct public_class \{${ws}int a;${ws}int b;$nl\}$nl$gdb_prompt $" {
- pass "ptype class public_class"
+ cp_test_ptype_class \
+ "class protected_class" "" "class" "protected_class" \
+ {
+ { field protected "int a;" }
+ { field protected "int b;" }
}
- -re ".*$gdb_prompt $" { fail "ptype class public_class" }
- timeout { fail "ptype class public_class (timeout)" ; return }
- }
- send_gdb "ptype class protected_class\n"
- gdb_expect {
- -re "type = class protected_class \{${ws}protected:${ws}int a;${ws}int b;$nl.*\}$nl$gdb_prompt $" {
- pass "ptype class protected_class"
- }
- -re "type = struct protected_class \{${ws}int a;${ws}int b;$nl\}$nl$gdb_prompt $" {
- fail "ptype class protected_class"
+ # Another simple type.
+
+ cp_test_ptype_class \
+ "class default_private_class" "" "class" "default_private_class" \
+ {
+ { field private "int a;" }
+ { field private "int b;" }
}
- -re ".*$gdb_prompt $" { fail "ptype class protected_class" }
- timeout { fail "ptype class protected_class (timeout)" ; return }
- }
- # Accept it if gdb just emits a superflous "private:"
- # attribute, since classes default to private and for consistency with
- # structs (where we don't print the "public:" attribute) we don't print
- # the "private:" attribute.
+ # Another simple type.
- send_gdb "ptype class default_private_class\n"
- gdb_expect {
- -re "type = class default_private_class \{${ws}int a;${ws}int b;$nl.*\}$nl$gdb_prompt $" {
- pass "ptype class default_private_class"
- }
- -re "type = class default_private_class \{${ws}private:${ws}int a;${ws}int b;$nl.*\}$nl$gdb_prompt $" {
- pass "ptype class default_private_class"
+ cp_test_ptype_class \
+ "class explicit_private_class" "" "class" "explicit_private_class" \
+ {
+ { field private "int a;" }
+ { field private "int b;" }
}
- -re ".*$gdb_prompt $" { fail "ptype class default_private_class" }
- timeout { fail "ptype class default_private_class (timeout)" ; return }
- }
- send_gdb "ptype class explicit_private_class\n"
- gdb_expect {
- -re "type = class explicit_private_class \{${ws}private:${ws}int a;${ws}int b;$nl.*\}$nl$gdb_prompt $" {
- pass "ptype class explicit_private_class"
- }
- -re "type = class explicit_private_class \{${ws}int a;${ws}int b;$nl.*\}$nl$gdb_prompt $" {
- pass "ptype class explicit_private_class"
- }
- -re "type = struct explicit_private_class \{${ws}int a;${ws}int b;$nl.*\}$nl$gdb_prompt $" {
- fail "ptype class explicit_private_class"
- }
- -re ".*$gdb_prompt $" { fail "ptype class explicit_private_class" }
- timeout { fail "ptype class explicit_private_class (timeout)" ; return }
- }
+ # A bigger type.
- send_gdb "ptype class mixed_protection_class\n"
- gdb_expect {
- -re "type = class mixed_protection_class \{${ws}public:${ws}int a;${ws}int b;${ws}private:${ws}int c;${ws}int d;${ws}protected:${ws}int e;${ws}int f;${ws}public:${ws}int g;${ws}private:${ws}int h;${ws}protected:${ws}int i;$nl.*\}$nl$gdb_prompt $" {
- pass "ptype class mixed_protection_class"
- }
- -re "type = struct mixed_protection_class \{${ws}int a;${ws}int b;${ws}int c;${ws}int d;${ws}int e;${ws}int f;${ws}int g;${ws}int h;${ws}int i;$nl.*\}$nl$gdb_prompt $" {
- fail "ptype class mixed_protection_class"
- }
- -re ".*$gdb_prompt $" { fail "ptype class mixed_protection_class" }
- timeout { fail "ptype class mixed_protection_class (timeout)" ; return }
- }
+ cp_test_ptype_class \
+ "class mixed_protection_class" "" "class" "mixed_protection_class" \
+ {
- # This class does not use any C++-specific features, so it's fine for
- # it to print as "struct".
- send_gdb "ptype class A\n"
- gdb_expect {
- -re "type = (class|struct) A \{(${ws}public:|)${ws}int a;${ws}int x;((${ws}A & operator=\\(A const ?&\\);)|(${ws}A\\((A const|const A) ?&\\);)|(${ws}A\\((void|)\\);))*${ws}\}$nl$gdb_prompt $" {
- pass "ptype class A"
- }
- -re ".*$gdb_prompt $" {
- fail "ptype class A"
- }
- timeout {
- fail "ptype class A (timeout)"
- return
+ { field public "int a;" }
+ { field public "int b;" }
+ { field private "int c;" }
+ { field private "int d;" }
+ { field protected "int e;" }
+ { field protected "int f;" }
+ { field public "int g;" }
+ { field private "int h;" }
+ { field protected "int i;" }
}
- }
- send_gdb "ptype class B\n"
- gdb_expect {
- -re "type = class B : public A \{${ws}public:${ws}int b;${ws}int x;${ws}B & operator=\\(B const ?&\\);${ws}B\\((B const|const B) ?&\\);${ws}B\\((void|)\\);${ws}\}$nl$gdb_prompt $" {
- pass "ptype class B"
- }
- -re "type = class B : public A \{${ws}public:${ws}int b;${ws}int x;((${ws}B & operator=\\(B const ?&\\);)|(${ws}B\\(B const ?&\\);)|(${ws}B\\((void|)\\);))*${ws}\}$nl$gdb_prompt $" {
- pass "ptype class B (obsolescent gcc or gdb)"
- }
- -re ".*$gdb_prompt $" {
- fail "ptype class B"
- }
- timeout {
- fail "ptype class B (timeout)"
- return
- }
- }
+ # Here are some classes with inheritance.
- send_gdb "ptype class C\n"
- gdb_expect {
- -re "type = class C : public A \{${ws}public:${ws}int c;${ws}int x;${ws}C & operator=\\(C const ?&\\);${ws}C\\((C const|const C) ?&\\);${ws}C\\((void|)\\);${ws}\}$nl$gdb_prompt $" {
- pass "ptype class C"
- }
- -re "type = class C : public A \{${ws}public:${ws}int c;${ws}int x;((${ws}C & operator=\\(C const ?&\\);)|(${ws}C\\(C const ?&\\);)|(${ws}C\\((void|)\\);))*${ws}\}$nl$gdb_prompt $" {
- pass "ptype class C (obsolescent gcc or gdb)"
- }
- -re ".*$gdb_prompt $" {
- fail "ptype class C"
- }
- timeout {
- fail "ptype class C (timeout)"
- return
- }
- }
+ # Base class.
- send_gdb "ptype class D\n"
- gdb_expect {
- -re "type = class D : public B, public C \{${ws}public:${ws}int d;${ws}int x;${ws}D & operator=\\(D const ?&\\);${ws}D\\((D const|const D) ?&\\);${ws}D\\((void|)\\);${ws}\}$nl$gdb_prompt $" {
- pass "ptype class D"
- }
- -re "type = class D : public B, public C \{${ws}public:${ws}int d;${ws}int x;((${ws}D & operator=\\(D const ?&\\);)|(${ws}D\\(D const ?&\\);)|(${ws}D\\((void|)\\);))*${ws}\}$nl$gdb_prompt $" {
- pass "ptype class D (obsolescent gcc or gdb)"
- }
- -re ".*$gdb_prompt $" {
- fail "ptype class D"
- }
- timeout {
- fail "ptype class D (timeout)"
- return
+ cp_test_ptype_class \
+ "class A" "" "class" "A" \
+ {
+ { field public "int a;" }
+ { field public "int x;" }
}
- }
- send_gdb "ptype class E\n"
- gdb_expect {
- -re "type = class E : public D \{${ws}public:${ws}int e;${ws}int x;${ws}E & operator=\\(E const ?&\\);${ws}E\\((E const|const E) ?&\\);${ws}E\\((void|)\\);${ws}\}$nl$gdb_prompt $" {
- pass "ptype class E"
- }
- -re "type = class E : public D \{${ws}public:${ws}int e;${ws}int x;((${ws}E & operator=\\(E const ?&\\);)|(${ws}E\\((E const|const E) ?&\\);)|(${ws}E\\((void|)\\);))*${ws}\}$nl$gdb_prompt $" {
- pass "ptype class E"
- }
- -re ".*$gdb_prompt $" {
- fail "ptype class E"
- }
- timeout {
- fail "ptype class E (timeout)"
- return
- }
- }
+ # Derived class.
- # With g++ 2.x and stabs debug info, we misinterpret static methods
- # whose name matches their argument mangling.
- send_gdb "ptype class Static\n"
- gdb_expect {
- -re "type = (class|struct) Static \{(${ws}public:|)${ws}Static & operator=\\(Static const ?&\\);${ws}Static\\((Static const|const Static) ?&\\);${ws}Static\\((void|)\\);${ws}static void ii\\(int, int\\);${ws}\}$nl$gdb_prompt $" {
- pass "ptype class Static"
- }
- -re "type = (class|struct) Static \{(${ws}public:|)${ws}static void ii\\(int, int\\);${ws}\}$nl$gdb_prompt $" {
- pass "ptype class Static"
- }
- -re ".*$gdb_prompt $" {
- fail "ptype class Static"
- }
- timeout {
- fail "ptype class Static (timeout)"
- return
+ cp_test_ptype_class \
+ "class B" "" "class" "B" \
+ {
+ { base "public A" }
+ { field public "int b;" }
+ { field public "int x;" }
}
- }
- send_gdb "ptype class vA\n"
- gdb_expect {
- -re "type = (class|struct) vA \{(${ws}public:|)${ws}int va;${ws}int vx;${ws}\}$nl$gdb_prompt $" {
- pass "ptype class vA"
- }
- -re "type = (class|struct) vA \{(${ws}public:|)${ws}int va;${ws}int vx;${ws}vA & operator=\\(vA const ?&\\);${ws}vA\\((vA const|const vA) ?&\\);${ws}vA\\((void|)\\);${ws}\}$nl$gdb_prompt $" {
- pass "ptype class vA"
- }
- -re "type = (class|struct) vA \{(${ws}public:|)${ws}int va;${ws}int vx;((${ws}vA & operator=\\(vA const ?&\\);)|(${ws}vA\\(vA const ?&\\);)|(${ws}vA\\((void|)\\);))*${ws}\}$nl$gdb_prompt $" {
- pass "ptype class vA (obsolescent gcc or gdb)"
+ # Derived class.
+
+ cp_test_ptype_class \
+ "class C" "" "class" "C" \
+ {
+ { base "public A" }
+ { field public "int c;" }
+ { field public "int x;" }
}
- -re ".*$gdb_prompt $" {
- fail "ptype class vA"
+
+ # Derived class, multiple inheritance.
+
+ cp_test_ptype_class \
+ "class D" "" "class" "D" \
+ {
+ { base "public B" }
+ { base "public C" }
+ { field public "int d;" }
+ { field public "int x;" }
}
- timeout {
- fail "ptype class vA (timeout)"
- return
+
+ # Derived class.
+
+ cp_test_ptype_class \
+ "class E" "" "class" "E" \
+ {
+ { base "public D" }
+ { field public "int e;" }
+ { field public "int x;" }
+ }
+
+ # This is a break from inheritance tests.
+ #
+ # gcc 2.X with stabs (stabs or stabs+?) used to have a problem with
+ # static methods whose name is the same as their argument mangling.
+
+ cp_test_ptype_class \
+ "class Static" "" "class" "Static" \
+ {
+ { method public "static void ii(int, int);" }
}
- }
- # Accept the form with embedded GNU style mangled virtual table constructs
- # for now, but with a FIXME. At some future point, gdb should use a
- # portable representation for the virtual table constructs.
+ # Here are some virtual inheritance tests.
- # The format of a g++ virtual base pointer.
- set vbptr "(_vb\[$.\]|__vb_)\[0-9\]?"
+ # A virtual base class.
- send_gdb "ptype class vB\n"
- gdb_expect {
- -re "type = class vB : public virtual vA \{${ws}public:${ws}int vb;${ws}int vx;${ws}vB & operator=\\(vB const ?&\\);${ws}vB\\((vB const|const vB) ?&\\);${ws}vB\\((void|)\\);${ws}\}$nl$gdb_prompt $" {
- pass "ptype class vB"
- }
- -re "type = class vB : public virtual vA \{${ws}private:${ws}vA \\*${vbptr}vA;${ws}public:${ws}int vb;${ws}int vx;${ws}vB & operator=\\(vB const ?&\\);${ws}vB\\(int, vB const ?&\\);${ws}vB\\(int\\);${ws}\}$nl$gdb_prompt $" {
- setup_xfail "*-*-*"
- fail "ptype class vB (FIXME: non-portable virtual table constructs)"
- }
- -re "type = class vB : public virtual vA \{${ws}public:${ws}int vb;${ws}int vx;${ws}\}$nl$gdb_prompt $" {
- pass "ptype class vB"
- }
- -re "type = class vB : public virtual vA \{${ws}private:${ws}vA \\*_vb.vA;${ws}public:${ws}int vb;${ws}int vx;((${ws}vB & operator=\\(vB const ?&\\);)|(${ws}vB\\(int, vB const ?&\\);)|(${ws}vB\\(int\\);))*${ws}\}$nl$gdb_prompt $" {
- setup_xfail "*-*-*"
- fail "ptype class vB (FIXME) (obsolescent gcc or gdb)"
- }
- -re ".*$gdb_prompt $" {
- fail "ptype class vB"
- }
- timeout {
- fail "ptype class vB (timeout)"
- return
+ cp_test_ptype_class \
+ "class vA" "" "class" "vA" \
+ {
+ { field public "int va;" }
+ { field public "int vx;" }
}
- }
- # Accept the form with embedded GNU style mangled virtual table constructs
- # for now, but with a FIXME. At some future point, gdb should use a
- # portable representation for the virtual table constructs.
+ # A derived class with a virtual base.
- send_gdb "ptype class vC\n"
- gdb_expect {
- -re "type = class vC : public virtual vA \{${ws}public:${ws}int vc;${ws}int vx;${ws}vC & operator=\\(vC const ?&\\);${ws}vC\\((vC const|const vC) ?&\\);${ws}vC\\((void|)\\);${ws}\}$nl$gdb_prompt $" {
- pass "ptype class vC"
- }
- -re "type = class vC : public virtual vA \{${ws}private:${ws}vA \\*${vbptr}vA;${ws}public:${ws}int vc;${ws}int vx;${ws}vC & operator=\\(vC const ?&\\);${ws}vC\\(int, vC const ?&\\);${ws}vC\\(int\\);${ws}\}$nl$gdb_prompt $" {
- setup_xfail "*-*-*"
- fail "ptype class vC (FIXME: non-portable virtual table constructs)"
- }
- -re "type = class vC : public virtual vA \{${ws}public:${ws}int vc;${ws}int vx;${ws}\}$nl$gdb_prompt $" {
- pass "ptype class vC"
- }
- -re "type = class vC : public virtual vA \{${ws}private:${ws}vA \\*_vb.vA;${ws}public:${ws}int vc;${ws}int vx;((${ws}vC & operator=\\(vC const ?&\\);)|(${ws}vC\\(int, vC const ?&\\);)|(${ws}vC\\(int\\);))*${ws}\}$nl$gdb_prompt $" {
- setup_xfail "*-*-*"
- fail "ptype class vC (FIXME) (obsolescent gcc or gdb)"
- }
- -re ".*$gdb_prompt $" {
- fail "ptype class vC"
- }
- timeout {
- fail "ptype class vC (timeout)"
- return
+ cp_test_ptype_class \
+ "class vB" "" "class" "vB" \
+ {
+ { base "public virtual vA" }
+ { vbase "vA" }
+ { field public "int vb;" }
+ { field public "int vx;" }
}
- }
- # Accept the form with embedded GNU style mangled virtual table constructs
- # for now, but with a FIXME. At some future point, gdb should use a
- # portable representation for the virtual table constructs.
+ # Another derived class with a virtual base.
- send_gdb "ptype class vD\n"
- gdb_expect {
- -re "type = class vD : public virtual vB, public virtual vC \{${ws}public:${ws}int vd;${ws}int vx;${ws}vD & operator=\\(vD const ?&\\);${ws}vD\\((vD const|const vD) ?&\\);${ws}vD\\((void|)\\);${ws}\}$nl$gdb_prompt $" {
- pass "ptype class vD"
- }
- -re "type = class vD : public virtual vB, public virtual vC \{${ws}private:${ws}vC \\*${vbptr}vC;${ws}vB \\*${vbptr}vB;${ws}public:${ws}int vd;${ws}int vx;${ws}vD & operator=\\(vD const ?&\\);${ws}vD\\(int, vD const ?&\\);${ws}vD\\(int\\);${ws}\}$nl$gdb_prompt $" {
- setup_xfail "*-*-*"
- fail "ptype class vD (FIXME: non-portable virtual table constructs)"
- }
- -re "type = class vD : public virtual vB, public virtual vC \{${ws}public:${ws}int vd;${ws}int vx;${ws}\}$nl$gdb_prompt $" {
- pass "ptype class vD"
- }
- -re "type = class vD : public virtual vB, public virtual vC \{${ws}private:${ws}vC \\*_vb.vC;${ws}vB \\*_vb.vB;${ws}public:${ws}int vd;${ws}int vx;((${ws}vD & operator=\\(vD const ?&\\);)|(${ws}vD\\(int, vD const ?&\\);)|(${ws}vD\\(int\\);))*${ws}\}$nl$gdb_prompt $" {
- setup_xfail "*-*-*"
- fail "ptype class vD (FIXME) (obsolescent gcc or gdb)"
- }
- -re ".*$gdb_prompt $" {
- fail "ptype class vD"
- }
- timeout {
- fail "ptype class vD (timeout)"
- return
+ cp_test_ptype_class \
+ "class vC" "" "class" "vC" \
+ {
+ { base "public virtual vA" }
+ { vbase "vA" }
+ { field public "int vc;" }
+ { field public "int vx;" }
}
- }
- # Accept the form with embedded GNU style mangled virtual table constructs
- # for now, but with a FIXME. At some future point, gdb should use a
- # portable representation for the virtual table constructs.
+ # A classic diamond class.
- send_gdb "ptype class vE\n"
- gdb_expect {
- -re "type = class vE : public virtual vD \{${ws}public:${ws}int ve;${ws}int vx;${ws}vE & operator=\\(vE const ?&\\);${ws}vE\\((vE const|const vE) ?&\\);${ws}vE\\((void|)\\);${ws}\}$nl$gdb_prompt $" {
- pass "ptype class vE"
- }
- -re "type = class vE : public virtual vD \{${ws}private:${ws}vD \\*${vbptr}vD;${ws}public:${ws}int ve;${ws}int vx;${ws}vE & operator=\\(vE const ?&\\);${ws}vE\\(int, vE const ?&\\);${ws}vE\\(int\\);${ws}\}$nl$gdb_prompt $" {
- setup_xfail "*-*-*"
- fail "ptype class vE (FIXME: non-portable virtual table constructs)"
- }
- -re "type = class vE : public virtual vD \{${ws}public:${ws}int ve;${ws}int vx;${ws}\}$nl$gdb_prompt $" {
- pass "ptype class vE"
- }
- -re "type = class vE : public virtual vD \{${ws}private:${ws}vD \\*_vb.vD;${ws}public:${ws}int ve;${ws}int vx;((${ws}vE & operator=\\(vE const ?&\\);)|(${ws}vE\\(int, vE const ?&\\);)|(${ws}vE\\(int\\);))*${ws}\}$nl$gdb_prompt $" {
- setup_xfail "*-*-*"
- fail "ptype class vE (FIXME) (obsolescent gcc or gdb)"
- }
- -re ".*$gdb_prompt $" {
- fail "ptype class vE"
- }
- timeout {
- fail "ptype class vE (timeout)"
- return
+ cp_test_ptype_class \
+ "class vD" "" "class" "vD" \
+ {
+ { base "public virtual vB" }
+ { base "public virtual vC" }
+ { vbase "vC" }
+ { vbase "vB" }
+ { field public "int vd;" }
+ { field public "int vx;" }
}
- }
- send_gdb "ptype class Base1\n"
- gdb_expect {
- -re "type = class Base1 \{${ws}public:${ws}int x;${ws}Base1 & operator=\\(Base1 const ?&\\);${ws}Base1\\(((Base1 const)|(const Base1)) ?&\\);${ws}Base1\\(int\\);${ws}\}$nl$gdb_prompt $" {
- pass "ptype class Base1"
- }
- -re "type = class Base1 \{${ws}public:${ws}int x;${ws}Base1\\(int\\);${ws}\}$nl$gdb_prompt $" {
- pass "ptype class Base1"
- }
- -re "type = class Base1 \{${ws}public:${ws}int x;((${ws}Base1 & operator=\\(Base1 const ?&\\);)|(${ws}Base1\\(Base1 const ?&\\);)|(${ws}Base1\\(int\\);))*${ws}\}$nl$gdb_prompt $" {
- pass "ptype class Base1 (obsolescent gcc or gdb)"
- }
- -re ".*$gdb_prompt $" {
- fail "ptype class Base1"
- }
- timeout {
- fail "ptype class Base1 (timeout)"
- return
- }
- }
+ # A class derived from a diamond class.
- send_gdb "ptype class Foo\n"
- gdb_expect {
- -re "type = class Foo \{${ws}public:${ws}int x;${ws}int y;${ws}static int st;\r\n${ws}Foo\\(int, int\\);${ws}int operator!\\((void|)\\);${ws}operator int\\((void|)\\);${ws}int times\\(int\\);$nl\}$nl$gdb_prompt $" {
- pass "ptype class Foo"
- }
- -re "type = class Foo \{${ws}public:${ws}int x;${ws}int y;${ws}static int st;${ws}Foo & operator=\\(Foo const ?&\\);${ws}Foo\\((Foo const|const Foo) ?&\\);${ws}Foo\\(int, int\\);${ws}int operator!\\((void|)\\);${ws}operator int\\((void|)\\);${ws}int times\\(int\\);${ws}\}$nl$gdb_prompt $" {
- pass "ptype class Foo"
- }
- -re "type = class Foo \{${ws}public:${ws}int x;${ws}int y;${ws}static int st;((${ws}Foo & operator=\\(Foo const ?&\\);)|(${ws}Foo\\(Foo const ?&\\);)|(${ws}Foo\\(int, int\\);)|(${ws}int operator!\\((void|)\\);)|(${ws}int operator int\\((void|)\\);)|(${ws}int times\\(int\\);))*${ws}\}$nl$gdb_prompt $" {
- pass "ptype class Foo (obsolescent gcc or gdb)"
- }
- -re ".*$gdb_prompt $" {
- fail "ptype class Foo"
- }
- timeout {
- fail "ptype class Foo (timeout)"
- return
+ cp_test_ptype_class \
+ "class vE" "" "class" "vE" \
+ {
+ { base "public virtual vD" }
+ { vbase "vD" }
+ { field public "int ve;" }
+ { field public "int vx;" }
}
- }
- send_gdb "ptype class Bar\n"
- gdb_expect {
- -re "type = class Bar : public Base1, public Foo \{${ws}public:${ws}int z;${ws}Bar & operator=\\(Bar const ?&\\);${ws}Bar\\((Bar const|const Bar) ?&\\);${ws}Bar\\(int, int, int\\);${ws}\}$nl$gdb_prompt $" {
- pass "ptype class Bar"
+ # Another inheritance series.
+
+ # A base class.
+
+ cp_test_ptype_class \
+ "class Base1" "" "class" "Base1" \
+ {
+ { field public "int x;" }
+ { method public "Base1(int);" }
}
- -re "type = class Bar : public Base1, public Foo \{${ws}public:${ws}int z;((${ws}Bar & operator=\\(Bar const ?&\\);)|(${ws}Bar\\(Bar const ?&\\);)|(${ws}Bar\\(int, int, int\\);))*${ws}\}$nl$gdb_prompt $" {
- pass "ptype class Bar (obsolescent gcc or gdb)"
+
+ # Another base class.
+
+ cp_test_ptype_class \
+ "class Foo" "" "class" "Foo" \
+ {
+ { field public "int x;" }
+ { field public "int y;" }
+ { field public "static int st;" }
+ { method public "Foo(int, int);" }
+ { method public "int operator!();" }
+ { method public "operator int();" }
+ { method public "int times(int);" }
+ } \
+ "" \
+ {
+ {
+ "operator int();"
+ "int operator int();"
+ { setup_kfail "gdb/1497" "*-*-*" }
+ }
+ {
+ "operator int();"
+ "int operator int(void);"
+ { setup_kfail "gdb/1497" "*-*-*" }
+ }
}
- -re ".*$gdb_prompt $" {
- fail "ptype class Bar"
+
+ # A multiple inheritance derived class.
+
+ cp_test_ptype_class \
+ "class Bar" "" "class" "Bar" \
+ {
+ { base "public Base1" }
+ { base "public Foo" }
+ { field public "int z;" }
+ { method public "Bar(int, int, int);" }
}
- timeout {
- fail "ptype class Bar (timeout)"
- return
+
+ # 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.
-#
proc test_non_inherited_member_access {} {
- global gdb_prompt
# Print non-inherited members of g_A.
-
- gdb_test "print g_A.a" ".* = 1" "g_A.a incorrect"
-
- gdb_test "print g_A.x" ".* = 2" "g_A.x incorrect"
+ gdb_test "print g_A.a" ".* = 1"
+ gdb_test "print g_A.x" ".* = 2"
# Print non-inherited members of g_B.
-
- gdb_test "print g_B.b" ".* = 5" "g_B.b incorrect"
-
- gdb_test "print g_B.x" ".* = 6" "g_B.x incorrect"
+ gdb_test "print g_B.b" ".* = 5"
+ gdb_test "print g_B.x" ".* = 6"
# Print non-inherited members of g_C.
-
- gdb_test "print g_C.c" ".* = 9" "g_C.c incorrect"
-
- gdb_test "print g_C.x" ".* = 10" "g_C.x incorrect"
+ gdb_test "print g_C.c" ".* = 9"
+ gdb_test "print g_C.x" ".* = 10"
# Print non-inherited members of g_D.
-
- gdb_test "print g_D.d" ".* = 19" "g_D.d incorrect"
-
- gdb_test "print g_D.x" ".* = 20" "g_D.x incorrect"
+ gdb_test "print g_D.d" ".* = 19"
+ gdb_test "print g_D.x" ".* = 20"
# Print non-inherited members of g_E.
-
- gdb_test "print g_E.e" ".* = 31" "g_E.e incorrect"
-
- gdb_test "print g_E.x" ".* = 32" "g_E.x incorrect"
+ gdb_test "print g_E.e" ".* = 31"
+ gdb_test "print g_E.x" ".* = 32"
}
-#
-# Try access to non-members that are members of another class.
-# Should give errors.
-#
+# Test access to members of other classes.
+# gdb should refuse to print them.
+# (I feel old -- I remember when this was legal in C -- chastain).
proc test_wrong_class_members {} {
- global gdb_prompt
-
- gdb_test "print g_A.b" "There is no member( or method|) named b." "print g_A.b should be error"
-
- gdb_test "print g_B.c" "There is no member( or method|) named c." "print g_B.c should be error"
-
- gdb_test "print g_B.d" "There is no member( or method|) named d." "print g_B.d should be error"
-
- gdb_test "print g_C.b" "There is no member( or method|) named b." "print g_C.b should be error"
-
- gdb_test "print g_C.d" "There is no member( or method|) named d." "print g_C.d should be error"
-
- gdb_test "print g_D.e" "There is no member( or method|) named e." "print g_D.e should be error"
+ gdb_test "print g_A.b" "There is no member( or method|) named b."
+ gdb_test "print g_B.c" "There is no member( or method|) named c."
+ gdb_test "print g_B.d" "There is no member( or method|) named d."
+ gdb_test "print g_C.b" "There is no member( or method|) named b."
+ gdb_test "print g_C.d" "There is no member( or method|) named d."
+ gdb_test "print g_D.e" "There is no member( or method|) named e."
}
-#
-# Try access to non-members that are not members of any class.
-# Should give errors.
-#
+# Test access to names that are not members of any class.
proc test_nonexistent_members {} {
- global gdb_prompt
-
- gdb_test "print g_A.y" "There is no member( or method|) named y." "print g_A.y should be error"
-
- gdb_test "print g_B.z" "There is no member( or method|) named z." "print g_B.z should be error"
-
- gdb_test "print g_C.q" "There is no member( or method|) named q." "print g_C.q should be error"
-
- gdb_test "print g_D.p" "There is no member( or method|) named p." "print g_D.p should be error"
+ gdb_test "print g_A.y" "There is no member( or method|) named y."
+ gdb_test "print g_B.z" "There is no member( or method|) named z."
+ gdb_test "print g_C.q" "There is no member( or method|) named q."
+ gdb_test "print g_D.p" "There is no member( or method|) named p."
}
-#
# Call a method that expects a base class parameter with base, inherited,
# and unrelated class arguments.
-#
proc test_method_param_class {} {
- gdb_test "call class_param.Aptr_a (&g_A)" ".* = 1" "base class param->a"
- gdb_test "call class_param.Aptr_x (&g_A)" ".* = 2" "base class param->x"
- gdb_test "call class_param.Aptr_a (&g_B)" ".* = 3" "inherited class param->a"
- gdb_test "call class_param.Aptr_x (&g_B)" ".* = 4" "inherited class param->x"
- gdb_test "call class_param.Aref_a (g_A)" ".* = 1" "base class (¶m)->a"
- gdb_test "call class_param.Aref_x (g_A)" ".* = 2" "base class (¶m)->x"
- gdb_test "call class_param.Aref_a (g_B)" ".* = 3" "inherited class (¶m)->a"
- gdb_test "call class_param.Aref_x (g_B)" ".* = 4" "inherited class (¶m)->x"
- gdb_test "call class_param.Aval_a (g_A)" ".* = 1" "base class param.a"
- gdb_test "call class_param.Aval_x (g_A)" ".* = 2" "base class param.x"
- gdb_test "call class_param.Aval_a (g_B)" ".* = 3" "inherited class param.a"
- gdb_test "call class_param.Aval_x (g_B)" ".* = 4" "inherited class param.x"
+ gdb_test "call class_param.Aptr_a (&g_A)" ".* = 1"
+ gdb_test "call class_param.Aptr_x (&g_A)" ".* = 2"
+ gdb_test "call class_param.Aptr_a (&g_B)" ".* = 3"
+ gdb_test "call class_param.Aptr_x (&g_B)" ".* = 4"
+ gdb_test "call class_param.Aref_a (g_A)" ".* = 1"
+ gdb_test "call class_param.Aref_x (g_A)" ".* = 2"
+ gdb_test "call class_param.Aref_a (g_B)" ".* = 3"
+ gdb_test "call class_param.Aref_x (g_B)" ".* = 4"
+ gdb_test "call class_param.Aval_a (g_A)" ".* = 1"
+ gdb_test "call class_param.Aval_x (g_A)" ".* = 2"
+ gdb_test "call class_param.Aval_a (g_B)" ".* = 3"
+ gdb_test "call class_param.Aval_x (g_B)" ".* = 4"
gdb_test "call class_param.Aptr_a (&foo)" "Cannot resolve .*" "unrelated class *param"
gdb_test "call class_param.Aref_a (foo)" "Cannot resolve .*" "unrelated class ¶m"
gdb_test "call class_param.Aval_a (foo)" "Cannot resolve .*" "unrelated class param"
}
-#
# Examine a class with an enum field.
-#
proc test_enums {} {
global gdb_prompt
- global hp_aCC_compiler
+ global nl
# print the object
- send_gdb "print obj_with_enum\n"
- gdb_expect {
- -re "\\$\[0-9\]* = \\{priv_enum = red, x = 0\\}.*$gdb_prompt $" { pass "print obj_with_enum (1)" }
- -re "$gdb_prompt $" { fail "print obj_with_enum (1)" }
- timeout { fail "(timeout) print obj_with_enum (1)" }
- }
- send_gdb "next\n"
- gdb_expect {
- -re "$gdb_prompt $" { pass "next" }
- timeout { fail "(timeout) next" }
- }
+ # We match the enum values with and without qualifiers. As of
+ # 2008-08-21 we can output the qualifiers for DWARF-2.
- # print the object again
- send_gdb "print obj_with_enum\n"
- gdb_expect {
- -re "\\$\[0-9\]* = \\{priv_enum = green, x = 0\\}.*$gdb_prompt $" { pass "print obj_with_enum (2)" }
- -re "$gdb_prompt $" { fail "print obj_with_enum (2)" }
- timeout { fail "(timeout) print obj_with_enum (2)" }
- }
+ gdb_test "print obj_with_enum" \
+ "\\$\[0-9\]+ = \{priv_enum = (ClassWithEnum::)?red, x = 0\}" \
+ "print obj_with_enum (1)"
- # print out the enum member
- send_gdb "print obj_with_enum.priv_enum\n"
- gdb_expect {
- -re "\\$\[0-9\]* = green.*$gdb_prompt $" { pass "print obj_with_enum.priv_enum" }
- -re "$gdb_prompt $" { fail "print obj_with_enum.priv_enum" }
- timeout { fail "(timeout) print obj_with_enum.priv_enum" }
- }
+ # advance one line
- # ptype on the enum member
- # The third success case is a little dubious, but it's not clear what
- # ought to be required of a ptype on a private enum... -sts 19990324
- send_gdb "ptype obj_with_enum.priv_enum\n"
- gdb_expect {
- -re "type = enum ClassWithEnum::PrivEnum \\{red, green, blue, yellow = 42\\}.*$gdb_prompt $" { pass "ptype obj_with_enum.priv_enum" }
- -re "type = enum PrivEnum \\{red, green, blue, yellow = 42\\}.*$gdb_prompt $" { pass "ptype obj_with_enum.priv_enum" }
- -re "type = enum \\{red, green, blue, yellow = 42\\}.*$gdb_prompt $" { pass "ptype obj_with_enum.priv_enum" }
- -re "$gdb_prompt $" { fail "ptype obj_with_enum.priv_enum" }
- timeout { fail "(timeout) ptype obj_with_enum.priv_enum" }
- }
+ gdb_test "next" ".*"
- # ptype on the object
- send_gdb "ptype obj_with_enum\n"
- gdb_expect {
- -re "type = class ClassWithEnum \\{\r\n\[ \t\]*public:\r\n\[ \t\]*(enum |)ClassWithEnum::PrivEnum priv_enum;\r\n\[ \t\]*int x;\r\n\\}\r\n$gdb_prompt $" { pass "ptype obj_with_enum" }
- -re "type = class ClassWithEnum \\{\r\n\[ \t\]*public:\r\n\[ \t\]*(enum |)PrivEnum priv_enum;\r\n\[ \t\]*int x;.*\\}\r\n$gdb_prompt $"
- {
- # NOTE: carlton/2003-02-28: One could certainly argue that
- # this output is acceptable: PrivEnum is a member of
- # ClassWithEnum, so there's no need to explicitly qualify
- # its name with "ClassWithEnum::". The truth, though, is
- # that GDB is simply forgetting that PrivEnum is a member
- # of ClassWithEnum, so we do that output for a bad reason
- # instead of a good reason. Under stabs, we probably
- # can't get this right; under DWARF-2, we can.
- kfail "gdb/57" "ptype obj_with_enum"
- }
- -re "$gdb_prompt $" { fail "ptype obj_with_enum" }
- timeout { fail "(timeout) ptype obj_with_enum" }
- }
+ # print the object again
- # We'll do this test twice, because of a parser bug: see
- # PR gdb/826.
+ gdb_test "print obj_with_enum" \
+ "\\$\[0-9\]+ = \{priv_enum = (ClassWithEnum::)?green, x = 0\}" \
+ "print obj_with_enum (2)"
- send_gdb "print (ClassWithEnum::PrivEnum) 42\n"
- gdb_expect {
- -re "\\$\[0-9\]* = yellow.*$gdb_prompt $" { pass "print (ClassWithEnum::PrivEnum) 42" }
- -re "A parse error in expression, near `42'.\r\n$gdb_prompt $"
- { kfail "gdb/826" "print (ClassWithEnum::PrivEnum) 42" }
- -re "$gdb_prompt $" { fail "print (ClassWithEnum::PrivEnum) 42" }
- timeout { fail "(timeout) print (ClassWithEnum::PrivEnum) 42" }
- }
+ # print the enum member
- send_gdb "print ('ClassWithEnum::PrivEnum') 42\n"
- gdb_expect {
- -re "\\$\[0-9\]* = yellow.*$gdb_prompt $" { pass "print ('ClassWithEnum::PrivEnum') 42" }
- -re "No symbol \"ClassWithEnum::PrivEnum\" in current context.\r\n$gdb_prompt $"
- { kfail "gdb/57" "print ('ClassWithEnum::PrivEnum') 42" }
- -re "$gdb_prompt $" { fail "print ('ClassWithEnum::PrivEnum') 42" }
- timeout { fail "(timeout) print ('ClassWithEnum::PrivEnum') 42" }
- }
-}
+ gdb_test "print obj_with_enum.priv_enum" "\\$\[0-9\]+ = (ClassWithEnum::)?green"
-#
-# Pointers to class members
-#
+ # ptype on the enum member
-proc test_pointers_to_class_members {} {
- global gdb_prompt
- global decimal
- global nl
+ gdb_test_multiple "ptype obj_with_enum.priv_enum" "ptype obj_with_enum.priv_enum" {
+ -re "type = enum ClassWithEnum::PrivEnum (: unsigned int )?\{ ?(ClassWithEnum::)?red, (ClassWithEnum::)?green, (ClassWithEnum::)?blue, (ClassWithEnum::)?yellow = 42 ?\}$nl$gdb_prompt $" {
+ pass "ptype obj_with_enum.priv_enum"
+ }
+ -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"
+ }
+ -re "type = enum \{ ?red, green, blue, yellow = 42 ?\}$nl$gdb_prompt $" {
+ # This case case is a little dubious, but it's not clear what
+ # ought to be required of a ptype on a private enum...
+ # -sts 19990324
+ #
+ # It bugs me that this happens with gcc 3.
+ # -- chastain 2003-12-30
+ #
+ # gcc 2.95.3 -gstabs+
+ # gcc 3.3.2 -gstabs+
+ # gcc HEAD 2003-12-28 21:08:30 UTC -gstabs+
+ pass "ptype obj_with_enum.priv_enum"
+ }
+ }
- gdb_test "print Bar::z" ".* = .int\[ \]*\[( \]*Bar::&\[)\]+\[ \]*Bar::z" "print Bar::z"
+ # ptype on the object
- gdb_test "print &Foo::x" ".* = .int\[ \]*\[( \]*Foo::\[*)\]+\[ \]*&Foo::x" "print &Foo::x"
+ # NOTE: carlton/2003-02-28: One could certainly argue that plain
+ # "PrivEnum"
+ # is acceptable: PrivEnum is a member of ClassWithEnum, so
+ # there's no need to explicitly qualify its name with
+ # "ClassWithEnum::". The truth, though, is that GDB is simply
+ # forgetting that PrivEnum is a member of ClassWithEnum, so we do
+ # that output for a bad reason instead of a good reason. Under
+ # stabs, we probably can't get this right; under DWARF-2, we can.
+
+ cp_test_ptype_class \
+ "obj_with_enum" "" "class" "ClassWithEnum" \
+ {
+ { field public "ClassWithEnum::PrivEnum priv_enum;" }
+ { field public "int x;" }
+ } \
+ "" \
+ {
+ {
+ "ClassWithEnum::PrivEnum priv_enum;"
+ "PrivEnum priv_enum;"
+ { setup_kfail "gdb/57" "*-*-*" }
+ }
+ }
- gdb_test "print (int)&Foo::x" ".* = 0" "print (int)&Foo::x"
+ # I'll do this test two different ways, because of a parser bug.
+ # See PR gdb/1588.
- send_gdb "print (int)&Bar::y == 2*sizeof(int)\n"
- gdb_expect {
- -re ".* = true$nl$gdb_prompt $" {
- pass "print (int)&Bar::y == 2*sizeof(int)"
+ gdb_test_multiple "print (ClassWithEnum::PrivEnum) 42" "print (ClassWithEnum::PrivEnum) 42" {
+ -re "\\$\[0-9\]+ = (ClassWithEnum::)?yellow$nl$gdb_prompt $" {
+ pass "print (ClassWithEnum::PrivEnum) 42"
}
- -re "There is no field named y.*$gdb_prompt $" {
- setup_xfail "*-*-*"
- fail "print (int)&Bar::y == 2*sizeof(int)"
+ -re "A (parse|syntax) error in expression, near `42'.$nl$gdb_prompt $" {
+ # "parse error" is bison 1.35.
+ # "syntax error" is bison 1.875.
+ kfail "gdb/1588" "print (ClassWithEnum::PrivEnum) 42"
}
- -re ".*$gdb_prompt $" { fail "print (int)&Bar::y == 2*sizeof(int)" }
- timeout { fail "print (int)&Bar::y == 2*sizeof(int) (timeout)" ; return }
}
- send_gdb "next 2\n"
- setup_xfail "*-*-*"
- gdb_expect {
- -re "$decimal\[ \t\]+inheritance3 \[)(\]+;$nl$gdb_prompt $" {}
- -re ".*$gdb_prompt $" { fail "next to inheritance3" ; return }
+ gdb_test_multiple "print ('ClassWithEnum::PrivEnum') 42" "print ('ClassWithEnum::PrivEnum') 42" {
+ -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"
+ }
+ -re "No symbol \"ClassWithEnum::PrivEnum\" in current context.$nl$gdb_prompt $" {
+ # gcc 2.95.3 -gdwarf-2
+ # gcc 3.3.2 -gdwarf-2
+ # gcc HEAD 2003-12-28 21:08:30 UTC -gdwarf-2
+ # gcc 2.95.3 -gstabs+
+ kfail "gdb/57" "print ('ClassWithEnum::PrivEnum') 42"
+ }
}
- clear_xfail "*-*-*"
+}
- gdb_test "print (int)pmi == sizeof(int)" ".* = false" "print (int)pmi == sizeof(int)"
+# Pointers to class members
+
+proc test_pointers_to_class_members {} {
+ 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
+ # value. It's been like this since gdb 4.10 in 1993!
+ # -- chastain 2004-01-01
+ gdb_test "print (int)pmi == sizeof(int)" ".* = false"
}
-#
# Test static members.
-#
proc test_static_members {} {
- global gdb_prompt
global hex
- global nl
-
- send_gdb "print Foo::st\n"
- gdb_expect {
- -re ".* = 100$nl$gdb_prompt $" {
- pass "print Foo::st"
- }
- -re "There is no field named st.*$gdb_prompt $" {
- setup_xfail "*-*-*"
- fail "print Foo::st"
- }
- -re ".*$gdb_prompt $" { fail "print Foo::st" }
- timeout { fail "print Foo::st (timeout)" ; return }
- }
-
- send_gdb "set foo.st = 200\n"
- gdb_expect {
- -re ".*$gdb_prompt $" {}
- }
- send_gdb "print bar.st\n"
- gdb_expect {
- -re ".* = 200$nl$gdb_prompt $" {
- pass "print bar.st"
- }
- -re "There is no member( or method|) named st.*$gdb_prompt $" {
- setup_xfail "*-*-*"
- fail "print bar.st"
- }
- -re ".*$gdb_prompt $" { fail "print bar.st" }
- timeout { fail "print bar.st (timeout)" ; return }
- }
+ gdb_test "print Foo::st" "\\$\[0-9\]+ = 100"
+ 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 <Foo::st>"
+ gdb_test "print &Bar::st" "\\$\[0-9\]+ = \\(int ?\\*\\) $hex <Foo::st>"
+ gdb_test "print *\$" "\\$\[0-9\]+ = 200"
- send_gdb "print &foo.st\n"
- gdb_expect {
- -re ".* = .int \[*)\]+ $hex$nl$gdb_prompt $" {
- pass "print &foo.st"
- }
- -re "There is no member( or method|) named st.*$gdb_prompt $" {
- setup_xfail "*-*-*"
- fail "print &foo.st"
- }
- -re ".*$gdb_prompt $" { fail "print &foo.st" }
- timeout { fail "print &foo.st (timeout)" ; return }
- }
-
- set got_bar_st 0
- send_gdb "print &Bar::st\n"
- gdb_expect {
- -re ".* = .int \[*)\]+ $hex$nl$gdb_prompt $" {
- pass "print &Bar::st"
- set got_bar_st 1
- }
- -re "There is no field named st.*$gdb_prompt $" {
- setup_xfail "*-*-*"
- fail "print &Bar::st"
- }
- -re ".*$gdb_prompt $" { fail "print &Bar::st" }
- timeout { fail "print &Bar::st (timeout)" ; return }
- }
-
- if $got_bar_st then {
- gdb_test "print *\$" ".* = 200" "print *\$"
- }
-
- 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"
"{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"
}
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_test_no_output "set language c++" ""
+ gdb_test_no_output "set width 0" ""
- gdb_exit
- gdb_start
- gdb_reinitialize_dir $srcdir/$subdir
- gdb_load $binfile
+ if ![runto_main ] then {
+ perror "couldn't run to breakpoint"
+ return
+ }
- send_gdb "set language c++\n"
- gdb_expect -re "$gdb_prompt $"
- send_gdb "set width 0\n"
- gdb_expect -re "$gdb_prompt $"
+ gdb_breakpoint inheritance2
+ gdb_test "continue" ".*Breakpoint .* inheritance2.*" ""
- runto_main
test_ptype_class_objects
-
- if [ runto 'inheritance2' ] then {
- test_non_inherited_member_access
- test_wrong_class_members
- test_nonexistent_members
- test_method_param_class
- }
+ test_non_inherited_member_access
+ test_wrong_class_members
+ test_nonexistent_members
+ test_method_param_class
gdb_breakpoint enums2
- if [ gdb_continue "enums2(\\(\\)|)" ]==0 then {
- gdb_test "finish" "" ""
- test_enums
- }
-
- if [istarget "mips-idt-*"] then {
- # Restart because IDT/SIM runs out of file descriptors.
- gdb_exit
- gdb_start
- gdb_reinitialize_dir $srcdir/$subdir
- gdb_load $binfile
- }
-
- if [ runto_main ] then {
- test_pointers_to_class_members
- test_static_members
- }
-
- if [istarget "mips-idt-*"] then {
- # Restart because IDT/SIM runs out of file descriptors.
- gdb_exit
- gdb_start
- gdb_reinitialize_dir $srcdir/$subdir
- gdb_load $binfile
- }
-
- if [ runto marker_reg1 ] then {
-
- gdb_test "finish" "Run till exit from.*" "finish from marker_reg1"
-
- send_gdb "print v.method ()\n"
- gdb_expect {
- -re "= 82.*$gdb_prompt $" {
- pass "calling method for small class"
- }
- -re "Address requested for identifier .v. which is in register.*$gdb_prompt $" {
- setup_xfail "*-*-*" 2972
- fail "calling method for small class"
- }
- -re ".*$gdb_prompt $" { fail "calling method for small class" }
- timeout { fail "calling method for small class (timeout)" }
- eof { fail "calling method for small class (eof)" }
- }
- }
-
+ gdb_test "continue" ".*Breakpoint .* enums2.*" "continue to enums2(\\(\\)|)"
+ # 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" ".*" ""
+ test_pointers_to_class_members
+ test_static_members
+
+ # Now some random tests that were just thrown in here.
+
+ gdb_breakpoint marker_reg1
+ gdb_test "continue" ".*Breakpoint .* marker_reg1.*" ""
+ gdb_test "finish" "Run till exit from.*" "finish from marker_reg1"
+
+ # This class is so small that an instance of it can fit in a register.
+ # When gdb tries to call a method, it gets embarrassed about taking
+ # the address of a register.
+ #
+ # TODO: I think that message should be a PASS, not an XFAIL.
+ # gdb prints an informative message and declines to do something
+ # impossible.
+ #
+ # The method call actually succeeds if the compiler allocates very
+ # small classes in memory instead of registers. So this test does
+ # not tell us anything interesting if the call succeeds.
+ #
+ # -- chastain 2003-12-31
+ gdb_test_multiple "print v.method ()" "calling method for small class" {
+ -re "\\$\[0-9\]+ = 82$nl$gdb_prompt $" {
+ # gcc 3.3.2 -gdwarf-2
+ # gcc HEAD 2003-12-28 21:08:30 UTC -gdwarf-2
+ # gcc 3.3.2 -gstabs+
+ # gcc HEAD 2003-12-28 21:08:30 UTC -gstabs+
+ pass "calling method for small class"
+ }
+ -re "Address requested for identifier \"v\" which is in register .*$nl$gdb_prompt $" {
+ # gcc 2.95.3 -gdwarf-2
+ # gcc 2.95.3 -gstabs+
+ setup_xfail "*-*-*" 2972
+ 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
-
-send_gdb "maint demangle inheritance1__Fv\n"
-gdb_expect {
- -re "inheritance1\\(void\\).*$gdb_prompt $" { pass "demangle" }
- -re ".*$gdb_prompt $" { fail "demangle" }
- timeout { fail "(timeout) demangle" }
-}