Skip to contentSkip to conversation

perf tools: Fix compile error on sample->user_regs

PATCH Applied Namhyung Kim 2 participants 4 messages Feb 14, 2025

Subsystems (4)
lore
Share & tools
lore

Namhyung Kim

author maintainer
#0 lore raw

PATCH v2 1/1 perf tools: Fix compile error on sample->user_regs

It's recently changed to allocate dynamically but misses to update some arch-dependent codes to use perf_sample__user_regs().

Fixes dc6d2bc2d893a878 ("perf sample: Make user_regs and intr_regs optional")

---
v2) fix arm (32-bit) as well

 tools/perf/arch/arm/tests/dwarf-unwind.c      | 2 +-
 tools/perf/arch/arm/util/unwind-libdw.c       | 2 +-
 tools/perf/arch/csky/util/unwind-libdw.c      | 2 +-
 tools/perf/arch/loongarch/util/unwind-libdw.c | 2 +-
 tools/perf/arch/powerpc/tests/dwarf-unwind.c  | 2 +-
 tools/perf/arch/powerpc/util/unwind-libdw.c   | 2 +-
 tools/perf/arch/riscv/util/unwind-libdw.c     | 2 +-
 tools/perf/arch/s390/util/unwind-libdw.c      | 2 +-
 8 files changed, 8 insertions(+), 8 deletions(-)
tools/perf/arch/arm/tests/dwarf-unwind.c +1 -1
index 9bc304cb7762b5d1..f421910e07097152 100644
@@ -45,7 +45,7 @@ static int sample_ustack(struct perf_sample *sample,
 int test__arch_unwind_sample(struct perf_sample *sample,
 			     struct thread *thread)
 {
-	struct regs_dump *regs = &sample->user_regs;
+	struct regs_dump *regs = perf_sample__user_regs(sample);
 	u64 *buf;
 
 	buf = calloc(1, sizeof(u64) * PERF_REGS_MAX);
tools/perf/arch/arm/util/unwind-libdw.c +1 -1
index 4e02cef461e3af34..fbb643f224ec4b27 100644
@@ -8,7 +8,7 @@
 bool libdw__arch_set_initial_registers(Dwfl_Thread *thread, void *arg)
 {
 	struct unwind_info *ui = arg;
-	struct regs_dump *user_regs = &ui->sample->user_regs;
+	struct regs_dump *user_regs = perf_sample__user_regs(ui->sample);
 	Dwarf_Word dwarf_regs[PERF_REG_ARM_MAX];
 
 #define REG(r) ({						\
tools/perf/arch/csky/util/unwind-libdw.c +1 -1
index 79df4374ab18dc36..b20b1569783d7e98 100644
@@ -10,7 +10,7 @@
 bool libdw__arch_set_initial_registers(Dwfl_Thread *thread, void *arg)
 {
 	struct unwind_info *ui = arg;
-	struct regs_dump *user_regs = &ui->sample->user_regs;
+	struct regs_dump *user_regs = perf_sample__user_regs(ui->sample);
 	Dwarf_Word dwarf_regs[PERF_REG_CSKY_MAX];
 
 #define REG(r) ({						\
tools/perf/arch/loongarch/util/unwind-libdw.c +1 -1
index 7b3b9a4b21f8f482..60b1144bedd5f325 100644
@@ -10,7 +10,7 @@
 bool libdw__arch_set_initial_registers(Dwfl_Thread *thread, void *arg)
 {
 	struct unwind_info *ui = arg;
-	struct regs_dump *user_regs = &ui->sample->user_regs;
+	struct regs_dump *user_regs = perf_sample__user_regs(ui->sample);
 	Dwarf_Word dwarf_regs[PERF_REG_LOONGARCH_MAX];
 
 #define REG(r) ({							\
tools/perf/arch/powerpc/tests/dwarf-unwind.c +1 -1
index 5ecf82893b84d5c0..66af884baa660389 100644
@@ -45,7 +45,7 @@ static int sample_ustack(struct perf_sample *sample,
 int test__arch_unwind_sample(struct perf_sample *sample,
 			     struct thread *thread)
 {
-	struct regs_dump *regs = &sample->user_regs;
+	struct regs_dump *regs = perf_sample__user_regs(sample);
 	u64 *buf;
 
 	buf = calloc(1, sizeof(u64) * PERF_REGS_MAX);
tools/perf/arch/powerpc/util/unwind-libdw.c +1 -1
index e9a5a8bb67d9186e..82d0c28ae3459ecd 100644
@@ -16,7 +16,7 @@ static const int special_regs[3][2] = {
 bool libdw__arch_set_initial_registers(Dwfl_Thread *thread, void *arg)
 {
 	struct unwind_info *ui = arg;
-	struct regs_dump *user_regs = &ui->sample->user_regs;
+	struct regs_dump *user_regs = perf_sample__user_regs(ui->sample);
 	Dwarf_Word dwarf_regs[32], dwarf_nip;
 	size_t i;
 
tools/perf/arch/riscv/util/unwind-libdw.c +1 -1
index 5c98010d8b59777f..dc1476e16321736d 100644
@@ -10,7 +10,7 @@
 bool libdw__arch_set_initial_registers(Dwfl_Thread *thread, void *arg)
 {
 	struct unwind_info *ui = arg;
-	struct regs_dump *user_regs = &ui->sample->user_regs;
+	struct regs_dump *user_regs = perf_sample__user_regs(ui->sample);
 	Dwarf_Word dwarf_regs[32];
 
 #define REG(r) ({						\
tools/perf/arch/s390/util/unwind-libdw.c +1 -1
index f50fb6dbb35c5dc6..c27c7a0d1076c890 100644
@@ -11,7 +11,7 @@
 bool libdw__arch_set_initial_registers(Dwfl_Thread *thread, void *arg)
 {
 	struct unwind_info *ui = arg;
-	struct regs_dump *user_regs = &ui->sample->user_regs;
+	struct regs_dump *user_regs = perf_sample__user_regs(ui->sample);
 	Dwarf_Word dwarf_regs[ARRAY_SIZE(s390_dwarf_regs)];
 
 #define REG(r) ({						\
Signature · 1 line
2.48.1.601.g30ceb7b040-goog
reviewer Reviewed-by on v2 1/1
#1 lore raw
Quoted 7 lines · Namhyung Kim

It's recently changed to allocate dynamically but misses to update some arch-dependent codes to use perf_sample__user_regs().

Fixes dc6d2bc2d893a878 ("perf sample: Make user_regs and intr_regs optional")

Thanks for this! My tag in case it is useful:

Would be nice to have asan testing to make sure there are arch dependent memory leaks, less arch code would be nice.

Thanks,
Ian

Quoted 120 lines

---
v2) fix arm (32-bit) as well

 tools/perf/arch/arm/tests/dwarf-unwind.c      | 2 +-
 tools/perf/arch/arm/util/unwind-libdw.c       | 2 +-
 tools/perf/arch/csky/util/unwind-libdw.c      | 2 +-
 tools/perf/arch/loongarch/util/unwind-libdw.c | 2 +-
 tools/perf/arch/powerpc/tests/dwarf-unwind.c  | 2 +-
 tools/perf/arch/powerpc/util/unwind-libdw.c   | 2 +-
 tools/perf/arch/riscv/util/unwind-libdw.c     | 2 +-
 tools/perf/arch/s390/util/unwind-libdw.c      | 2 +-
 8 files changed, 8 insertions(+), 8 deletions(-)
tools/perf/arch/arm/tests/dwarf-unwind.c +1 -1
index 9bc304cb7762b5d1..f421910e07097152 100644
@@ -45,7 +45,7 @@ static int sample_ustack(struct perf_sample *sample,
 int test__arch_unwind_sample(struct perf_sample *sample,
                             struct thread *thread)
 {
-       struct regs_dump *regs = &sample->user_regs;
+       struct regs_dump *regs = perf_sample__user_regs(sample);
        u64 *buf;
 
        buf = calloc(1, sizeof(u64) * PERF_REGS_MAX);
tools/perf/arch/arm/util/unwind-libdw.c +1 -1
index 4e02cef461e3af34..fbb643f224ec4b27 100644
@@ -8,7 +8,7 @@
 bool libdw__arch_set_initial_registers(Dwfl_Thread *thread, void *arg)
 {
        struct unwind_info *ui = arg;
-       struct regs_dump *user_regs = &ui->sample->user_regs;
+       struct regs_dump *user_regs = perf_sample__user_regs(ui->sample);
        Dwarf_Word dwarf_regs[PERF_REG_ARM_MAX];
 
 #define REG(r) ({                                              \
tools/perf/arch/csky/util/unwind-libdw.c +1 -1
index 79df4374ab18dc36..b20b1569783d7e98 100644
@@ -10,7 +10,7 @@
 bool libdw__arch_set_initial_registers(Dwfl_Thread *thread, void *arg)
 {
        struct unwind_info *ui = arg;
-       struct regs_dump *user_regs = &ui->sample->user_regs;
+       struct regs_dump *user_regs = perf_sample__user_regs(ui->sample);
        Dwarf_Word dwarf_regs[PERF_REG_CSKY_MAX];
 
 #define REG(r) ({                                              \
tools/perf/arch/loongarch/util/unwind-libdw.c +1 -1
index 7b3b9a4b21f8f482..60b1144bedd5f325 100644
@@ -10,7 +10,7 @@
 bool libdw__arch_set_initial_registers(Dwfl_Thread *thread, void *arg)
 {
        struct unwind_info *ui = arg;
-       struct regs_dump *user_regs = &ui->sample->user_regs;
+       struct regs_dump *user_regs = perf_sample__user_regs(ui->sample);
        Dwarf_Word dwarf_regs[PERF_REG_LOONGARCH_MAX];
 
 #define REG(r) ({                                                      \
tools/perf/arch/powerpc/tests/dwarf-unwind.c +1 -1
index 5ecf82893b84d5c0..66af884baa660389 100644
@@ -45,7 +45,7 @@ static int sample_ustack(struct perf_sample *sample,
 int test__arch_unwind_sample(struct perf_sample *sample,
                             struct thread *thread)
 {
-       struct regs_dump *regs = &sample->user_regs;
+       struct regs_dump *regs = perf_sample__user_regs(sample);
        u64 *buf;
 
        buf = calloc(1, sizeof(u64) * PERF_REGS_MAX);
tools/perf/arch/powerpc/util/unwind-libdw.c +1 -1
index e9a5a8bb67d9186e..82d0c28ae3459ecd 100644
@@ -16,7 +16,7 @@ static const int special_regs[3][2] = {
 bool libdw__arch_set_initial_registers(Dwfl_Thread *thread, void *arg)
 {
        struct unwind_info *ui = arg;
-       struct regs_dump *user_regs = &ui->sample->user_regs;
+       struct regs_dump *user_regs = perf_sample__user_regs(ui->sample);
        Dwarf_Word dwarf_regs[32], dwarf_nip;
        size_t i;
 
tools/perf/arch/riscv/util/unwind-libdw.c +1 -1
index 5c98010d8b59777f..dc1476e16321736d 100644
@@ -10,7 +10,7 @@
 bool libdw__arch_set_initial_registers(Dwfl_Thread *thread, void *arg)
 {
        struct unwind_info *ui = arg;
-       struct regs_dump *user_regs = &ui->sample->user_regs;
+       struct regs_dump *user_regs = perf_sample__user_regs(ui->sample);
        Dwarf_Word dwarf_regs[32];
 
 #define REG(r) ({                                              \
tools/perf/arch/s390/util/unwind-libdw.c +1 -2
index f50fb6dbb35c5dc6..c27c7a0d1076c890 100644
@@ -11,7 +11,7 @@
 bool libdw__arch_set_initial_registers(Dwfl_Thread *thread, void *arg)
 {
        struct unwind_info *ui = arg;
-       struct regs_dump *user_regs = &ui->sample->user_regs;
+       struct regs_dump *user_regs = perf_sample__user_regs(ui->sample);
        Dwarf_Word dwarf_regs[ARRAY_SIZE(s390_dwarf_regs)];
 
 #define REG(r) ({                                              \
--

2.48.1.601.g30ceb7b040-goog

author maintainer
#2 lore raw
Quoted 11 lines · Ian Rogers
Quoted 7 lines · Namhyung Kim

It's recently changed to allocate dynamically but misses to update some arch-dependent codes to use perf_sample__user_regs().

Fixes dc6d2bc2d893a878 ("perf sample: Make user_regs and intr_regs optional")

Thanks for this! My tag in case it is useful:

Sure, thanks for the review.

Quoted 3 lines

Would be nice to have asan testing to make sure there are arch dependent memory leaks, less arch code would be nice.

Right, I need cross-arch or native non-x86 testing.

Thanks,
Namhyung

author maintainer Applied
#3 lore raw
In reply to Namhyung Kim
Quoted 4 lines · Namhyung Kim

It's recently changed to allocate dynamically but misses to update some arch-dependent codes to use perf_sample__user_regs().

Applied to perf-tools-next, thanks!

Best regards,
Namhyung