Skip to content

Commit f19b587

Browse files
Leo Yanacmel
authored andcommitted
perf probe: Fixup Arm64 SDT arguments
Arm64 ELF section '.note.stapsdt' uses string format "-4@[sp, NUM]" if the probe is to access data in stack, e.g. below is an example for dumping Arm64 ELF file and shows the argument format: Arguments: -4@[sp, 12] -4@[sp, 8] -4@[sp, 4] Comparing against other archs' argument format, Arm64's argument introduces an extra space character in the middle of square brackets, due to argv_split() uses space as splitter, the argument is wrongly divided into two items. To support Arm64 SDT, this patch fixes up for this case, if any item contains sub string "[sp", concatenates the two continuous items. And adds the detailed explaination in comment. Signed-off-by: Leo Yan <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Alexandre Truong <[email protected]> Cc: Alexis Berlemont <[email protected]> Cc: He Zhe <[email protected]> Cc: Ian Rogers <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: John Garry <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Masami Hiramatsu <[email protected]> Cc: Mathieu Poirier <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Sumanth Korikkar <[email protected]> Cc: Thomas Richter <[email protected]> Cc: Will Deacon <[email protected]> Cc: [email protected] Link: http://lore.kernel.org/lkml/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 5c8fe58 commit f19b587

File tree

1 file changed

+36
-2
lines changed

1 file changed

+36
-2
lines changed

tools/perf/util/probe-file.c

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,8 @@ static char *synthesize_sdt_probe_command(struct sdt_note *note,
794794
char *ret = NULL;
795795
int i, args_count, err;
796796
unsigned long long ref_ctr_offset;
797+
char *arg;
798+
int arg_idx = 0;
797799

798800
if (strbuf_init(&buf, 32) < 0)
799801
return NULL;
@@ -818,11 +820,43 @@ static char *synthesize_sdt_probe_command(struct sdt_note *note,
818820
if (args == NULL)
819821
goto error;
820822

821-
for (i = 0; i < args_count; ++i) {
822-
if (synthesize_sdt_probe_arg(&buf, i, args[i]) < 0) {
823+
for (i = 0; i < args_count; ) {
824+
/*
825+
* FIXUP: Arm64 ELF section '.note.stapsdt' uses string
826+
* format "-4@[sp, NUM]" if a probe is to access data in
827+
* the stack, e.g. below is an example for the SDT
828+
* Arguments:
829+
*
830+
* Arguments: -4@[sp, 12] -4@[sp, 8] -4@[sp, 4]
831+
*
832+
* Since the string introduces an extra space character
833+
* in the middle of square brackets, the argument is
834+
* divided into two items. Fixup for this case, if an
835+
* item contains sub string "[sp,", need to concatenate
836+
* the two items.
837+
*/
838+
if (strstr(args[i], "[sp,") && (i+1) < args_count) {
839+
err = asprintf(&arg, "%s %s", args[i], args[i+1]);
840+
i += 2;
841+
} else {
842+
err = asprintf(&arg, "%s", args[i]);
843+
i += 1;
844+
}
845+
846+
/* Failed to allocate memory */
847+
if (err < 0) {
823848
argv_free(args);
824849
goto error;
825850
}
851+
852+
if (synthesize_sdt_probe_arg(&buf, arg_idx, arg) < 0) {
853+
free(arg);
854+
argv_free(args);
855+
goto error;
856+
}
857+
858+
free(arg);
859+
arg_idx++;
826860
}
827861

828862
argv_free(args);

0 commit comments

Comments
 (0)