From: Namhyung Kim <namhyung@kernel.org>
To: Arnaldo Carvalho de Melo <acme@kernel.org>,
Ian Rogers <irogers@google.com>,
James Clark <james.clark@linaro.org>
Cc: Jiri Olsa <jolsa@kernel.org>,
Adrian Hunter <adrian.hunter@intel.com>,
Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@kernel.org>,
LKML <linux-kernel@vger.kernel.org>,
linux-perf-users@vger.kernel.org, Zecheng Li <zli94@ncsu.edu>,
Dmitry Dolgov <9erthalion6@gmail.com>
Subject: [PATCH] perf annotate: Fix register usage in data type profiling
Date: Thu, 5 Feb 2026 17:27:43 -0800 [thread overview]
Message-ID: <20260206012743.2617945-1-namhyung@kernel.org> (raw)
On data type profiling, it tried to match register name with a partial
string. For example, it allowed to match with "%rbp)" or "%rdi,8)".
But with recent change in the area, it doesn't match anymore and break
the data type profiling.
Let's pass the correct register name by removing the unwanted part. Add
arch__dwarf_regnum() to handle it in a single place.
Reported-by: Dmitry Dolgov <9erthalion6@gmail.com>
Closes: 7d3n23li6drroxrdlpxn7ixehdeszkjdftah3zyngjl2qs22ef@yelcjv53v42o
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
tools/perf/util/annotate.c | 61 +++++++++++++++++++-------------------
1 file changed, 30 insertions(+), 31 deletions(-)
diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index 880b1bd300c21e67..2e3522905046c1ec 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -2447,6 +2447,29 @@ int annotate_check_args(void)
return 0;
}
+static int arch__dwarf_regnum(const struct arch *arch, const char *str)
+{
+ const char *p;
+ char *regname, *q;
+ int reg;
+
+ p = strchr(str, arch->objdump.register_char);
+ if (p == NULL)
+ return -1;
+
+ regname = strdup(p);
+ if (regname == NULL)
+ return -1;
+
+ q = strpbrk(regname, ",) ");
+ if (q)
+ *q = '\0';
+
+ reg = get_dwarf_regnum(regname, arch->id.e_machine, arch->id.e_flags);
+ free(regname);
+ return reg;
+}
+
/*
* Get register number and access offset from the given instruction.
* It assumes AT&T x86 asm format like OFFSET(REG). Maybe it needs
@@ -2457,7 +2480,6 @@ static int extract_reg_offset(const struct arch *arch, const char *str,
struct annotated_op_loc *op_loc)
{
char *p;
- char *regname;
if (arch->objdump.register_char == 0)
return -1;
@@ -2482,31 +2504,14 @@ static int extract_reg_offset(const struct arch *arch, const char *str,
}
op_loc->offset = strtol(str, &p, 0);
-
- p = strchr(p, arch->objdump.register_char);
- if (p == NULL)
+ op_loc->reg1 = arch__dwarf_regnum(arch, p);
+ if (op_loc->reg1 == -1)
return -1;
- regname = strdup(p);
- if (regname == NULL)
- return -1;
-
- op_loc->reg1 = get_dwarf_regnum(regname, arch->id.e_machine, arch->id.e_flags);
- free(regname);
-
/* Get the second register */
- if (op_loc->multi_regs) {
- p = strchr(p + 1, arch->objdump.register_char);
- if (p == NULL)
- return -1;
-
- regname = strdup(p);
- if (regname == NULL)
- return -1;
+ if (op_loc->multi_regs)
+ op_loc->reg2 = arch__dwarf_regnum(arch, p + 1);
- op_loc->reg2 = get_dwarf_regnum(regname, arch->id.e_machine, arch->id.e_flags);
- free(regname);
- }
return 0;
}
@@ -2585,7 +2590,8 @@ int annotate_get_insn_location(const struct arch *arch, struct disasm_line *dl,
op_loc->multi_regs = multi_regs;
extract_reg_offset(arch, insn_str, op_loc);
} else {
- char *s, *p = NULL;
+ const char *s = insn_str;
+ char *p = NULL;
if (arch__is_x86(arch)) {
/* FIXME: Handle other segment registers */
@@ -2599,21 +2605,14 @@ int annotate_get_insn_location(const struct arch *arch, struct disasm_line *dl,
}
}
- s = strdup(insn_str);
- if (s == NULL)
- return -1;
-
if (*s == arch->objdump.register_char) {
- op_loc->reg1 = get_dwarf_regnum(s,
- arch->id.e_machine,
- arch->id.e_flags);
+ op_loc->reg1 = arch__dwarf_regnum(arch, s);
}
else if (*s == arch->objdump.imm_char) {
op_loc->offset = strtol(s + 1, &p, 0);
if (p && p != s + 1)
op_loc->imm = true;
}
- free(s);
}
}
--
2.53.0.rc2.204.g2597b5adb4-goog
next reply other threads:[~2026-02-06 1:27 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-06 1:27 Namhyung Kim [this message]
2026-02-06 5:00 ` [PATCH] perf annotate: Fix register usage in data type profiling Ian Rogers
2026-02-06 9:08 ` Dmitry Dolgov
2026-02-06 21:19 ` Arnaldo Carvalho de Melo
2026-02-08 12:24 ` Dmitry Dolgov
2026-02-06 21:18 ` Arnaldo Carvalho de Melo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260206012743.2617945-1-namhyung@kernel.org \
--to=namhyung@kernel.org \
--cc=9erthalion6@gmail.com \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=irogers@google.com \
--cc=james.clark@linaro.org \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=peterz@infradead.org \
--cc=zli94@ncsu.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox