lkml.org 
[lkml]   [2015]   [Feb]   [12]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH 1/4] perf tools: add Java demangling support
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@google.com>
> ---

[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;
> +}
> +
> +


\
 
 \ /
  Last update: 2015-02-12 09:21    [W:0.475 / U:1.448 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site