[PATCH v4 06/23] perf annotate: Adapt arch__dwarf_regnum() for arm64
Tengda Wu <[email protected]>
| Newsgroups | dev.linux.lists.llvm,org.kernel.vger.linux-kernel,org.kernel.vger.linux-perf-users |
|---|---|
| Message-ID | <[email protected]> |
Currently, arch__dwarf_regnum() assumes that all architectures use a register prefix character (e.g., '%' for x86) defined by arch->objdump.register_char, and uses it to match register names in objdump output. However, this assumption does not hold for arm64, where assembly syntax uses bare register names like 'x0', 'w1' without any prefix. As a result, arm64 builds may fail to correctly recognize register names from objdump disassembly, leading to incomplete or incorrect annotation output. To address this: - Make the register prefix check optional, allowing architectures without a prefix character to be parsed correctly. - Extend the delimiter set in strpbrk() to include the closing square bracket ']'. In arm64 assembly, memory operands often use bracketed syntax such as '[x1, #16]' or '[x2]'. Adding ']' ensures clean extraction of register names like 'x2' without trailing characters. - Remove the 'static' qualifier from arch__dwarf_regnum() so that it can be reused by other architecture-specific profiling components in future changes. Signed-off-by: Tengda Wu <[email protected]> --- tools/perf/util/annotate.c | 14 ++++++++------ tools/perf/util/annotate.h | 2 ++ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index df70e95a8470..9d8b4d6b859b 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c @@ -2472,21 +2472,23 @@ int annotate_check_args(void) return 0; } -static int arch__dwarf_regnum(const struct arch *arch, const char *str) +int arch__dwarf_regnum(const struct arch *arch, const char *str) { - const char *p; + const char *p = str; char *regname, *q; int reg; - p = strchr(str, arch->objdump.register_char); - if (p == NULL) - return -1; + if (arch->objdump.register_char) { + p = strchr(str, arch->objdump.register_char); + if (p == NULL) + return -1; + } regname = strdup(p); if (regname == NULL) return -1; - q = strpbrk(regname, ",) "); + q = strpbrk(regname, ",)] "); if (q) *q = '\0'; diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h index fa08d09b80f7..11b6e4780c02 100644 --- a/tools/perf/util/annotate.h +++ b/tools/perf/util/annotate.h @@ -492,6 +492,8 @@ int annotate_parse_percent_type(const struct option *opt, const char *_str, int annotate_check_args(void); +int arch__dwarf_regnum(const struct arch *arch, const char *str); + /** * struct annotated_op_loc - Location info of instruction operand * @reg1: First register in the operand -- 2.34.1