From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752839AbbCaHAT (ORCPT ); Tue, 31 Mar 2015 03:00:19 -0400 Received: from mail-wi0-f182.google.com ([209.85.212.182]:35526 "EHLO mail-wi0-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750774AbbCaHAR (ORCPT ); Tue, 31 Mar 2015 03:00:17 -0400 MIME-Version: 1.0 In-Reply-To: <1427753974-13380-3-git-send-email-eranian@google.com> References: <1427753974-13380-1-git-send-email-eranian@google.com> <1427753974-13380-3-git-send-email-eranian@google.com> Date: Tue, 31 Mar 2015 10:00:15 +0300 X-Google-Sender-Auth: ptbq1soi6sga6_VI6XImO2_nviQ Message-ID: Subject: Re: [PATCH v6 2/4] perf tools: add Java demangling support From: Pekka Enberg To: Stephane Eranian Cc: LKML , Arnaldo Carvalho de Melo , Peter Zijlstra , Ingo Molnar , Andi Kleen , Jiri Olsa , Namhyung Kim , cel@us.ibm.com, sukadev@linux.vnet.ibm.com, sonnyrao@chromium.org, johnmccutchan@google.com, David Ahern , adrian.hunter@intel.com, Pawel Moll Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Stephane, On Tue, Mar 31, 2015 at 1:19 AM, Stephane Eranian wrote: > +#define BASE_ENT(c, n) [c-'A']=n > +static const char *base_types['Z'-'A' + 1]={ > + BASE_ENT('B', "byte" ), > + BASE_ENT('C', "char" ), > + BASE_ENT('D', "double" ), > + BASE_ENT('F', "float" ), > + BASE_ENT('I', "int" ), > + BASE_ENT('J', "long" ), > + BASE_ENT('S', "short" ), > + BASE_ENT('Z', "bool" ), It's "boolean", not "bool" in JVM speak. > +static char * > +__demangle_java_sym(const char *str, const char *end, char *buf, int maxlen, int mode) > +{ > + int rlen = 0; > + int array = 0; > + int narg = 0; > + const char *q; > + > + if (!end) > + end = str + strlen(str); > + > + for (q = str; q != end; q++) { > + > + if (rlen == (maxlen - 1)) > + break; > + > + switch (*q) { > + case 'L': > + if (mode == MODE_PREFIX || mode == MODE_CTYPE) { > + if (mode == MODE_CTYPE) { > + if (narg) > + rlen += scnprintf(buf + rlen, maxlen - rlen, ", "); > + narg++; > + } > + rlen += scnprintf(buf + rlen, maxlen - rlen, "class "); > + if (mode == MODE_PREFIX) > + mode = MODE_CLASS; > + } else > + buf[rlen++] = *q; > + break; This looks odd to me. "L" marks the beginning of an class name and it's terminated by ";". You could just strhchr() the terminator and simply copy the name to "buf" and drop cases ';', '/', and the default label fro the switch statement. > +char * > +java_demangle_sym(const char *str, int flags) > +{ [snip] > + /* > + * expansion factor estimated to 3x > + */ > + len = strlen(str) * 3 + 1; > + buf = malloc(len); > + if (!buf) > + return NULL; Truncated symbols are lame. Can't you use realloc() to ensure that never happens? - Pekka