From: Keith Seitz <keiths@redhat.com>
To: gdb-patches@sourceware.org
Subject: [RFA] Typedef support for linespecs
Date: Wed, 11 Nov 2009 22:49:00 -0000 [thread overview]
Message-ID: <4AFB3F69.9070107@redhat.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 1030 bytes --]
Hi,
CVS HEAD currently fails if a user does something like:
class foo
{
public:
void a_function (void) { }
};
typedef MyFoo foo;
MyFoo instance;
(gdb) list MyFoo::a_function
This happens because when we lookup "MyFoo", lookup_prefix_sym will only
search STRUCT_DOMAIN, and it won't find "MyFoo", since typedefs live in
VAR_DOMAIN.
The attached patch attempts to address this issue by searching
VAR_DOMAIN if the search through STRUCT_DOMAIN fails.
[In case I am not always explicit: This patch introduces no regressions
or failures/errors of any kind with the test suite on x86 linux.]
Comments/Questions/Concerns?
Keith
ChangeLog
2009-11-11 Keith Seitz <keiths@redhat.com>
* linespec.c (lookup_prefix_sym): Lookup the symbol
in both STRUCT_DOMAIN and VAR_DOMAIN.
testsuite/ChangeLog
2009-11-11 Keith Seitz <keiths@redhat.com>
* gdb.cp/classes.cc (ByAnyOtherName): Add typedef and
use it instead of "Foo".
* gdb.cp/classes.exp (do_tests): Add a test to access
a method through a typedef'd class name.
[-- Attachment #2: linespec-typedef.patch --]
[-- Type: text/plain, Size: 2689 bytes --]
Index: linespec.c
===================================================================
RCS file: /cvs/src/src/gdb/linespec.c,v
retrieving revision 1.92
diff -u -p -r1.92 linespec.c
--- linespec.c 19 Oct 2009 09:51:41 -0000 1.92
+++ linespec.c 11 Nov 2009 22:37:47 -0000
@@ -1428,6 +1428,7 @@ lookup_prefix_sym (char **argptr, char *
{
char *p1;
char *copy;
+ struct symbol *sym;
/* Extract the class name. */
p1 = p;
@@ -1446,7 +1447,26 @@ lookup_prefix_sym (char **argptr, char *
/* At this point p1->"::inA::fun", p->"inA::fun" copy->"AAA",
argptr->"inA::fun" */
- return lookup_symbol (copy, 0, STRUCT_DOMAIN, 0);
+ sym = lookup_symbol (copy, 0, STRUCT_DOMAIN, 0);
+ if (sym == NULL)
+ {
+ /* Typedefs are in VAR_DOMAIN so the above symbol lookup will
+ fail when the user attempts to lookup a method of a class
+ via a typedef'd name (NOT via the class's name, which is already
+ handled in symbol_matches_domain). So try the lookup again
+ using VAR_DOMAIN (where typedefs live) and double-check that we
+ found a struct/class type. */
+ struct symbol *s = lookup_symbol (copy, 0, VAR_DOMAIN, 0);
+ if (s != NULL)
+ {
+ struct type *t = SYMBOL_TYPE (s);
+ CHECK_TYPEDEF (t);
+ if (TYPE_CODE (t) == TYPE_CODE_STRUCT)
+ return s;
+ }
+ }
+
+ return sym;
}
/* This finds the method COPY in the class whose type is T and whose
Index: testsuite/gdb.cp/classes.cc
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.cp/classes.cc,v
retrieving revision 1.7
diff -u -p -r1.7 classes.cc
--- testsuite/gdb.cp/classes.cc 21 Sep 2009 19:23:22 -0000 1.7
+++ testsuite/gdb.cp/classes.cc 11 Nov 2009 22:37:48 -0000
@@ -417,6 +417,8 @@ class Foo
int times (int y);
};
+typedef Foo ByAnyOtherName;
+
class Bar : public Base1, public Foo {
public:
int z;
@@ -431,7 +433,7 @@ int Foo::st = 100;
Foo::operator int() { return x; }
-Foo foo(10, 11);
+ByAnyOtherName foo(10, 11);
Bar bar(20, 21, 22);
class ClassWithEnum {
Index: testsuite/gdb.cp/classes.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.cp/classes.exp,v
retrieving revision 1.22
diff -u -p -r1.22 classes.exp
--- testsuite/gdb.cp/classes.exp 21 Sep 2009 19:23:22 -0000 1.22
+++ testsuite/gdb.cp/classes.exp 11 Nov 2009 22:37:48 -0000
@@ -636,6 +636,8 @@ proc do_tests {} {
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
next reply other threads:[~2009-11-11 22:49 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-11-11 22:49 Keith Seitz [this message]
2009-11-11 23:02 ` Daniel Jacobowitz
2009-11-11 23:35 ` Keith Seitz
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4AFB3F69.9070107@redhat.com \
--to=keiths@redhat.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox