Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1530579 > unrolled thread

[PATCH v4 1/2] perf sdt: add scanning of sdt probles arguments

Started byAlexis Berlemont <alexis.berlemont@gmail.com>
First post2016-11-26 02:10 +0100
Last post2016-12-07 03:50 +0100
Articles 2 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [PATCH v4 1/2] perf sdt: add scanning of sdt probles arguments Alexis Berlemont <alexis.berlemont@gmail.com> - 2016-11-26 02:10 +0100
    Re: [PATCH v4 1/2] perf sdt: add scanning of sdt probles arguments Masami Hiramatsu <mhiramat@kernel.org> - 2016-12-07 03:50 +0100

#1530579 — [PATCH v4 1/2] perf sdt: add scanning of sdt probles arguments

FromAlexis Berlemont <alexis.berlemont@gmail.com>
Date2016-11-26 02:10 +0100
Subject[PATCH v4 1/2] perf sdt: add scanning of sdt probles arguments
Message-ID<sHzF7-8am-7@gated-at.bofh.it>
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 <alexis.berlemont@gmail.com>
---
 tools/perf/util/symbol-elf.c | 25 +++++++++++++++++++++++--
 tools/perf/util/symbol.h     |  1 +
 2 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/symbol-elf.c b/tools/perf/util/symbol-elf.c
index 99400b0..7725c3f 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,25 @@ static int populate_sdt_note(Elf **elf, const char *data, size_t len,
 		goto out_free_prov;
 	}
 
+	args = 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 (!tmp->args) {
+			ret = -ENOMEM;
+			goto out_free_name;
+		}
+	}
+
 	if (gelf_getclass(*elf) == ELFCLASS32) {
 		memcpy(&tmp->addr, &buf, 3 * sizeof(Elf32_Addr));
 		tmp->bit32 = true;
@@ -1892,7 +1911,7 @@ static int populate_sdt_note(Elf **elf, const char *data, size_t len,
 	if (!gelf_getehdr(*elf, &ehdr)) {
 		pr_debug("%s : cannot get elf header.\n", __func__);
 		ret = -EBADF;
-		goto out_free_name;
+		goto out_free_args;
 	}
 
 	/* Adjust the prelink effect :
@@ -1917,6 +1936,8 @@ static int populate_sdt_note(Elf **elf, const char *data, size_t len,
 	list_add_tail(&tmp->note_list, sdt_notes);
 	return 0;
 
+out_free_args:
+	free(tmp->args);
 out_free_name:
 	free(tmp->name);
 out_free_prov:
diff --git a/tools/perf/util/symbol.h b/tools/perf/util/symbol.h
index dec7e2d4..db1953e 100644
--- a/tools/perf/util/symbol.h
+++ b/tools/perf/util/symbol.h
@@ -348,6 +348,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

[toc] | [next] | [standalone]


#1537433

FromMasami Hiramatsu <mhiramat@kernel.org>
Date2016-12-07 03:50 +0100
Message-ID<sLAsV-22T-7@gated-at.bofh.it>
In reply to#1530579
On Sat, 26 Nov 2016 01:58:02 +0100
Alexis Berlemont <alexis.berlemont@gmail.com> wrote:

> 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.
> 

Looks OK for me :)

Acked-by: Masami Hiramatsu <mhiramat@kernel.org>

Thanks!

> Signed-off-by: Alexis Berlemont <alexis.berlemont@gmail.com>
> ---
>  tools/perf/util/symbol-elf.c | 25 +++++++++++++++++++++++--
>  tools/perf/util/symbol.h     |  1 +
>  2 files changed, 24 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/perf/util/symbol-elf.c b/tools/perf/util/symbol-elf.c
> index 99400b0..7725c3f 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,25 @@ static int populate_sdt_note(Elf **elf, const char *data, size_t len,
>  		goto out_free_prov;
>  	}
>  
> +	args = 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 (!tmp->args) {
> +			ret = -ENOMEM;
> +			goto out_free_name;
> +		}
> +	}
> +
>  	if (gelf_getclass(*elf) == ELFCLASS32) {
>  		memcpy(&tmp->addr, &buf, 3 * sizeof(Elf32_Addr));
>  		tmp->bit32 = true;
> @@ -1892,7 +1911,7 @@ static int populate_sdt_note(Elf **elf, const char *data, size_t len,
>  	if (!gelf_getehdr(*elf, &ehdr)) {
>  		pr_debug("%s : cannot get elf header.\n", __func__);
>  		ret = -EBADF;
> -		goto out_free_name;
> +		goto out_free_args;
>  	}
>  
>  	/* Adjust the prelink effect :
> @@ -1917,6 +1936,8 @@ static int populate_sdt_note(Elf **elf, const char *data, size_t len,
>  	list_add_tail(&tmp->note_list, sdt_notes);
>  	return 0;
>  
> +out_free_args:
> +	free(tmp->args);
>  out_free_name:
>  	free(tmp->name);
>  out_free_prov:
> diff --git a/tools/perf/util/symbol.h b/tools/perf/util/symbol.h
> index dec7e2d4..db1953e 100644
> --- a/tools/perf/util/symbol.h
> +++ b/tools/perf/util/symbol.h
> @@ -348,6 +348,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
> 


-- 
Masami Hiramatsu <mhiramat@kernel.org>

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web