Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753586AbcKSAPR (ORCPT ); Fri, 18 Nov 2016 19:15:17 -0500 Received: from mail-wm0-f67.google.com ([74.125.82.67]:35754 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752336AbcKSAPQ (ORCPT ); Fri, 18 Nov 2016 19:15:16 -0500 From: Alexis Berlemont To: linux-kernel@vger.kernel.org Cc: Alexis Berlemont , peterz@infradead.org, mingo@redhat.com, acme@kernel.org, alexander.shishkin@linux.intel.com, hemant@linux.vnet.ibm.com Subject: [PATCH v2 1/2] perf sdt: add scanning of sdt probles arguments Date: Sat, 19 Nov 2016 00:56:36 +0100 Message-Id: <20161118235637.21651-2-alexis.berlemont@gmail.com> X-Mailer: git-send-email 2.10.2 In-Reply-To: <20161118235637.21651-1-alexis.berlemont@gmail.com> References: <20161118235637.21651-1-alexis.berlemont@gmail.com> In-Reply-To: <52251cbe-6825-1d03-7b5b-e7517549caa0@linux.vnet.ibm.com> References: <52251cbe-6825-1d03-7b5b-e7517549caa0@linux.vnet.ibm.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2179 Lines: 62 During a "perf buildid-cache --add" command, the section ".note.stapsdt" of the "added" binary is scanned in order to list the available SDT markers available in a binary. The parts containing the probes arguments were left unscanned. The whole section is now parsed; the probe arguments are extracted for later use. Signed-off-by: Alexis Berlemont --- tools/perf/util/symbol-elf.c | 16 +++++++++++++++- tools/perf/util/symbol.h | 1 + 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/tools/perf/util/symbol-elf.c b/tools/perf/util/symbol-elf.c index 99400b0..0fbe0b2 100644 --- a/tools/perf/util/symbol-elf.c +++ b/tools/perf/util/symbol-elf.c @@ -1822,7 +1822,7 @@ void kcore_extract__delete(struct kcore_extract *kce) static int populate_sdt_note(Elf **elf, const char *data, size_t len, struct list_head *sdt_notes) { - const char *provider, *name; + const char *provider, *name, *args; struct sdt_note *tmp = NULL; GElf_Ehdr ehdr; GElf_Addr base_off = 0; @@ -1881,6 +1881,20 @@ static int populate_sdt_note(Elf **elf, const char *data, size_t len, goto out_free_prov; } + args = (const char *)memchr(name, '\0', data + len - name); + + /* + * There is no argument if: + * - We reached the end of the note; + * - There is not enough room to hold a potential string; + * - The argument string is empty or just contains ':'. + */ + if (args == NULL || data + len - args < 2 || + args[1] == ':' || args[1] == '\0') + tmp->args = NULL; + else + tmp->args = strdup(++args); + if (gelf_getclass(*elf) == ELFCLASS32) { memcpy(&tmp->addr, &buf, 3 * sizeof(Elf32_Addr)); tmp->bit32 = true; diff --git a/tools/perf/util/symbol.h b/tools/perf/util/symbol.h index 2d0a905..913be07 100644 --- a/tools/perf/util/symbol.h +++ b/tools/perf/util/symbol.h @@ -347,6 +347,7 @@ int arch__choose_best_symbol(struct symbol *syma, struct symbol *symb); struct sdt_note { char *name; /* name of the note*/ char *provider; /* provider name */ + char *args; bool bit32; /* whether the location is 32 bits? */ union { /* location, base and semaphore addrs */ Elf64_Addr a64[3]; -- 2.10.2