This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

[RFA] Fix C++ enum tests


Several enum-related tests in gdb.c++/classes.exp have been failing
because they set a breakpoint on a line number that has moved.

This patch sets the breakpoint on a function rather than a line number,
fixes a spelling error, and encapsulates the enum tests in functions.

On sparc-sun-solaris2, the patch increases expected passes by 4 and
decreases unexpected failures by the same amount.

Okay to apply?

Nick Duffek
nsd@redhat.com

2000-07-08  Nick Duffek  <nsd@redhat.com>

	* gdb.c++/classes.exp (test_nonexistant_members): Fix name
	spelling.
	(test_enums): New procedure.  Move enum tests from end of script
	to here.  Set breakpoint on function name instead of line number.
	* gdb.c++/misc.cc (ClassWithEnum): Move past Foo definitions.
	(enums2): New marker function.
	(enums1): New function.
	(main): Call enums1().  Move enum tests to enums1().

Index: gdb/testsuite/gdb.c++/classes.exp
===================================================================
diff -up gdb/testsuite/gdb.c++/classes.exp gdb/testsuite/gdb.c++/classes.exp
--- gdb/testsuite/gdb.c++/classes.exp	Sat Jul  8 19:24:23 2000
+++ gdb/testsuite/gdb.c++/classes.exp	Sat Jul  8 19:24:14 2000
@@ -557,7 +557,7 @@ proc test_wrong_class_members {} {
 # Should give errors.
 #
 
-proc test_nonexistant_members {} {
+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"
@@ -570,6 +570,76 @@ proc test_nonexistant_members {} {
 }
 
 #
+# Examine a class with an enum field.
+#
+
+proc test_enums {} {
+    global gdb_prompt
+    global hp_aCC_compiler
+
+    # 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" }
+    }
+
+    # 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)" }
+    }
+
+    # 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" }
+    }
+
+    # 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" }
+    }
+
+    # ptype on the object
+    # g++ is putting out the wrong debug info.  This works with aCC
+    if {!$hp_aCC_compiler} {setup_xfail "*-*-*"}
+    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 "$gdb_prompt $"                     { fail "ptype obj_with_enum" }
+	timeout                             { fail "(timeout) ptype obj_with_enum" }
+    }
+
+    # g++ is putting out the wrong debug info.  This works with aCC
+    if {!$hp_aCC_compiler} {setup_xfail "*-*-*"}
+    send_gdb "print (ClassWithEnum::PrivEnum) 42\n"
+    gdb_expect {
+	-re "\\$\[0-9\]* = yellow.*$gdb_prompt $" { pass "print (ClassWithEnum::PrivEnum) 42" }
+	-re "$gdb_prompt $"                     { fail "print (ClassWithEnum::PrivEnum) 42" }
+	timeout                             { fail "(timeout) print (ClassWithEnum::PrivEnum) 42" }
+    }
+}
+
+#
 # Pointers to class members
 #
 
@@ -735,7 +805,13 @@ proc do_tests {} {
     if [ runto 'inheritance2(void)' ] then {
 	test_non_inherited_member_access
 	test_wrong_class_members
-	test_nonexistant_members
+	test_nonexistent_members
+    }
+
+    gdb_breakpoint enums2
+    if [ gdb_continue enums2 ]==0 then {
+	send_gdb "finish\n"
+	test_enums
     }
 
     if [istarget "mips-idt-*"] then {
@@ -758,7 +834,7 @@ proc do_tests {} {
 	gdb_reinitialize_dir $srcdir/$subdir
 	gdb_load $binfile
     }
- 
+
     if [ runto marker_reg1 ] then {
 
 	gdb_test "finish" "Run till exit from.*" "finish from marker_reg1"
@@ -782,90 +858,9 @@ proc do_tests {} {
 
 do_tests
 
-
-# Some additional tests for enums inside classes
-
-
-# set a breakpoint and go there
-send_gdb "break 516\n"   
-gdb_expect {   
-   -re "Breakpoint \[0-9\] at.*$gdb_prompt $" { pass "set break 516" }
-   -re "$gdb_prompt $"                     { fail "set break 516" }
-   timeout                             { fail "(timeout) set break 516" }
-}
-send_gdb "continue\n"   
-gdb_expect {   
-   -re "Continuing\\.\r\n\r\nBreakpoint \[0-9\]*, main....at.*misc\\.cc:516\r\n516.*\r\n$gdb_prompt $" { pass "continue" }
-   -re "$gdb_prompt $"                     { fail "continue" }
-   timeout                             { fail "(timeout) continue" }
-}
-
-# 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" }
-}
-
-# 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)" }
-}
-
-# 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" }
-}
-
-# 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" }
-}
-
-# ptype on the object
-# g++ is putting out the wrong debug info.  This works with aCC
-if {!$hp_aCC_compiler} {setup_xfail "*-*-*"}
-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 "$gdb_prompt $"                     { fail "ptype obj_with_enum" }
-   timeout                             { fail "(timeout) ptype obj_with_enum" }
-}
-
-# g++ is putting out the wrong debug info.  This works with aCC
-if {!$hp_aCC_compiler} {setup_xfail "*-*-*"}
-send_gdb "print (ClassWithEnum::PrivEnum) 42\n"   
-gdb_expect {   
-   -re "\\$\[0-9\]* = yellow.*$gdb_prompt $" { pass "print (ClassWithEnum::PrivEnum) 42" }
-   -re "$gdb_prompt $"                     { fail "print (ClassWithEnum::PrivEnum) 42" }
-   timeout                             { fail "(timeout) print (ClassWithEnum::PrivEnum) 42" }
-}
-
-
 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" }
 }
-
Index: gdb/testsuite/gdb.c++/misc.cc
===================================================================
diff -up gdb/testsuite/gdb.c++/misc.cc gdb/testsuite/gdb.c++/misc.cc
--- gdb/testsuite/gdb.c++/misc.cc	Sat Jul  8 19:24:27 2000
+++ gdb/testsuite/gdb.c++/misc.cc	Sat Jul  8 19:22:30 2000
@@ -393,13 +393,6 @@ class Bar : public Base1, public Foo {
   Bar (int i, int j, int k) : Base1 (10*k), Foo (i, j) { z = k; }
 };
 
-class ClassWithEnum {
-public:
-  enum PrivEnum { red, green, blue, yellow = 42 };
-  PrivEnum priv_enum;
-  int x;
-};
-
 int Foo::operator! () { return !x; }
 
 int Foo::times (int y) { return x * y; }
@@ -411,6 +404,29 @@ Foo::operator int() { return x; }
 Foo foo(10, 11);
 Bar bar(20, 21, 22);
 
+class ClassWithEnum {
+public:
+  enum PrivEnum { red, green, blue, yellow = 42 };
+  PrivEnum priv_enum;
+  int x;
+};
+
+void enums2 (void)
+{
+}
+
+/* classes.exp relies on statement order in this function for testing
+   enumeration fields.  */
+
+void enums1 ()
+{
+  ClassWithEnum obj_with_enum;
+  obj_with_enum.priv_enum = ClassWithEnum::red;
+  obj_with_enum.x = 0;
+  enums2 ();
+  obj_with_enum.priv_enum = ClassWithEnum::green;
+}
+
 class Contains_static_instance
 {
  public:
@@ -509,6 +525,7 @@ main()
   dummy();
   inheritance1 ();
   inheritance3 ();
+  enums1 ();
   register_class ();
 
   /* FIXME: pmi gets optimized out.  Need to do some more computation with
@@ -518,12 +535,6 @@ main()
 
   /* Make sure the AIX linker doesn't remove the variable.  */
   v_tagless.one = 5;
-
-  /* Class with enumeration inside it */ 
-  ClassWithEnum obj_with_enum;
-  obj_with_enum.priv_enum = ClassWithEnum::red;
-  obj_with_enum.x = 0;
-  obj_with_enum.priv_enum = ClassWithEnum::green;
 
   return foo.*pmi;
 }

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]