public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Pedro Alves <pedro@codesourcery.com>
To: gdb-patches@sourceware.org
Cc: sami wagiaalla <swagiaal@redhat.com>
Subject: Re: [patch] stabs assertion failure  symbol_get_demangled_name
Date: Tue, 03 Aug 2010 16:59:00 -0000	[thread overview]
Message-ID: <201008031758.55493.pedro@codesourcery.com> (raw)
In-Reply-To: <4C509011.2040207@redhat.com>

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  <swagiaal@redhat.com>
> 
>         * 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

  reply	other threads:[~2010-08-03 16:59 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-07-28 20:16 sami wagiaalla
2010-08-03 16:59 ` Pedro Alves [this message]
2010-08-03 17:48 ` sami wagiaalla

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=201008031758.55493.pedro@codesourcery.com \
    --to=pedro@codesourcery.com \
    --cc=gdb-patches@sourceware.org \
    --cc=swagiaal@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).