Re: [PATCH 1/4] perf tools: add Java demangling support

From: Namhyung Kim
Date: Thu Feb 12 2015 - 03:14:15 EST


On Wed, Feb 11, 2015 at 12:42:42AM +0100, Stephane Eranian wrote:
> Add Java function descriptor demangling support.
> Something bfd cannot do.
>
> Signed-off-by: Stephane Eranian <eranian@xxxxxxxxxx>
> ---

[SNIP]
> +/*
> + * Demangle Java function signature (Hotspot, not GCJ)
> + * input:
> + * str: string to parse. String is not modified
> + * return:
> + * if can demangle then a a newly allocate string is returned.
> + * if cannot demangle, then NULL is returned
> + *
> + * Note that caller is responsible for freeing demangled string
> + */
> +char *
> +java_demangle_sym(const char *str)
> +{
> + char *buf, *ptr;
> + char *p;
> + size_t len, l1;
> +
> + if (!str)
> + return NULL;
> +
> + /* find start of retunr type */
> + p = strrchr(str, ')');
> + if (!p)
> + return NULL;
> +
> + /*
> + * expansion factor estimated to 3x
> + */
> + len = strlen(str) * 3 + 1;
> + buf = malloc(len);
> + if (!buf)
> + return NULL;
> +
> + buf[0] = '\0';
> + /*
> + * get return type first
> + */
> + ptr = __demangle_java_sym(p+1, NULL, buf, len, MODE_TYPE);
> + if (!ptr)
> + goto error;
> +
> + /* add space between return type and function prototype */
> + l1 = strlen(buf);
> + buf[l1++] = ' ';
> +
> + /* process function up to return type */
> + ptr = __demangle_java_sym(str, p + 1, buf + l1, len - l1, MODE_PREFIX);
> + if (!ptr)
> + goto error;

Do we really need to use return type for Java symbol name? Note that
for C++ demangling, we show function name only by default and
parameters will be shown when user gave -v option.

Thanks,
Namhyung


> +
> + return buf;
> +error:
> + free(buf);
> + return NULL;
> +}
> +
> +
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/