This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[patch, testsuite] replace bogus pointer-to-member test in gdb.cp/classes.exp
- From: Sandra Loosemore <sandra at codesourcery dot com>
- To: gdb-patches <gdb-patches at sourceware dot org>
- Date: Thu, 24 Sep 2015 19:44:03 -0600
- Subject: [patch, testsuite] replace bogus pointer-to-member test in gdb.cp/classes.exp
- Authentication-results: sourceware.org; auth=none
While I was working on this patch
https://sourceware.org/ml/gdb-patches/2015-09/msg00566.html
to fix a regexp bug in gdb.cp/classes.exp, I also took a look at the
long-standing failure involving the pmi comparison. In addition to the
uninitialized-variable problem noted in the comments (dating back to
2004!), casting a pointer-to-member to an int and expecting it to have
(or not have) any particular value seems highly dubious to me in terms
of correctness and portability. I also don't think it's representative
of actual use cases involving pointer-to-member variables in the debugger.
This patch addresses the uninitialized variable and potential
optimizing-away problems by moving the definition to file scope, and
changes the test to just printing its value.
OK to commit?
-Sandra
2015-09-24 Sandra Loosemore <sandra@codesourcery.com>
gdb/testsuite/
* gdb.cp/classes.cc (pmi): Move declaration out of main to file
scope.
* gdb.cp/classes.exp (test_pointers_to_class_members): Replace
bogus test involving cast and comparison of pmi with something
more useful.
diff --git a/gdb/testsuite/gdb.cp/classes.cc b/gdb/testsuite/gdb.cp/classes.cc
index 648452c..9fb687e 100644
--- a/gdb/testsuite/gdb.cp/classes.cc
+++ b/gdb/testsuite/gdb.cp/classes.cc
@@ -433,6 +433,7 @@ Foo::operator int() { return x; }
ByAnyOtherName foo(10, 11);
Bar bar(20, 21, 22);
+int Foo::* pmi = &Foo::y;
/* Use a typedef for the baseclass to exercise gnu-v3-abi.c:gnuv3_dynamic_class
recursion. It's important that the class itself have no name to make sure
@@ -599,11 +600,6 @@ main()
enums1 ();
register_class ();
- /* FIXME: pmi gets optimized out. Need to do some more computation with
- it or something. (No one notices, because the test is xfail'd anyway,
- but that probably won't always be true...). */
- int Foo::* pmi = &Foo::y;
-
/* Make sure the AIX linker doesn't remove the variable. */
v_tagless.one = 5;
diff --git a/gdb/testsuite/gdb.cp/classes.exp b/gdb/testsuite/gdb.cp/classes.exp
index 00f16fc..9dab864 100644
--- a/gdb/testsuite/gdb.cp/classes.exp
+++ b/gdb/testsuite/gdb.cp/classes.exp
@@ -509,12 +509,7 @@ proc test_pointers_to_class_members {} {
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"
+ gdb_test "print pmi" "\\$\[0-9\]+ = &Foo::y"
}
# Test static members.