From patchwork Thu Dec 18 12:33:29 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Evans X-Patchwork-Id: 4345 Received: (qmail 6969 invoked by alias); 18 Dec 2014 12:34:26 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 6956 invoked by uid 89); 18 Dec 2014 12:34:24 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.0 required=5.0 tests=AWL, BAYES_00, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-pa0-f50.google.com Received: from mail-pa0-f50.google.com (HELO mail-pa0-f50.google.com) (209.85.220.50) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Thu, 18 Dec 2014 12:34:23 +0000 Received: by mail-pa0-f50.google.com with SMTP id bj1so1356363pad.9 for ; Thu, 18 Dec 2014 04:34:21 -0800 (PST) X-Received: by 10.70.50.228 with SMTP id f4mr2937760pdo.27.1418906060991; Thu, 18 Dec 2014 04:34:20 -0800 (PST) Received: from seba.sebabeach.org.gmail.com (173-13-178-53-sfba.hfc.comcastbusiness.net. [173.13.178.53]) by mx.google.com with ESMTPSA id hc10sm6665980pbd.78.2014.12.18.04.34.19 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Dec 2014 04:34:20 -0800 (PST) From: Doug Evans To: gdb-patches@sourceware.org Subject: [PATCH 6/6] [PR 17684] Add c++ support Date: Thu, 18 Dec 2014 04:33:29 -0800 Message-ID: MIME-Version: 1.0 X-IsSubscribed: yes Hi. This patch adds support for looking up primitive types as symbols to the more complicated c++ symbol lookup machinery. 2014-12-18 Doug Evans * cp-namespace.c (cp_lookup_bare_symbol): New arg langdef. All callers updated. Try to find the symbol as a primitive type. (lookup_namespace_scope): New arg langdef. All callers updated. Call cp_lookup_bare_symbol directly for simple bare symbols. diff --git a/gdb/cp-namespace.c b/gdb/cp-namespace.c index 6599d45..9e9dce0 100644 --- a/gdb/cp-namespace.c +++ b/gdb/cp-namespace.c @@ -242,12 +242,18 @@ cp_basic_lookup_symbol (const char *name, const struct block *block, } /* Search bare symbol NAME in DOMAIN in BLOCK. - NAME is guaranteed to not have any scope (no "::"). + NAME is guaranteed to not have any scope (no "::") in its name, though + if for example NAME is a template spec then "::" may appear in the + argument list. + If LANGDEF is non-NULL then try to lookup NAME as a primitive type in + that language. Normally we wouldn't need LANGDEF but fortran also uses + this code. If SEARCH is non-zero then see if we can determine "this" from BLOCK, and if so then also search for NAME in that class. */ static struct symbol * -cp_lookup_bare_symbol (const char *name, const struct block *block, +cp_lookup_bare_symbol (const struct language_defn *langdef, + const char *name, const struct block *block, const domain_enum domain, int search) { struct symbol *sym; @@ -262,6 +268,25 @@ cp_lookup_bare_symbol (const char *name, const struct block *block, if (sym != NULL) return sym; + /* If we didn't find a definition for a builtin type in the static block, + search for it now. This is actually the right thing to do and can be + a massive performance win. E.g., when debugging a program with lots of + shared libraries we could search all of them only to find out the + builtin type isn't defined in any of them. This is common for types + like "void". */ + if (langdef != NULL && domain == VAR_DOMAIN) + { + struct gdbarch *gdbarch; + + if (block == NULL) + gdbarch = target_gdbarch (); + else + gdbarch = block_gdbarch (block); + sym = language_lookup_primitive_type_as_symbol (langdef, gdbarch, name); + if (sym != NULL) + return sym; + } + sym = lookup_global_symbol (name, block, domain); if (sym != NULL) return sym; @@ -378,7 +403,7 @@ cp_lookup_symbol_in_namespace (const char *namespace, const char *name, prefix_len = cp_entire_prefix_len (name); if (prefix_len == 0) - return cp_lookup_bare_symbol (name, block, domain, search); + return cp_lookup_bare_symbol (NULL, name, block, domain, search); /* This would be simpler if we just called cp_lookup_nested_symbol at this point. But that would require first looking up the containing @@ -753,7 +778,8 @@ cp_lookup_symbol_namespace (const char *scope, "x". */ static struct symbol * -lookup_namespace_scope (const char *name, +lookup_namespace_scope (const struct language_defn *langdef, + const char *name, const struct block *block, const domain_enum domain, const char *scope, @@ -775,14 +801,25 @@ lookup_namespace_scope (const char *name, new_scope_len += 2; } new_scope_len += cp_find_first_component (scope + new_scope_len); - sym = lookup_namespace_scope (name, block, domain, + sym = lookup_namespace_scope (langdef, name, block, domain, scope, new_scope_len); if (sym != NULL) return sym; } /* Okay, we didn't find a match in our children, so look for the - name in the current namespace. */ + name in the current namespace. + + If we there is no scope and we know we have a bare symbol, then short + circuit everything and call cp_lookup_bare_symbol directly. + This isn't an optimization, rather it allows us to pass LANGDEF which + is needed for primitive type lookup. The test doesn't have to be + perfect: if NAME is a bare symbol that our test doesn't catch (e.g., a + template symbol with "::" in the argument list) then + cp_lookup_symbol_in_namespace will catch it. */ + + if (scope_len == 0 && strchr (name, ':') == NULL) + return cp_lookup_bare_symbol (langdef, name, block, domain, 1); namespace = alloca (scope_len + 1); strncpy (namespace, scope, scope_len); @@ -817,7 +854,7 @@ cp_lookup_symbol_nonlocal (const struct language_defn *langdef, /* First, try to find the symbol in the given namespace, and all containing namespaces. */ - sym = lookup_namespace_scope (name, block, domain, scope, 0); + sym = lookup_namespace_scope (langdef, name, block, domain, scope, 0); /* Search for name in namespaces imported to this and parent blocks. */ if (sym == NULL)