From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17250 invoked by alias); 26 May 2010 15:57:18 -0000 Received: (qmail 17132 invoked by uid 22791); 26 May 2010 15:57:17 -0000 X-SWARE-Spam-Status: No, hits=-4.9 required=5.0 tests=AWL,BAYES_00,KAM_STOCKGEN,RCVD_IN_DNSWL_HI,SPF_HELO_PASS,TW_BJ,TW_CP,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; Wed, 26 May 2010 15:57:03 +0000 Received: from int-mx05.intmail.prod.int.phx2.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.18]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o4QFv1GP018118 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 26 May 2010 11:57:01 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx05.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o4QFv1Wh029956 for ; Wed, 26 May 2010 11:57:01 -0400 Received: from [10.15.16.55] (toner.yyz.redhat.com [10.15.16.55]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id o4QFv03d022101 for ; Wed, 26 May 2010 11:57:00 -0400 Message-ID: <4BFD4230.3030600@redhat.com> Date: Wed, 26 May 2010 16:05:00 -0000 From: sami wagiaalla User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.9) Gecko/20100330 Fedora/3.0.4-1.fc12 Thunderbird/3.0.4 MIME-Version: 1.0 To: gdb-patches@sourceware.org Subject: [patch] Change cplus_specific to an alocated struct Content-Type: multipart/mixed; boundary="------------070107040801070208010701" 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-05/txt/msg00595.txt.bz2 This is a multi-part message in MIME format. --------------070107040801070208010701 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-length: 276 I plan to expand the cplus_specific struct to store template information needed, of course, only for C++. Tom suggested that I move the substruct out of struct general_symbol_info and change its reference to a pointer to be assigned to the struct if allocated. Thoughts ? --------------070107040801070208010701 Content-Type: text/plain; name="cplus_specific-cleanup.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="cplus_specific-cleanup.patch" Content-length: 8333 Change cplus_specific to an allocated struct. 2010-05-26 Sami Wagiaalla * symtab.h: Change general_symbol_info.cplus_specific to a pointer instead of a sub-struct. Added prototype for +symbol_get_cplus_demangled_name. * symtab.c (symbol_set_cplus_demangled_name): New function. (symbol_get_cplus_demangled_name): New function. (symbol_init_cplus_specific): New function. (symbol_init_language_specific): Set language_specific.cplus_specific to null instead of language_specific.cplus_specific.demangled_name. (symbol_set_names): Ditto. call symbol_init_cplus_specific when needed. (symbol_natural_name): Use symbol_demangled_name. (symbol_demangled_name): Use symbol_get_cplus_demangled_name. * ada-lang.c (ada_decode_symbol): Use symbol_get_cplus_demangled_name. Change char **result to char *result. diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index 3b3894c..62e1251 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -1142,32 +1142,32 @@ static struct htab *decoded_names_store; char * ada_decode_symbol (const struct general_symbol_info *gsymbol) { - char **resultp = - (char **) &gsymbol->language_specific.cplus_specific.demangled_name; - if (*resultp == NULL) + char *result = symbol_get_cplus_demangled_name (gsymbol); + + if (result == NULL) { const char *decoded = ada_decode (gsymbol->name); if (gsymbol->obj_section != NULL) { struct objfile *objf = gsymbol->obj_section->objfile; - *resultp = obsavestring (decoded, strlen (decoded), - &objf->objfile_obstack); + result = obsavestring (decoded, strlen (decoded), + &objf->objfile_obstack); } /* Sometimes, we can't find a corresponding objfile, in which case, we put the result on the heap. Since we only decode when needed, we hope this usually does not cause a significant memory leak (FIXME). */ - if (*resultp == NULL) + if (result == NULL) { char **slot = (char **) htab_find_slot (decoded_names_store, decoded, INSERT); if (*slot == NULL) *slot = xstrdup (decoded); - *resultp = *slot; + result = *slot; } } - return *resultp; + return result; } static char * diff --git a/gdb/symtab.c b/gdb/symtab.c index 8b30ff1..f20baab 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -338,6 +338,38 @@ gdb_mangle_name (struct type *type, int method_id, int signature_id) return (mangled_name); } +/* Set the cplus demangled name of GSYMBOL to NAME. NAME must be already + correctly allocated. */ +static void +symbol_set_cplus_demangled_name (struct general_symbol_info *gsymbol, + char *name) +{ + gdb_assert (gsymbol->language_specific.cplus_specific != NULL); + gsymbol->language_specific.cplus_specific->demangled_name = name; +} + +/* Return the cplus demangled name of GSYMBOL. If GYSMBOL does not have a + cplus_specific struct allocated NULL is returned. */ +char * +symbol_get_cplus_demangled_name (const struct general_symbol_info *gsymbol) +{ + if (gsymbol->language_specific.cplus_specific != NULL) + return gsymbol->language_specific.cplus_specific->demangled_name; + + return NULL; +} + +/* Initialize the cplus_specific structure. 'cplus_specific' is intended to + be allocated lazily. So this should only be called if the structure is + needed. */ +static void +symbol_init_cplus_specific (struct general_symbol_info *gsymbol, + struct objfile *objfile) +{ + gsymbol->language_specific.cplus_specific = + OBSTACK_ZALLOC (&objfile->objfile_obstack, struct cplus_specific); +} + /* Initialize the language dependent portion of a symbol depending upon the language for the symbol. */ @@ -351,7 +383,7 @@ symbol_init_language_specific (struct general_symbol_info *gsymbol, || gsymbol->language == language_java || gsymbol->language == language_objc) { - gsymbol->language_specific.cplus_specific.demangled_name = NULL; + gsymbol->language_specific.cplus_specific = NULL; } else { @@ -527,7 +559,7 @@ symbol_set_names (struct general_symbol_info *gsymbol, memcpy (gsymbol->name, linkage_name, len); gsymbol->name[len] = '\0'; } - gsymbol->language_specific.cplus_specific.demangled_name = NULL; + gsymbol->language_specific.cplus_specific = NULL; return; } @@ -623,10 +655,12 @@ symbol_set_names (struct general_symbol_info *gsymbol, gsymbol->name = (*slot)->mangled + lookup_len - len; if ((*slot)->demangled[0] != '\0') - gsymbol->language_specific.cplus_specific.demangled_name - = (*slot)->demangled; + { + symbol_init_cplus_specific (gsymbol, objfile); + symbol_set_cplus_demangled_name (gsymbol, (*slot)->demangled); + } else - gsymbol->language_specific.cplus_specific.demangled_name = NULL; + gsymbol->language_specific.cplus_specific = NULL; } /* Return the source code name of a symbol. In languages where @@ -635,24 +669,11 @@ symbol_set_names (struct general_symbol_info *gsymbol, char * symbol_natural_name (const struct general_symbol_info *gsymbol) { - switch (gsymbol->language) - { - case language_cplus: - case language_d: - case language_java: - case language_objc: - if (gsymbol->language_specific.cplus_specific.demangled_name != NULL) - return gsymbol->language_specific.cplus_specific.demangled_name; - break; - case language_ada: - if (gsymbol->language_specific.cplus_specific.demangled_name != NULL) - return gsymbol->language_specific.cplus_specific.demangled_name; - else - return ada_decode_symbol (gsymbol); - break; - default: - break; - } + char *name = symbol_demangled_name (gsymbol); + + if (name != NULL) + return name; + return gsymbol->name; } @@ -661,18 +682,22 @@ symbol_natural_name (const struct general_symbol_info *gsymbol) char * symbol_demangled_name (const struct general_symbol_info *gsymbol) { + char *name; + switch (gsymbol->language) { case language_cplus: case language_d: case language_java: case language_objc: - if (gsymbol->language_specific.cplus_specific.demangled_name != NULL) - return gsymbol->language_specific.cplus_specific.demangled_name; + name = symbol_get_cplus_demangled_name (gsymbol); + if (name != NULL) + return name; break; case language_ada: - if (gsymbol->language_specific.cplus_specific.demangled_name != NULL) - return gsymbol->language_specific.cplus_specific.demangled_name; + name = symbol_get_cplus_demangled_name (gsymbol); + if (name != NULL) + return name; else return ada_decode_symbol (gsymbol); break; diff --git a/gdb/symtab.h b/gdb/symtab.h index 115c8ba..8ae799b 100644 --- a/gdb/symtab.h +++ b/gdb/symtab.h @@ -75,7 +75,13 @@ struct program_space; --chastain 2003-08-21 */ +/* Struct for storing C++ specific information. Allocated when needed. */ +struct cplus_specific +{ + /* This is in fact used for C++, Java, and Objective C. */ + char *demangled_name; +}; /* Define a structure for the information that is common to all symbol types, including minimal symbols, partial symbols, and full symbols. In a @@ -120,16 +126,11 @@ struct general_symbol_info value; /* Since one and only one language can apply, wrap the language specific - information inside a union. */ + information inside a union. */ union { - struct cplus_specific - { - /* This is in fact used for C++, Java, and Objective C. */ - char *demangled_name; - } - cplus_specific; + struct cplus_specific *cplus_specific; } language_specific; @@ -172,6 +173,10 @@ extern CORE_ADDR symbol_overlayed_address (CORE_ADDR, struct obj_section *); #define SYMBOL_SECTION(symbol) (symbol)->ginfo.section #define SYMBOL_OBJ_SECTION(symbol) (symbol)->ginfo.obj_section + +extern char * +symbol_get_cplus_demangled_name (const struct general_symbol_info *gsymbol); + /* Initializes the language dependent portion of a symbol depending upon the language for the symbol. */ #define SYMBOL_INIT_LANGUAGE_SPECIFIC(symbol,language) \ --------------070107040801070208010701--