Re: [PATCH] perf riscv: fix register name strings

From: Ian Rogers

Date: Mon Jun 08 2026 - 16:15:55 EST


On Mon, Jun 8, 2026 at 12:27 PM Martin Kaiser <martin@xxxxxxxxx> wrote:
>
> On risc-v, pref probe generates an invalid syntax for a named register in
> a kprobe.
>
> $ perf probe --debug verbose --add "n_tty_write tty"
> ...
> Writing event: p:probe/n_tty_write _text+8922528 tty=%"%a0":x64
> Failed to write event: Invalid argument
>
> The problem is the combination of
>
> #define REG_DWARFNUM_NAME(reg, idx) [idx] = "%" #reg
>
> and entries such as
>
> REG_DWARFNUM_NAME("%a0", 10)
>
> where #reg will escape the quotes of the first macro parameter.
>
> Update the macro definition to produce the correct syntax for a named
> register in a kprobe, i.e. the unquoted register name with only one
> leading %.
>
> Fixes: a90c4519186d ("perf riscv: Remove dwarf-regs.c and add dwarf-regs-table.h")
> Signed-off-by: Martin Kaiser <martin@xxxxxxxxx>

Reviewed-by: Ian Rogers <irogers@xxxxxxxxxx>

Thanks for catching this! Sashiko is also green for this change:
https://sashiko.dev/#/patchset/20260608192731.708606-1-martin%40kaiser.cx

Thanks,
Ian

> ---
> tools/perf/arch/riscv/include/dwarf-regs-table.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/perf/arch/riscv/include/dwarf-regs-table.h b/tools/perf/arch/riscv/include/dwarf-regs-table.h
> index a45b63a6d5a8..c0a6e84e7a75 100644
> --- a/tools/perf/arch/riscv/include/dwarf-regs-table.h
> +++ b/tools/perf/arch/riscv/include/dwarf-regs-table.h
> @@ -2,7 +2,7 @@
> #ifdef DEFINE_DWARF_REGSTR_TABLE
> /* This is included in perf/util/dwarf-regs.c */
>
> -#define REG_DWARFNUM_NAME(reg, idx) [idx] = "%" #reg
> +#define REG_DWARFNUM_NAME(reg, idx) [idx] = reg
>
> static const char * const riscv_regstr_tbl[] = {
> REG_DWARFNUM_NAME("%zero", 0),
> --
> 2.43.7
>