Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf unwind: Use perf_arch_reg_{ip|sp}() to substitute macros

We use perf_arch_reg_ip() and perf_arch_reg_sp() to substitute macros
for obtaining the register numbers of SP and IP. This modification
enables cross analysis in the unwinding, therefore, the unwinding is
not restricted to the predefined values by the macros.

Consequently, the macros LIBUNWIND__ARCH_REG_{IP|SP} are removed since
they are no longer used.

Committer notes:

Add missing "util/env.h" header to make sure we have the definition for
perf_env__arch(), that when built with NO_LIBUNWIND=1 isn't available,
i.e. it was being included by sheer luck.

Signed-off-by: Leo Yan <leo.yan@linaro.org>
Acked-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Albert Ou <aou@eecs.berkeley.edu>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Eric Lin <eric.lin@sifive.com>
Cc: Fangrui Song <maskray@google.com>
Cc: Guo Ren <guoren@kernel.org>
Cc: Huacai Chen <chenhuacai@kernel.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Ivan Babrou <ivan@cloudflare.com>
Cc: James Clark <james.clark@arm.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: John Garry <john.g.garry@oracle.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Mike Leach <mike.leach@linaro.org>
Cc: Ming Wang <wangming01@loongson.cn>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Palmer Dabbelt <palmer@dabbelt.com>
Cc: Paul Walmsley <paul.walmsley@sifive.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Sandipan Das <sandipan.das@amd.com>
Cc: Will Deacon <will@kernel.org>
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-csky@vger.kernel.org
Cc: linux-riscv@lists.infradead.org
Link: https://lore.kernel.org/r/20230606014559.21783-4-leo.yan@linaro.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Leo Yan and committed by
Arnaldo Carvalho de Melo
d8f69fb6 34af56af

+10 -16
-2
tools/perf/util/libunwind/arm64.c
··· 18 18 * defined before including "unwind.h" 19 19 */ 20 20 #define LIBUNWIND__ARCH_REG_ID(regnum) libunwind__arm64_reg_id(regnum) 21 - #define LIBUNWIND__ARCH_REG_IP PERF_REG_ARM64_PC 22 - #define LIBUNWIND__ARCH_REG_SP PERF_REG_ARM64_SP 23 21 24 22 #include "unwind.h" 25 23 #include "libunwind-aarch64.h"
-2
tools/perf/util/libunwind/x86_32.c
··· 18 18 * defined before including "unwind.h" 19 19 */ 20 20 #define LIBUNWIND__ARCH_REG_ID(regnum) libunwind__x86_reg_id(regnum) 21 - #define LIBUNWIND__ARCH_REG_IP PERF_REG_X86_IP 22 - #define LIBUNWIND__ARCH_REG_SP PERF_REG_X86_SP 23 21 24 22 #include "unwind.h" 25 23 #include "libunwind-x86.h"
+6 -2
tools/perf/util/unwind-libdw.c
··· 17 17 #include "event.h" 18 18 #include "perf_regs.h" 19 19 #include "callchain.h" 20 + #include "util/env.h" 20 21 21 22 static char *debuginfo_path; 22 23 ··· 171 170 void *arg) 172 171 { 173 172 struct unwind_info *ui = arg; 173 + const char *arch = perf_env__arch(ui->machine->env); 174 174 struct stack_dump *stack = &ui->sample->user_stack; 175 175 u64 start, end; 176 176 int offset; 177 177 int ret; 178 178 179 - ret = perf_reg_value(&start, &ui->sample->user_regs, PERF_REG_SP); 179 + ret = perf_reg_value(&start, &ui->sample->user_regs, 180 + perf_arch_reg_sp(arch)); 180 181 if (ret) 181 182 return false; 182 183 ··· 256 253 .max_stack = max_stack, 257 254 .best_effort = best_effort 258 255 }; 256 + const char *arch = perf_env__arch(ui_buf.machine->env); 259 257 Dwarf_Word ip; 260 258 int err = -EINVAL, i; 261 259 ··· 273 269 if (!ui->dwfl) 274 270 goto out; 275 271 276 - err = perf_reg_value(&ip, &data->user_regs, PERF_REG_IP); 272 + err = perf_reg_value(&ip, &data->user_regs, perf_arch_reg_ip(arch)); 277 273 if (err) 278 274 goto out; 279 275
+4 -2
tools/perf/util/unwind-libunwind-local.c
··· 553 553 int __write, void *arg) 554 554 { 555 555 struct unwind_info *ui = arg; 556 + const char *arch = perf_env__arch(ui->machine->env); 556 557 struct stack_dump *stack = &ui->sample->user_stack; 557 558 u64 start, end; 558 559 int offset; ··· 566 565 } 567 566 568 567 ret = perf_reg_value(&start, &ui->sample->user_regs, 569 - LIBUNWIND__ARCH_REG_SP); 568 + perf_arch_reg_sp(arch)); 570 569 if (ret) 571 570 return ret; 572 571 ··· 715 714 static int get_entries(struct unwind_info *ui, unwind_entry_cb_t cb, 716 715 void *arg, int max_stack) 717 716 { 717 + const char *arch = perf_env__arch(ui->machine->env); 718 718 u64 val; 719 719 unw_word_t ips[max_stack]; 720 720 unw_addr_space_t addr_space; ··· 723 721 int ret, i = 0; 724 722 725 723 ret = perf_reg_value(&val, &ui->sample->user_regs, 726 - LIBUNWIND__ARCH_REG_IP); 724 + perf_arch_reg_ip(arch)); 727 725 if (ret) 728 726 return ret; 729 727
-8
tools/perf/util/unwind.h
··· 42 42 #define LIBUNWIND__ARCH_REG_ID(regnum) libunwind__arch_reg_id(regnum) 43 43 #endif 44 44 45 - #ifndef LIBUNWIND__ARCH_REG_SP 46 - #define LIBUNWIND__ARCH_REG_SP PERF_REG_SP 47 - #endif 48 - 49 - #ifndef LIBUNWIND__ARCH_REG_IP 50 - #define LIBUNWIND__ARCH_REG_IP PERF_REG_IP 51 - #endif 52 - 53 45 int LIBUNWIND__ARCH_REG_ID(int regnum); 54 46 int unwind__prepare_access(struct maps *maps, struct map *map, bool *initialized); 55 47 void unwind__flush_access(struct maps *maps);