From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18745 invoked by alias); 23 Sep 2010 14:48:13 -0000 Received: (qmail 18713 invoked by uid 22791); 23 Sep 2010 14:48:11 -0000 X-SWARE-Spam-Status: No, hits=-5.4 required=5.0 tests=AWL,BAYES_00,KAM_STOCKGEN,RCVD_IN_DNSWL_HI,SPF_HELO_PASS,TW_BJ,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 23 Sep 2010 14:48:01 +0000 Received: from int-mx08.intmail.prod.int.phx2.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o8NEm0GQ008750 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 23 Sep 2010 10:48:00 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx08.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o8NElxwW013556 for ; Thu, 23 Sep 2010 10:48:00 -0400 Received: from [10.15.16.129] (dhcp-10-15-16-129.yyz.redhat.com [10.15.16.129]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id o8NElxma015276 for ; Thu, 23 Sep 2010 10:47:59 -0400 Message-ID: <4C9B689F.9030304@redhat.com> Date: Thu, 23 Sep 2010 18:43:00 -0000 From: sami wagiaalla User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.8) Gecko/20100806 Fedora/3.1.2-1.fc13 Lightning/1.0b2pre Thunderbird/3.1.2 MIME-Version: 1.0 To: gdb-patches@sourceware.org Subject: Re: [patch 3/4 optional] Template Lookup References: <4C446F53.7000209@redhat.com> <4C7BC740.6090503@redhat.com> In-Reply-To: <4C7BC740.6090503@redhat.com> Content-Type: multipart/mixed; boundary="------------060100040304030100000207" X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2010-09/txt/msg00407.txt.bz2 This is a multi-part message in MIME format. --------------060100040304030100000207 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-length: 26 Updated patch attached. --------------060100040304030100000207 Content-Type: text/x-patch; name="template_lookup_3.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="template_lookup_3.patch" Content-length: 7735 Template Lookup 3: Template meta var learns about its instances. 2010-09-15 Sami Wagiaalla * symtab.h (symbol_add_template_instance): New function prototype. (symbol_get_template_instances): New function prototype. Created struct symbol_list_element. Created struct template_symbol. (instances): Add an instance of symbol_list_element to general_symbol_info * symtab.c (symbol_add_template_instance): New function. (symbol_get_template_instances): New function. * findvar.c (read_var_value): Print list of candidates when attempting to evaluate a LOC_TEMPLATE. * dwarf2read.c (add_template_variable): Find template variable and add instance reference to it. 2010-09-15 Sami Wagiaalla * gdb.cp/temp-op.exp: Test printing of template instances. diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index 848366a..0d3a34b 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -10520,7 +10520,7 @@ add_template_meta_symbol (struct symbol *symbol, struct pending **listhead, struct objfile *objfile) { const struct pending *iterator = *listhead; - struct symbol *template_sym; + struct template_meta_symbol *template_sym = NULL; struct symbol *iterator_sym; struct type *type; char *search_name; @@ -10534,7 +10534,7 @@ add_template_meta_symbol (struct symbol *symbol, struct pending **listhead, /* Has a template symbol for this symbol been added already ? */ for (iterator = *(listhead); - iterator != NULL; + iterator != NULL && template_sym == NULL; iterator = iterator->next) { for (i = iterator->nsyms - 1; i >= 0; --i) @@ -10543,25 +10543,39 @@ add_template_meta_symbol (struct symbol *symbol, struct pending **listhead, if (TYPE_CODE (SYMBOL_TYPE (iterator_sym)) == TYPE_CODE_TEMPLATE && strcmp (SYMBOL_SEARCH_NAME (iterator_sym), search_name) == 0) - return; + { + template_sym = (struct template_meta_symbol *) iterator_sym; + break; + } } } - /* This is a new template therefore add a new template symbol. */ - template_sym = (struct symbol *) obstack_alloc (&objfile->objfile_obstack, - sizeof (struct symbol)); - OBJSTAT (objfile, n_syms++); - memset (template_sym, 0, sizeof (struct symbol)); + if (template_sym == NULL) + { + /* Add a new template symbol. */ + template_sym = (struct template_meta_symbol *) + obstack_alloc (&objfile->objfile_obstack, + sizeof (struct template_meta_symbol)); - SYMBOL_SET_NAMES (template_sym, search_name, strlen (search_name), 0, objfile); - type = alloc_type (objfile); - TYPE_CODE (type) = TYPE_CODE_TEMPLATE; - SYMBOL_TYPE (template_sym) = type; + OBJSTAT (objfile, n_syms++); + memset (&template_sym->sym, 0, sizeof (struct symbol)); + + SYMBOL_SET_NAMES (&template_sym->sym, + search_name, + strlen (search_name), + 0, objfile); + + type = alloc_type (objfile); + TYPE_CODE (type) = TYPE_CODE_TEMPLATE; + SYMBOL_TYPE (&template_sym->sym) = type; - SYMBOL_DOMAIN (template_sym) = VAR_DOMAIN; - SYMBOL_CLASS (template_sym) = LOC_TEMPLATE; + SYMBOL_DOMAIN (&template_sym->sym) = VAR_DOMAIN; + SYMBOL_CLASS (&template_sym->sym) = LOC_TEMPLATE; + + add_symbol_to_list (&template_sym->sym, listhead); + } - add_symbol_to_list (template_sym, listhead); + symbol_add_template_instance (template_sym, symbol, objfile); } /* Given a pointer to a DWARF information entry, figure out if we need diff --git a/gdb/findvar.c b/gdb/findvar.c index f4749b7..1d2f2a8 100644 --- a/gdb/findvar.c +++ b/gdb/findvar.c @@ -35,6 +35,7 @@ #include "user-regs.h" #include "block.h" #include "objfiles.h" +#include "exceptions.h" /* Basic byte-swapping routines. All 'extract' functions return a host-format integer from a target-format integer at ADDR which is @@ -568,9 +569,20 @@ read_var_value (struct symbol *var, struct frame_info *frame) return v; case LOC_TEMPLATE: - error (_("Symbol represents a template and cannot be evaluated.")); - break; + { + const struct symbol_list_element *instance = + symbol_get_template_instances (var); + + printf_filtered ("Symbol represents a template and cannot be evaluated.\n"); + printf_filtered ("Did you mean:\n"); + while (instance != NULL) + { + printf_filtered (" %s\n", SYMBOL_NATURAL_NAME (instance->sym)); + instance = instance->next; + } + throw_error (NOT_FOUND_ERROR, " "); + } default: error (_("Cannot look up value of a botched symbol.")); break; diff --git a/gdb/symtab.c b/gdb/symtab.c index 068bf87..c0b9bec 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -344,6 +344,28 @@ gdb_mangle_name (struct type *type, int method_id, int signature_id) /* Initialize the cplus_specific structure. 'cplus_specific' should only be allocated for use with cplus symbols. */ +void +symbol_add_template_instance (struct template_meta_symbol *template_sym, + const struct symbol *instance, + struct objfile *objfile) +{ + struct symbol_list_element *new_instance = + OBSTACK_ZALLOC (&objfile->objfile_obstack, + struct symbol_list_element); + + new_instance->sym = instance; + new_instance->next = template_sym->instances; + template_sym->instances = new_instance; +} + +/* Return the list of known instances of this template symbol. */ + +const struct symbol_list_element * +symbol_get_template_instances (const struct symbol *sym) +{ + return ((struct template_meta_symbol *) sym)->instances; +} + static void symbol_init_cplus_specific (struct general_symbol_info *gsymbol, struct objfile *objfile) diff --git a/gdb/symtab.h b/gdb/symtab.h index a1fba1c..998545d 100644 --- a/gdb/symtab.h +++ b/gdb/symtab.h @@ -75,6 +75,15 @@ struct program_space; --chastain 2003-08-21 */ +/* A likend list of symbols used to keep references to + instances of a template. */ + +struct symbol_list_element +{ + struct symbol_list_element *next; + const struct symbol *sym; +}; + /* Struct for storing C++ specific information. Allocated when needed. */ struct cplus_specific @@ -657,6 +666,22 @@ struct symbol struct symbol *hash_next; }; +/* A "subclass" of symbol object for representing templates. Each + template knows about its INSTANCES. */ + +struct template_meta_symbol +{ + struct symbol sym; + struct symbol_list_element *instances; +}; + +extern void +symbol_add_template_instance (struct template_meta_symbol *template_sym, + const struct symbol *instance, + struct objfile *objfile); + +extern const struct symbol_list_element * +symbol_get_template_instances (const struct symbol *sym); #define SYMBOL_DOMAIN(symbol) (symbol)->domain #define SYMBOL_CLASS(symbol) (symbol)->aclass diff --git a/gdb/testsuite/gdb.cp/temp-op.exp b/gdb/testsuite/gdb.cp/temp-op.exp index 21e644f..7352e14 100644 --- a/gdb/testsuite/gdb.cp/temp-op.exp +++ b/gdb/testsuite/gdb.cp/temp-op.exp @@ -63,5 +63,5 @@ gdb_test "p bc == 'a'" "= 19" # Test that printing the a template name without # template parameters does not return an arbitrary match -gdb_test "print foo" "Symbol represents a template and cannot be evaluated." -gdb_test "ptype B" "type = Template Symbol" +gdb_test "print foo" "Symbol represents a template and cannot be evaluated.*foo\\(A, char\\).*" +gdb_test "ptype B" "Symbol represents a template and cannot be evaluated.*B.*B.*" --------------060100040304030100000207--