From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14222 invoked by alias); 2 May 2008 23:01:51 -0000 Received: (qmail 14212 invoked by uid 22791); 2 May 2008 23:01:50 -0000 X-Spam-Check-By: sourceware.org Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.31) with ESMTP; Fri, 02 May 2008 23:01:32 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id B26FF2A99A6; Fri, 2 May 2008 19:01:30 -0400 (EDT) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id AOSsWas7ccMy; Fri, 2 May 2008 19:01:30 -0400 (EDT) Received: from joel.gnat.com (localhost.localdomain [127.0.0.1]) by rock.gnat.com (Postfix) with ESMTP id 2563D2A995A; Fri, 2 May 2008 19:01:30 -0400 (EDT) Received: by joel.gnat.com (Postfix, from userid 1000) id 46C90E7ACD; Fri, 2 May 2008 16:01:27 -0700 (PDT) Date: Sat, 03 May 2008 00:01:00 -0000 From: Joel Brobecker To: Aleksandar Ristovski , GDB Patches Subject: Re: [rfc] get rid of redundant data in c++ and java Message-ID: <20080502230127.GJ3801@adacore.com> References: <47AD383E.7000205@qnx.com> <20080501192532.GG22218@caradoc.them.org> <481B198F.30701@qnx.com> <20080502135132.GD29202@caradoc.them.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="96YOpH+ONegL0A3E" Content-Disposition: inline In-Reply-To: <20080502135132.GD29202@caradoc.them.org> User-Agent: Mutt/1.4.2.2i 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: 2008-05/txt/msg00119.txt.bz2 --96YOpH+ONegL0A3E Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-length: 1418 > > * dwarf2read.c (add_partial_symbol): Do not add new psym for > > STRUCT_DOMAIN. Make sure you recognize c++ struct and java and ada > > class as typedefs. See lookup_partial_symbol function. > > (new_symbol): Similar to add_partial_symbol, do not create symbol for > > the typedef. See lookup_block_symbol. > > * symtab.c (symbol_matches_domain): New function, takes care > > of dual meaning of STRUCT_DOMAIN symbol for c++, ada and java. > > (lookup_partial_symbol): Use symbol_matches_domain to see if the > > found psym domain matches the given domain. > > (lookup_block_symbol): Likewise. > > Thanks. Joel, could you give this a try with GNAT? If it works for > Joel, it's OK to commit. This is a nice welcome space saver! I missed the patch when it was sent. There was a piece missing, however. The Ada module has its own bunch of symbol lookup routines, and some of them were checking the symbol domain. So I had to make the symbol_matches_domain routine non-static, and add a declaration in symtab.h. I also took the opportunity to fix an indentation issue, spell "C++" instead of "c++" as well as extend a comment to explain the Ada situation. * ada-lang.c: Update throughout to use symbol_matches_domain instead of matching the symbol domain explictly. I tested the above on x86-linux against the AdaCore testsuite and the gdb.ada section of our testsuite. -- Joel --96YOpH+ONegL0A3E Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="sym-dups.diff" Content-length: 7471 Index: ada-lang.c =================================================================== --- ada-lang.c (revision 130550) +++ ada-lang.c (working copy) @@ -4398,7 +4398,8 @@ ada_lookup_partial_symbol (struct partia { struct partial_symbol *psym = start[i]; - if (SYMBOL_DOMAIN (psym) == namespace + if (symbol_matches_domain (SYMBOL_LANGUAGE (psym), + SYMBOL_DOMAIN (psym), namespace) && wild_match (name, name_len, SYMBOL_LINKAGE_NAME (psym))) return psym; } @@ -4432,7 +4433,8 @@ ada_lookup_partial_symbol (struct partia { struct partial_symbol *psym = start[i]; - if (SYMBOL_DOMAIN (psym) == namespace) + if (symbol_matches_domain (SYMBOL_LANGUAGE (psym), + SYMBOL_DOMAIN (psym), namespace)) { int cmp = strncmp (name, SYMBOL_LINKAGE_NAME (psym), name_len); @@ -4475,7 +4477,8 @@ ada_lookup_partial_symbol (struct partia { struct partial_symbol *psym = start[i]; - if (SYMBOL_DOMAIN (psym) == namespace) + if (symbol_matches_domain (SYMBOL_LANGUAGE (psym), + SYMBOL_DOMAIN (psym), namespace)) { int cmp; @@ -5593,7 +5596,8 @@ ada_add_block_symbols (struct obstack *o struct symbol *sym; ALL_BLOCK_SYMBOLS (block, iter, sym) { - if (SYMBOL_DOMAIN (sym) == domain + if (symbol_matches_domain (SYMBOL_LANGUAGE (sym), + SYMBOL_DOMAIN (sym), domain) && wild_match (name, name_len, SYMBOL_LINKAGE_NAME (sym))) { switch (SYMBOL_CLASS (sym)) @@ -5623,7 +5627,8 @@ ada_add_block_symbols (struct obstack *o { ALL_BLOCK_SYMBOLS (block, iter, sym) { - if (SYMBOL_DOMAIN (sym) == domain) + if (symbol_matches_domain (SYMBOL_LANGUAGE (sym), + SYMBOL_DOMAIN (sym), domain)) { int cmp = strncmp (name, SYMBOL_LINKAGE_NAME (sym), name_len); if (cmp == 0 @@ -5668,7 +5673,8 @@ ada_add_block_symbols (struct obstack *o ALL_BLOCK_SYMBOLS (block, iter, sym) { - if (SYMBOL_DOMAIN (sym) == domain) + if (symbol_matches_domain (SYMBOL_LANGUAGE (sym), + SYMBOL_DOMAIN (sym), domain)) { int cmp; Index: dwarf2read.c =================================================================== --- dwarf2read.c (revision 130550) +++ dwarf2read.c (working copy) @@ -2114,16 +2114,6 @@ add_partial_symbol (struct partial_die_i : &objfile->static_psymbols, 0, (CORE_ADDR) 0, cu->language, objfile); - if (cu->language == language_cplus - || cu->language == language_java - || cu->language == language_ada) - { - /* For C++ and Java, these implicitly act as typedefs as well. */ - add_psymbol_to_list (actual_name, strlen (actual_name), - VAR_DOMAIN, LOC_TYPEDEF, - &objfile->global_psymbols, - 0, (CORE_ADDR) 0, cu->language, objfile); - } break; case DW_TAG_enumerator: add_psymbol_to_list (actual_name, strlen (actual_name), @@ -7863,23 +7853,16 @@ new_symbol (struct die_info *die, struct /* The semantics of C++ state that "struct foo { ... }" also defines a typedef for "foo". A Java class declaration also - defines a typedef for the class. Synthesize a typedef symbol - so that "ptype foo" works as expected. */ + defines a typedef for the class. */ if (cu->language == language_cplus || cu->language == language_java || cu->language == language_ada) { - struct symbol *typedef_sym = (struct symbol *) - obstack_alloc (&objfile->objfile_obstack, - sizeof (struct symbol)); - *typedef_sym = *sym; - SYMBOL_DOMAIN (typedef_sym) = VAR_DOMAIN; /* The symbol's name is already allocated along with this objfile, so we don't need to duplicate it for the type. */ if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0) TYPE_NAME (SYMBOL_TYPE (sym)) = SYMBOL_SEARCH_NAME (sym); - add_symbol_to_list (typedef_sym, list_to_add); } } break; Index: symtab.c =================================================================== --- symtab.c (revision 130550) +++ symtab.c (working copy) @@ -1675,6 +1675,26 @@ lookup_symbol_global (const char *name, domain, symtab); } +int +symbol_matches_domain (enum language symbol_language, + domain_enum symbol_domain, + domain_enum domain) +{ + /* For C++ "struct foo { ... }" also defines a typedef for "foo". + A Java class declaration also defines a typedef for the class. + Similarly, any Ada type declaration implicitly defines a typedef. */ + if (symbol_language == language_cplus + || symbol_language == language_java + || symbol_language == language_ada) + { + if ((domain == VAR_DOMAIN || domain == STRUCT_DOMAIN) + && symbol_domain == STRUCT_DOMAIN) + return 1; + } + /* For all other languages, strict match is required. */ + return (symbol_domain == domain); +} + /* Look, in partial_symtab PST, for symbol whose natural name is NAME. If LINKAGE_NAME is non-NULL, check in addition that the symbol's linkage name matches it. Check the global symbols if GLOBAL, the @@ -1739,10 +1759,9 @@ lookup_partial_symbol (struct partial_sy ? strcmp (SYMBOL_LINKAGE_NAME (*top), linkage_name) == 0 : SYMBOL_MATCHES_SEARCH_NAME (*top,name))) { - if (SYMBOL_DOMAIN (*top) == domain) - { - return (*top); - } + if (symbol_matches_domain (SYMBOL_LANGUAGE (*top), + SYMBOL_DOMAIN (*top), domain)) + return (*top); top++; } } @@ -1754,7 +1773,8 @@ lookup_partial_symbol (struct partial_sy { for (psym = start; psym < start + length; psym++) { - if (domain == SYMBOL_DOMAIN (*psym)) + if (symbol_matches_domain (SYMBOL_LANGUAGE (*psym), + SYMBOL_DOMAIN (*psym), domain)) { if (linkage_name != NULL ? strcmp (SYMBOL_LINKAGE_NAME (*psym), linkage_name) == 0 @@ -1939,7 +1959,8 @@ lookup_block_symbol (const struct block sym != NULL; sym = dict_iter_name_next (name, &iter)) { - if (SYMBOL_DOMAIN (sym) == domain + if (symbol_matches_domain (SYMBOL_LANGUAGE (sym), + SYMBOL_DOMAIN (sym), domain) && (linkage_name != NULL ? strcmp (SYMBOL_LINKAGE_NAME (sym), linkage_name) == 0 : 1)) return sym; @@ -1960,7 +1981,8 @@ lookup_block_symbol (const struct block sym != NULL; sym = dict_iter_name_next (name, &iter)) { - if (SYMBOL_DOMAIN (sym) == domain + if (symbol_matches_domain (SYMBOL_LANGUAGE (sym), + SYMBOL_DOMAIN (sym), domain) && (linkage_name != NULL ? strcmp (SYMBOL_LINKAGE_NAME (sym), linkage_name) == 0 : 1)) { Index: symtab.h =================================================================== --- symtab.h (revision 130550) +++ symtab.h (working copy) @@ -1019,6 +1019,10 @@ extern const char multiple_symbols_cance const char *multiple_symbols_select_mode (void); +int symbol_matches_domain (enum language symbol_language, + domain_enum symbol_domain, + domain_enum domain); + /* lookup a symbol table by source file name */ extern struct symtab *lookup_symtab (const char *); --96YOpH+ONegL0A3E--