Re: [RFA 3/3] Move logic out of symbol_find_demangled_name

Pedro Alves
2016-06-13T13:35:56Z

On 06/08/2016 05:02 AM, Tom Tromey wrote:

> * cp-support.h (gdb_sniff_from_mangled_name): Declare.
> * cp-support.c (gdb_sniff_from_mangled_name): New function.

I think this one would be better called cp_sniff_from_mangled_name.

> +static int
> +ada_sniff_from_mangled_name (const char *mangled, char **out)
> +{
> + const char *demangled = ada_decode (mangled);
> +
> + *out = NULL;
> +
> + if (demangled != mangled && demangled != NULL && demangled[0] != '<')
> + {
> + /* Set the gsymbol language to Ada, but still return 0.

This sentence needs updating.

> + Two reasons for that:
> +
> + 1. For Ada, we prefer computing the symbol's decoded name
> + on the fly rather than pre-compute it, in order to save
> + memory (Ada projects are typically very large).
> +
> + 2. There are some areas in the definition of the GNAT
> + encoding where, with a bit of bad luck, we might be able
> + to decode a non-Ada symbol, generating an incorrect
> + demangled name (Eg: names ending with "TB" for instance
> + are identified as task bodies and so stripped from
> + the decoded name returned).
> +
> + Returning 1, here, but not setting *DEMANGLED, helps us get a

This one too: it's OUT, not DEMANGLED.

> + little bit of the best of both worlds. Because we're last,
> + we should not affect any of the other languages that were
> + able to demangle the symbol before us; we get to correctly
> + tag Ada symbols as such; and even if we incorrectly tagged a
> + non-Ada symbol, which should be rare, any routing through the
> + Ada language should be transparent (Ada tries to behave much
> + like C/C++ with non-Ada symbols). */
> + return 1;
> + }
> +
> + return 0;
> +}
> +

> --- a/gdb/language.c
> +++ b/gdb/language.c
> @@ -663,6 +663,23 @@ language_demangle (const struct language_defn *current_language,
> return NULL;
> }
>
> +/* See langauge.h. */

Typo.

> +
> +int
> +language_sniff_from_mangled_name (const struct language_defn *lang,
> + const char *mangled, char **demangled)
> +{

Thanks,
Pedro Alves