[PATCH v1 20/23] perf dwarf-regs: Add MIPS perf to dwarf register number mapping functions

Ian Rogers
2026-01-17T05:29:57Z

Despite an unused function declaration, there was no unwind-libdw for
MIPS but there is a perf_regs.h and a libdw implementation. Fill in
the pieces so hopefully MIPS unwinding with libdw works.

Signed-off-by: Ian Rogers <irogers@google.com>
---
tools/perf/util/dwarf-regs-arch/Build | 1 +
tools/perf/util/dwarf-regs-arch/dwarf-regs-mips.c | 14 ++++++++++++++
tools/perf/util/dwarf-regs.c | 5 +++++
tools/perf/util/include/dwarf-regs.h | 1 +
tools/perf/util/unwind-libdw.h | 2 --
5 files changed, 21 insertions(+), 2 deletions(-)
create mode 100644 tools/perf/util/dwarf-regs-arch/dwarf-regs-mips.c

diff --git a/tools/perf/util/dwarf-regs-arch/Build b/tools/perf/util/dwarf-regs-arch/Build
index 10c2af3d933a..ceb68ae86fd8 100644
--- a/tools/perf/util/dwarf-regs-arch/Build
+++ b/tools/perf/util/dwarf-regs-arch/Build
@@ -2,6 +2,7 @@ perf-util-$(CONFIG_LIBDW) += dwarf-regs-arm64.o
perf-util-$(CONFIG_LIBDW) += dwarf-regs-arm.o
perf-util-$(CONFIG_LIBDW) += dwarf-regs-csky.o
perf-util-$(CONFIG_LIBDW) += dwarf-regs-loongarch.o
+perf-util-$(CONFIG_LIBDW) += dwarf-regs-mips.o
perf-util-$(CONFIG_LIBDW) += dwarf-regs-powerpc.o
perf-util-$(CONFIG_LIBDW) += dwarf-regs-riscv.o
perf-util-$(CONFIG_LIBDW) += dwarf-regs-s390.o
diff --git a/tools/perf/util/dwarf-regs-arch/dwarf-regs-mips.c b/tools/perf/util/dwarf-regs-arch/dwarf-regs-mips.c
new file mode 100644
index 000000000000..3bb916b45c66
--- /dev/null
+++ b/tools/perf/util/dwarf-regs-arch/dwarf-regs-mips.c
@@ -0,0 +1,14 @@
+// SPDX-License-Identifier: GPL-2.0
+#include <errno.h>
+#include <dwarf-regs.h>
+#include "../../../arch/mips/include/uapi/asm/perf_regs.h"
+
+int __get_dwarf_regnum_for_perf_regnum_mips(int perf_regnum)
+{
+ if (perf_regnum == PERF_REG_MIPS_PC)
+ return 37;
+ if (perf_regnum < 0 || perf_regnum >= PERF_REG_MIPS_MAX)
+ return -ENOENT;
+
+ return perf_regnum;
+}
diff --git a/tools/perf/util/dwarf-regs.c b/tools/perf/util/dwarf-regs.c
index f86f76547592..797f455eba0d 100644
--- a/tools/perf/util/dwarf-regs.c
+++ b/tools/perf/util/dwarf-regs.c
@@ -179,6 +179,8 @@ static int get_libdw_frame_nregs(unsigned int machine, unsigned int flags __mayb
return 103;
case EM_LOONGARCH:
return 74;
+ case EM_MIPS:
+ return 71;
default:
return 0;
}
@@ -218,6 +220,9 @@ int get_dwarf_regnum_for_perf_regnum(int perf_regnum, unsigned int machine,
case EM_LOONGARCH:
reg = __get_dwarf_regnum_for_perf_regnum_loongarch(perf_regnum);
break;
+ case EM_MIPS:
+ reg = __get_dwarf_regnum_for_perf_regnum_mips(perf_regnum);
+ break;
default:
pr_err("ELF MACHINE %x is not supported.\n", machine);
return -ENOENT;
diff --git a/tools/perf/util/include/dwarf-regs.h b/tools/perf/util/include/dwarf-regs.h
index b95cf2d7b5b3..46a764cf322f 100644
--- a/tools/perf/util/include/dwarf-regs.h
+++ b/tools/perf/util/include/dwarf-regs.h
@@ -113,6 +113,7 @@ int __get_dwarf_regnum_for_perf_regnum_loongarch(int perf_regnum);
int __get_dwarf_regnum_for_perf_regnum_powerpc(int perf_regnum);
int __get_dwarf_regnum_for_perf_regnum_riscv(int perf_regnum);
int __get_dwarf_regnum_for_perf_regnum_s390(int perf_regnum);
+int __get_dwarf_regnum_for_perf_regnum_mips(int perf_regnum);

/*
* get_dwarf_regnum - Returns DWARF regnum from register name
diff --git a/tools/perf/util/unwind-libdw.h b/tools/perf/util/unwind-libdw.h
index 20d63d881dff..9c5b5fcaaae8 100644
--- a/tools/perf/util/unwind-libdw.h
+++ b/tools/perf/util/unwind-libdw.h
@@ -9,8 +9,6 @@ struct machine;
struct perf_sample;
struct thread;

-bool libdw_set_initial_registers_mips(Dwfl_Thread *thread, void *arg);
-
struct unwind_info {
Dwfl *dwfl;
struct perf_sample *sample;
--
2.52.0.457.g6b5491de43-goog