From patchwork Mon May 18 20:00:08 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Evans X-Patchwork-Id: 6784 Received: (qmail 16836 invoked by alias); 18 May 2015 20:00:13 -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 16820 invoked by uid 89); 18 May 2015 20:00:12 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.6 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mail-qc0-f201.google.com Received: from mail-qc0-f201.google.com (HELO mail-qc0-f201.google.com) (209.85.216.201) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Mon, 18 May 2015 20:00:11 +0000 Received: by qcvs11 with SMTP id s11so5541681qcv.1 for ; Mon, 18 May 2015 13:00:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:message-id:date:subject:from:to :content-type; bh=d63rkTt9Gl3AK/QikQGg2tnLzGUFq+08ScqyIXmK6/8=; b=XxaQ8l33U7t7YlWWRlIWs+m4XBSAwJ73LrRuxuL4FDF5R5H4aT7EL10a7ASLgusWVf +ovetfEXUeO+f19j/5yeJPAWOdHcny4AmXahUr6OxJN86U5/L8sEkpBKJxhGdosV7Hpg sG8xGi6ZLaECLKbp1WjKXlFaiFeLoG1Pad6x7VWcnrjTpsKUEl2LwJugl5rit5+I3y+S x3Wj97Cb9DavN+LyKtRyvkAqIgSQ1lTqgc5Zj+ZgaSqQWB4hClHCw6AnxgDO4q8/+bZW 3ROPoXgEIwnoVGIMdDuRcNw/zMYLv3hhpV3l26ogty6PXLNWdN+EKMgCg2MM2z5oAcBg 7nSA== X-Gm-Message-State: ALoCoQkGIY18GBdb2g8MPoCUY2v0mQNAoeDIFOp2HR1zMChTZubC0bJlb7JZaiKzdo0ex08ZRjMi22of3/6z8kG/Zg3KbHSrvTo72chLLWpoXu/+0+zomDTAs8UYGRQjG1L+jVohimEFqDoh2RejJ/0pet32M/kmscJBjL9WusSuMMTymNq+jWQ= MIME-Version: 1.0 X-Received: by 10.52.188.225 with SMTP id gd1mr35491522vdc.2.1431979208302; Mon, 18 May 2015 13:00:08 -0700 (PDT) Message-ID: Date: Mon, 18 May 2015 20:00:08 +0000 Subject: [PATCH] add domain arg to cp_lookup_nested_symbol_1 From: Doug Evans To: gdb-patches@sourceware.org X-IsSubscribed: yes Hi. This patch is a cleanup of one bit of cp-namespace.c that I've wanted to make, but didn't have the impetus until now. This isn't something I introduced. E.g., in 7.6.2 cp-namespace.c:lookup_symbol_file calls cp_lookup_nested_symbol, ignoring the requested domain of its caller. The "domain" of a symbol is an integral part of symbol lookup (e.g., in C do I look up "foo" as a plain variable or as a struct?). In c++ the waters are a bit muddy because "class c" in STRUCT_DOMAIN also creates symbol "c" in VAR_DOMAIN. The calls to cp_lookup_nested_symbol_1 were ignoring the incoming domain and hardcoding a lookup in VAR_DOMAIN. It may be ok to get away with this, at least most of the time, but it can create confusion. Regression tested on amd64-linux. 2015-05-18 Doug Evans * cp-namespace.c (cp_lookup_nested_symbol): New arg "domain". All callers updated. (cp_lookup_nested_symbol_1, find_symbol_in_baseclass): Ditto. * cp-support.h (cp_lookup_nested_symbol): Update. diff --git a/gdb/c-exp.y b/gdb/c-exp.y index 84f3a33..f458545 100644 --- a/gdb/c-exp.y +++ b/gdb/c-exp.y @@ -3004,7 +3004,8 @@ classify_inner_name (struct parser_state *par_state, return ERROR; copy = copy_name (yylval.ssym.stoken); - yylval.ssym.sym = cp_lookup_nested_symbol (type, copy, block); + /* N.B. We assume the symbol can only be in VAR_DOMAIN. */ + yylval.ssym.sym = cp_lookup_nested_symbol (type, copy, block, VAR_DOMAIN); /* If no symbol was found, search for a matching base class named COPY. This will allow users to enter qualified names of class members diff --git a/gdb/cp-namespace.c b/gdb/cp-namespace.c index 0feeb35..ab7d0cb 100644 --- a/gdb/cp-namespace.c +++ b/gdb/cp-namespace.c @@ -37,6 +37,7 @@ static struct symbol * const char *nested_name, const char *concatenated_name, const struct block *block, + const domain_enum domain, int basic_lookup, int is_in_anonymous); static struct type *cp_lookup_transparent_type_loop (const char *name, @@ -308,7 +309,7 @@ cp_lookup_bare_symbol (const struct language_defn *langdef, return NULL; /* Look for symbol NAME in this class. */ - sym = cp_lookup_nested_symbol (type, name, block); + sym = cp_lookup_nested_symbol (type, name, block, domain); } return sym; @@ -370,8 +371,8 @@ cp_search_static_and_baseclasses (const char *name, /* Look for a symbol named NESTED in this class. The caller is assumed to have already have done a basic lookup of NAME. So we pass zero for BASIC_LOOKUP to cp_lookup_nested_symbol_1 here. */ - sym = cp_lookup_nested_symbol_1 (klass_type, nested, name, block, 0, - is_in_anonymous); + sym = cp_lookup_nested_symbol_1 (klass_type, nested, name, block, domain, + 0, is_in_anonymous); do_cleanups (cleanup); return sym; @@ -906,7 +907,8 @@ cp_find_type_baseclass_by_name (struct type *parent_type, const char *name) static struct symbol * find_symbol_in_baseclass (struct type *parent_type, const char *name, - const struct block *block, int is_in_anonymous) + const struct block *block, const domain_enum domain, + int is_in_anonymous) { int i; struct symbol *sym; @@ -931,7 +933,7 @@ find_symbol_in_baseclass (struct type *parent_type, const char *name, xsnprintf (concatenated_name, len, "%s::%s", base_name, name); sym = cp_lookup_nested_symbol_1 (base_type, name, concatenated_name, - block, 1, is_in_anonymous); + block, domain, 1, is_in_anonymous); if (sym != NULL) break; } @@ -940,8 +942,8 @@ find_symbol_in_baseclass (struct type *parent_type, const char *name, return sym; } -/* Helper function to look up NESTED_NAME in CONTAINER_TYPE within the - context of BLOCK. +/* Helper function to look up NESTED_NAME in CONTAINER_TYPE and in DOMAIN + and within the context of BLOCK. NESTED_NAME may have scope ("::"). CONTAINER_TYPE needn't have been "check_typedef'd" yet. CONCATENATED_NAME is the fully scoped spelling of NESTED_NAME, it is @@ -957,6 +959,7 @@ cp_lookup_nested_symbol_1 (struct type *container_type, const char *nested_name, const char *concatenated_name, const struct block *block, + const domain_enum domain, int basic_lookup, int is_in_anonymous) { struct symbol *sym; @@ -970,7 +973,7 @@ cp_lookup_nested_symbol_1 (struct type *container_type, if (basic_lookup) { - sym = cp_basic_lookup_symbol (concatenated_name, block, VAR_DOMAIN, + sym = cp_basic_lookup_symbol (concatenated_name, block, domain, is_in_anonymous); if (sym != NULL) return sym; @@ -982,7 +985,7 @@ cp_lookup_nested_symbol_1 (struct type *container_type, C++ compliant and more assumptions could make it too magic. */ /* First search in this symtab, what we want is possibly there. */ - sym = lookup_symbol_in_static_block (concatenated_name, block, VAR_DOMAIN); + sym = lookup_symbol_in_static_block (concatenated_name, block, domain); if (sym != NULL) return sym; @@ -993,7 +996,7 @@ cp_lookup_nested_symbol_1 (struct type *container_type, which we just searched. */ if (!is_in_anonymous) { - sym = lookup_static_symbol (concatenated_name, VAR_DOMAIN); + sym = lookup_static_symbol (concatenated_name, domain); if (sym != NULL) return sym; } @@ -1003,7 +1006,7 @@ cp_lookup_nested_symbol_1 (struct type *container_type, if (TYPE_N_BASECLASSES (container_type) > 0) { sym = find_symbol_in_baseclass (container_type, nested_name, block, - is_in_anonymous); + domain, is_in_anonymous); if (sym != NULL) return sym; } @@ -1013,12 +1016,14 @@ cp_lookup_nested_symbol_1 (struct type *container_type, /* Look up a symbol named NESTED_NAME that is nested inside the C++ class or namespace given by PARENT_TYPE, from within the context - given by BLOCK. Return NULL if there is no such nested symbol. */ + given by BLOCK, and in DOMAIN. + Return NULL if there is no such nested symbol. */ struct symbol * cp_lookup_nested_symbol (struct type *parent_type, const char *nested_name, - const struct block *block) + const struct block *block, + const domain_enum domain) { /* type_name_no_tag_or_error provides better error reporting using the original type. */ @@ -1031,9 +1036,10 @@ cp_lookup_nested_symbol (struct type *parent_type, const char *type_name = type_name_no_tag (saved_parent_type); fprintf_unfiltered (gdb_stdlog, - "cp_lookup_nested_symbol (%s, %s, %s)\n", + "cp_lookup_nested_symbol (%s, %s, %s, %s)\n", type_name != NULL ? type_name : "unnamed", - nested_name, host_address_to_string (block)); + nested_name, host_address_to_string (block), + domain_name (domain)); } switch (TYPE_CODE (parent_type)) @@ -1060,8 +1066,8 @@ cp_lookup_nested_symbol (struct type *parent_type, is_in_anonymous = cp_is_in_anonymous (concatenated_name); sym = cp_lookup_nested_symbol_1 (parent_type, nested_name, - concatenated_name, block, 1, - is_in_anonymous); + concatenated_name, block, domain, + 1, is_in_anonymous); if (symbol_lookup_debug) { diff --git a/gdb/cp-support.h b/gdb/cp-support.h index cbff610..e92d6e7 100644 --- a/gdb/cp-support.h +++ b/gdb/cp-support.h @@ -211,7 +211,8 @@ extern struct symbol *cp_lookup_symbol_imports_or_template extern struct symbol *cp_lookup_nested_symbol (struct type *parent_type, const char *nested_name, - const struct block *block); + const struct block *block, + const domain_enum domain); struct type *cp_lookup_transparent_type (const char *name);