From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29606 invoked by alias); 3 Aug 2010 16:59:14 -0000 Received: (qmail 29539 invoked by uid 22791); 3 Aug 2010 16:59:11 -0000 X-SWARE-Spam-Status: No, hits=0.8 required=5.0 tests=AWL,BAYES_00,KAM_STOCKTIP,TW_BJ,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mail.codesourcery.com (HELO mail.codesourcery.com) (38.113.113.100) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 03 Aug 2010 16:59:01 +0000 Received: (qmail 10146 invoked from network); 3 Aug 2010 16:58:58 -0000 Received: from unknown (HELO orlando.localnet) (pedro@127.0.0.2) by mail.codesourcery.com with ESMTPA; 3 Aug 2010 16:58:58 -0000 From: Pedro Alves To: gdb-patches@sourceware.org Subject: Re: [patch] stabs assertion failure symbol_get_demangled_name Date: Tue, 03 Aug 2010 16:59:00 -0000 User-Agent: KMail/1.13.2 (Linux/2.6.31-11-rt; KDE/4.4.2; x86_64; ; ) Cc: sami wagiaalla References: <4C509011.2040207@redhat.com> In-Reply-To: <4C509011.2040207@redhat.com> MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-15" Content-Transfer-Encoding: 7bit Message-Id: <201008031758.55493.pedro@codesourcery.com> 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-08/txt/msg00011.txt.bz2 On Wednesday 28 July 2010 21:16:17, sami wagiaalla wrote: > Pedro reported a crash of code compiled with stabs on > > gdb_assert(gsymbol->language_specific.cplus_specific != NULL); > > in symbol_get_demangled_name. The problem was that > stabsread.c:define_symbol was calling cp_scan_for_anonymous_namespaces > before setting the name. > I corrected that but there other case, and for > those I changed the assertion into an if statement that returns null > since symbol_natural_name depends on symbol_get_demangled_name to return > null in order to fall back to gsymbol->name. I tried this myself to check what symbol this was, and why doesn't this assert trigger with dwarf. It's a typedef symbol. The dwarf reader ends up with a call to symbol_set_demangled_name with a NULL name, while the stabs reader never calls it, and, symbol_set_demangled_name with a NULL name always allocates gsymbol->language_specific.cplus_specific even in that case. void symbol_set_demangled_name (struct general_symbol_info *gsymbol, char *name, struct objfile *objfile) { if (gsymbol->language == language_cplus) { if (gsymbol->language_specific.cplus_specific == NULL) symbol_init_cplus_specific (gsymbol, objfile); gsymbol->language_specific.cplus_specific->demangled_name = name; } else gsymbol->language_specific.mangled_lang.demangled_name = name; } I guess we could avoid a number of allocations if when (gsymbol->language_specific.cplus_specific == NULL && name == NULL) is true, we didn't allocate the cplus_specific bit. > 2010-07-28 Sami Wagiaalla > > * symtab.c (symbol_get_demangled_name): Remove assertion and > return NULL when language_specific.cplus_specific is not initialized. > * stabsread.c (define_symbol): Set the name before calling > cp_scan_for_anonymous_namespaces. Okay, thanks. Small formatting issue pointed out below. > --- a/gdb/symtab.c > +++ b/gdb/symtab.c > @@ -381,10 +381,10 @@ char * > symbol_get_demangled_name (const struct general_symbol_info *gsymbol) > { > if (gsymbol->language == language_cplus) > - { > - gdb_assert (gsymbol->language_specific.cplus_specific != NULL); > + if (gsymbol->language_specific.cplus_specific != NULL) > return gsymbol->language_specific.cplus_specific->demangled_name; > - } > + else > + return NULL; > else > return gsymbol->language_specific.mangled_lang.demangled_name; > } In cases like this (if as only statement of if), it's preferred to leave the outer {}'s in place, to future proof against dangling else problems: if (gsymbol->language == language_cplus) { if (gsymbol->language_specific.cplus_specific != NULL) return gsymbol->language_specific.cplus_specific->demangled_name; else return NULL; } else return gsymbol->language_specific.mangled_lang.demangled_name; -- Pedro Alves