From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17123 invoked by alias); 9 Feb 2008 05:21:30 -0000 Received: (qmail 17115 invoked by uid 22791); 9 Feb 2008 05:21:29 -0000 X-Spam-Check-By: sourceware.org Received: from qnxmail.qnx.com (HELO qnxmail.qnx.com) (209.226.137.76) by sourceware.org (qpsmtpd/0.31) with ESMTP; Sat, 09 Feb 2008 05:21:06 +0000 Received: from smtp.ott.qnx.com (smtp.ott.qnx.com [10.42.96.5]) by hub.ott.qnx.com (8.9.3/8.9.3) with ESMTP id AAA31257 for ; Sat, 9 Feb 2008 00:06:50 -0500 Received: from [192.168.20.178] (pptp_vpn-20-178 [192.168.20.178]) by smtp.ott.qnx.com (8.8.8/8.6.12) with ESMTP id AAA00279 for ; Sat, 9 Feb 2008 00:21:03 -0500 Message-ID: <47AD383E.7000205@qnx.com> Date: Sat, 09 Feb 2008 05:21:00 -0000 From: Aleksandar Ristovski User-Agent: Thunderbird 2.0.0.9 (Windows/20071031) MIME-Version: 1.0 To: gdb-patches@sourceware.org Subject: [rfc] get rid of redundant data in c++ and java Content-Type: multipart/mixed; boundary="------------040500000806040306040604" 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: 2008-02/txt/msg00161.txt.bz2 This is a multi-part message in MIME format. --------------040500000806040306040604 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-length: 1360 Hello, Currently we synthesize typedef info for java and c++ (and ada, but I am not familiar with that language) for any symbol with STRUCT_DOMAIN domain. This can add up to a lot of redundant data. For partial symbols, we generate two identical names for the same symbol, once as struct second as typedef. The same happens with symbols, except we do not duplicate symbol name, but we do allocate another symbol struture. Instead of generating redundant data for symbols with STRUCT_DOMAIN domain in java and c++ languages, treat STRUCT_DOMAIN as equal to VAR_DOMAIN for these two languages when looking up symbols. See the patch for details. Running tests on linux x86, no regressions. --- Aleksandar Ristovski QNX Software Systems 2008-02-08 Aleksandar Ristovski * dwarf2read.c (add_partial_symbol): Do not add new psym for STRUCT_DOMAIN. Make sure you recognize c++ struct and java 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++ and java. (lookup_partial_symbol): Use symbol_matches_domain to see if the found psym domain matches the given domain. (lookup_block_symbol): Likewise. --------------040500000806040306040604 Content-Type: text/plain; name="duplicatesymbolfix.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="duplicatesymbolfix.diff" Content-length: 5925 Index: gdb/dwarf2read.c =================================================================== RCS file: /cvs/src/src/gdb/dwarf2read.c,v retrieving revision 1.251 diff -u -5 -p -p -r1.251 dwarf2read.c --- gdb/dwarf2read.c 1 Feb 2008 22:45:13 -0000 1.251 +++ gdb/dwarf2read.c 9 Feb 2008 04:51:19 -0000 @@ -2006,15 +2006,14 @@ add_partial_symbol (struct partial_die_i || cu->language == language_java) ? &objfile->global_psymbols : &objfile->static_psymbols, 0, (CORE_ADDR) 0, cu->language, objfile); - if (cu->language == language_cplus - || cu->language == language_java - || cu->language == language_ada) + if (cu->language == language_ada) { - /* For C++ and Java, these implicitly act as typedefs as well. */ + /* FIXME: Check if Ada really + needs to implicitly set typedef. */ add_psymbol_to_list (actual_name, strlen (actual_name), VAR_DOMAIN, LOC_TYPEDEF, &objfile->global_psymbols, 0, (CORE_ADDR) 0, cu->language, objfile); } @@ -7429,29 +7428,32 @@ new_symbol (struct die_info *die, struct && (cu->language == language_cplus || cu->language == language_java) ? &global_symbols : cu->list_in_scope); add_symbol_to_list (sym, list_to_add); - - /* 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. */ + 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); + } + + /* FIXME: Check if ada really needs to synthesize the typedef + or it can, as cplus and java, reuse STRUCT_DOMAIN in + lookup_ functions. */ + if (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; add_symbol_to_list (typedef_sym, list_to_add); } } break; case DW_TAG_typedef: Index: gdb/symtab.c =================================================================== RCS file: /cvs/src/src/gdb/symtab.c,v retrieving revision 1.173 diff -u -5 -p -p -r1.173 symtab.c --- gdb/symtab.c 5 Feb 2008 22:17:40 -0000 1.173 +++ gdb/symtab.c 9 Feb 2008 04:51:20 -0000 @@ -1577,10 +1577,28 @@ lookup_symbol_global (const char *name, return lookup_symbol_aux_psymtabs (GLOBAL_BLOCK, name, linkage_name, domain, symtab); } +static 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. */ + if (symbol_language == language_cplus + || symbol_language == language_java) + { + 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 static symbols if not */ @@ -1641,14 +1659,13 @@ lookup_partial_symbol (struct partial_sy while (top <= real_top && (linkage_name != NULL ? 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++; } } /* Can't use a binary search or else we found during the binary search that @@ -1656,11 +1673,12 @@ lookup_partial_symbol (struct partial_sy if (do_linear_search) { 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 : SYMBOL_MATCHES_SEARCH_NAME (*psym, name)) { @@ -1841,11 +1859,12 @@ lookup_block_symbol (const struct block { for (sym = dict_iter_name_first (BLOCK_DICT (block), name, &iter); 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; } return NULL; @@ -1862,11 +1881,12 @@ lookup_block_symbol (const struct block for (sym = dict_iter_name_first (BLOCK_DICT (block), name, &iter); 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)) { sym_found = sym; if (SYMBOL_CLASS (sym) != LOC_ARG && --------------040500000806040306040604--