]> git.itanic.dy.fi Git - linux-stable/commitdiff
perf annotate: Check if operand has multiple regs
authorNamhyung Kim <namhyung@kernel.org>
Thu, 12 Oct 2023 03:50:25 +0000 (20:50 -0700)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Mon, 27 Nov 2023 19:05:19 +0000 (16:05 -0300)
It needs to check all possible information in an instruction.  Let's add
a field indicating if the operand has multiple registers.  I'll be used
to search type information like in an array access on x86 like:

  mov    0x10(%rax,%rbx,8), %rcx
             -------------
                 here

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: linux-toolchains@vger.kernel.org
Cc: linux-trace-devel@vger.kernel.org
Link: https://lore.kernel.org/r/20231012035111.676789-3-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/annotate.c
tools/perf/util/annotate.h

index 3364edf30f50e84a10f760d9941dd97438235a30..9a828dc601c75e8178b350fe958b379d42e368d6 100644 (file)
@@ -85,6 +85,8 @@ struct arch {
        struct          {
                char comment_char;
                char skip_functions_char;
+               char register_char;
+               char memory_ref_char;
        } objdump;
 };
 
@@ -188,6 +190,8 @@ static struct arch architectures[] = {
                .insn_suffix = "bwlq",
                .objdump =  {
                        .comment_char = '#',
+                       .register_char = '%',
+                       .memory_ref_char = '(',
                },
        },
        {
@@ -566,6 +570,34 @@ static struct ins_ops lock_ops = {
        .scnprintf = lock__scnprintf,
 };
 
+/*
+ * Check if the operand has more than one registers like x86 SIB addressing:
+ *   0x1234(%rax, %rbx, 8)
+ *
+ * But it doesn't care segment selectors like %gs:0x5678(%rcx), so just check
+ * the input string after 'memory_ref_char' if exists.
+ */
+static bool check_multi_regs(struct arch *arch, const char *op)
+{
+       int count = 0;
+
+       if (arch->objdump.register_char == 0)
+               return false;
+
+       if (arch->objdump.memory_ref_char) {
+               op = strchr(op, arch->objdump.memory_ref_char);
+               if (op == NULL)
+                       return false;
+       }
+
+       while ((op = strchr(op, arch->objdump.register_char)) != NULL) {
+               count++;
+               op++;
+       }
+
+       return count > 1;
+}
+
 static int mov__parse(struct arch *arch, struct ins_operands *ops, struct map_symbol *ms __maybe_unused)
 {
        char *s = strchr(ops->raw, ','), *target, *comment, prev;
@@ -593,6 +625,8 @@ static int mov__parse(struct arch *arch, struct ins_operands *ops, struct map_sy
        if (ops->source.raw == NULL)
                return -1;
 
+       ops->source.multi_regs = check_multi_regs(arch, ops->source.raw);
+
        target = skip_spaces(++s);
        comment = strchr(s, arch->objdump.comment_char);
 
@@ -613,6 +647,8 @@ static int mov__parse(struct arch *arch, struct ins_operands *ops, struct map_sy
        if (ops->target.raw == NULL)
                goto out_free_source;
 
+       ops->target.multi_regs = check_multi_regs(arch, ops->target.raw);
+
        if (comment == NULL)
                return 0;
 
index bc8b95e8b1be1e43d379b2f1a5f015eb69f25216..b64a2be287b30c4ac0c62d7212e8a62514c11541 100644 (file)
@@ -39,12 +39,14 @@ struct ins_operands {
                s64     offset;
                bool    offset_avail;
                bool    outside;
+               bool    multi_regs;
        } target;
        union {
                struct {
                        char    *raw;
                        char    *name;
                        u64     addr;
+                       bool    multi_regs;
                } source;
                struct {
                        struct ins          ins;