This is the mail archive of the
gdb-patches@sources.redhat.com
mailing list for the GDB project.
Re: [Jim Blandy <jimb@redhat.com>] RFA: Check that `Local' is not in scope when it shouldn't be
- From: Jim Blandy <jimb at redhat dot com>
- To: gdb-patches at sources dot redhat dot com
- Date: 04 Feb 2003 16:53:48 -0500
- Subject: Re: [Jim Blandy <jimb@redhat.com>] RFA: Check that `Local' is not in scope when it shouldn't be
- References: <vt2bs3gpmfb.fsf@zenia.red-bean.com>
Okay, here's a revision of my patch to gdb.c++/local.{c,exp} that
correctly recognizes the two bugs where they occur:
- GDB prints 'class Local' incorrectly
- GDB misunderstands the scope in which 'class Local' is visible
I believe it flags them as known failures in the appropriate way.
David Carlton originally asked:
> I'm confused: don't you want to do the first 'ptype Local' _before_
> going up from foobar? In which case your added test might as well
> happen after you go up from foobar but before running to marker2.
The test doesn't go up from foobar; it goes up from marker1, which is
called from foobar, so the "up" makes foobar the current scope.
Michael Chastain corrected the way I'd written the second kfail
patch. I believe I've done it right this time --- so that if the
output changes from the current known incorrect output to anything
other than the correct output, the known failure will become a
straight failure.
I couldn't figure out, though, why folks were advising me to use
setup_kfail with a pattern that always matches, instead of simply
calling kfail directly. So I just used kfail.
Whip me, beat me, make me write bad checks.
gdb/testsuite/ChangeLog:
2003-02-04 Jim Blandy <jimb@redhat.com>
* gdb.c++/local.exp: Don't expect Local to be in scope in main;
it's local to foobar. Check for it there, and check that it's not
present in main.
* gdb.c++/local.cc (marker2): New function.
(foobar): Call marker1.
(main): Call marker2 instead of marker1.
Index: gdb/testsuite/gdb.c++/local.cc
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.c++/local.cc,v
retrieving revision 1.2
diff -c -r1.2 local.cc
*** gdb/testsuite/gdb.c++/local.cc 10 Apr 2002 03:52:21 -0000 1.2
--- gdb/testsuite/gdb.c++/local.cc 4 Feb 2003 21:07:07 -0000
***************
*** 4,9 ****
--- 4,12 ----
{
}
+ void marker2 (void)
+ {
+ }
int foobar (int x)
{
***************
*** 20,25 ****
--- 23,30 ----
static Local l1;
char c;
+ marker1 ();
+
l.loc1 = 23;
c = l.loc_foo('x');
***************
*** 56,61 ****
il.ilc = 'b';
il.ip = &c;
! marker1();
}
}
--- 61,66 ----
il.ilc = 'b';
il.ip = &c;
! marker2();
}
}
Index: gdb/testsuite/gdb.c++/local.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.c++/local.exp,v
retrieving revision 1.10
diff -c -r1.10 local.exp
*** gdb/testsuite/gdb.c++/local.exp 14 Jan 2003 04:34:46 -0000 1.10
--- gdb/testsuite/gdb.c++/local.exp 4 Feb 2003 21:07:07 -0000
***************
*** 67,73 ****
continue
}
! gdb_test "up" ".*main.*" "up from marker1"
# Local classes in g++ get names like "main.1::InnerLocal", just like local
# static variables. Some targets use "___" instead of ".".
--- 67,73 ----
continue
}
! gdb_test "up" ".*foobar.*" "up from marker1"
# Local classes in g++ get names like "main.1::InnerLocal", just like local
# static variables. Some targets use "___" instead of ".".
***************
*** 102,115 ****
gdb_expect {
-re "type = class Local \{\[\r\n\t \]*public:\[\r\n\t \]*int loc1;\[\r\n\t \]*char loc_foo\\((const *|)char\\);\[\r\n\t \]*\}.*$gdb_prompt $" { pass "ptype Local" }
-re "type = class Local \{\[\r\n\t \]*public:\[\r\n\t \]*int loc1;\[\r\n\t \]*char loc_foo\\((const *|)char\\);\[\r\n\t \]*char loc_foo\\((const *|)char\\);\[\r\n\t \]*\}.*$gdb_prompt $" {
! # setup_kfail "gdb/483"
! fail "ptype Local (gdb/483)"
}
-re "type = class Local \{\[\r\n\t \]*public:\[\r\n\t \]*int loc1;\[\r\n\t \]*Local & operator *=\\((foobar__Fi${sep}::|)Local const *&\\);\[\r\n\t \]*Local\\((foobar__Fi${sep}::|)Local const *&\\);\[\r\n\t \]*Local\\((void|)\\);\[\r\n\t \]*char loc_foo\\(char\\);\[\r\n\t \]*\}.*$gdb_prompt $" { pass "ptype Local" }
-re "type = class Local \{\r\n\[\t \]*public:\r\n\[\t \]*int loc1;\r\n\r\n\[\t \]*char loc_foo\\(char\\);\r\n\[\t \]*\\(Local at.*local\\.cc:\[0-9\]*\\)\r\n\}.*$gdb_prompt $" { xpass "ptype Local (old aCC)" }
-re ".*$gdb_prompt $" { fail "ptype Local" }
timeout { fail "(timeout) ptype Local" }
}
# DTS CLLbs14316 and CLLbs17058
# coulter - I added a clause for HP's aCC compiler. We print out the type
--- 102,144 ----
gdb_expect {
-re "type = class Local \{\[\r\n\t \]*public:\[\r\n\t \]*int loc1;\[\r\n\t \]*char loc_foo\\((const *|)char\\);\[\r\n\t \]*\}.*$gdb_prompt $" { pass "ptype Local" }
-re "type = class Local \{\[\r\n\t \]*public:\[\r\n\t \]*int loc1;\[\r\n\t \]*char loc_foo\\((const *|)char\\);\[\r\n\t \]*char loc_foo\\((const *|)char\\);\[\r\n\t \]*\}.*$gdb_prompt $" {
! kfail "gdb/483" "ptype Local"
}
-re "type = class Local \{\[\r\n\t \]*public:\[\r\n\t \]*int loc1;\[\r\n\t \]*Local & operator *=\\((foobar__Fi${sep}::|)Local const *&\\);\[\r\n\t \]*Local\\((foobar__Fi${sep}::|)Local const *&\\);\[\r\n\t \]*Local\\((void|)\\);\[\r\n\t \]*char loc_foo\\(char\\);\[\r\n\t \]*\}.*$gdb_prompt $" { pass "ptype Local" }
-re "type = class Local \{\r\n\[\t \]*public:\r\n\[\t \]*int loc1;\r\n\r\n\[\t \]*char loc_foo\\(char\\);\r\n\[\t \]*\\(Local at.*local\\.cc:\[0-9\]*\\)\r\n\}.*$gdb_prompt $" { xpass "ptype Local (old aCC)" }
-re ".*$gdb_prompt $" { fail "ptype Local" }
timeout { fail "(timeout) ptype Local" }
}
+
+ gdb_test "break marker2"
+ gdb_test "continue" "Continuing\\..*Breakpoint \[0-9\]+, marker2.*" \
+ "continuing to marker2"
+
+ gdb_test "up" ".*main.*" "up from marker2"
+
+ # Make sure that `Local' isn't in scope here; it's local to foobar.
+ # setup_kfail "gdb/825"
+ send_gdb "ptype Local\n"
+ set eol "\[\t \]*\[\r\n\]+\[\t \]*"
+ gdb_expect {
+ -re "No symbol \"Local\" in current context.*${gdb_prompt} $" {
+ pass "Local out of scope"
+ }
+ -re "ptype Local${eol}type = class Local {${eol} public:${eol} int loc1;${eol}${eol} Local & operator=\\(Local const&\\);${eol} Local\\(Local const&\\);${eol} Local\\(\\);${eol} char loc_foo\\(char\\);${eol}}${eol}${gdb_prompt} " {
+ # GCC emits STABS debugging information in a way that doesn't
+ # properly preserve the scoping of local classes. I think
+ # we'd need to start using Sun's extensions to stabs to get
+ # this right.
+ kfail gdb/825 "Local out of scope"
+ }
+ -re ".*${gdb_prompt} $" {
+ fail "Local out of scope"
+ }
+ timeout {
+ fail "Local out of scope (timeout)"
+ }
+ }
+
# DTS CLLbs14316 and CLLbs17058
# coulter - I added a clause for HP's aCC compiler. We print out the type