]> www.infradead.org Git - users/hch/misc.git/commitdiff
perf dwarf-aux: Better variable collection for insn tracking
authorZecheng Li <zecheng@google.com>
Mon, 25 Aug 2025 19:54:05 +0000 (19:54 +0000)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Fri, 19 Sep 2025 15:14:30 +0000 (12:14 -0300)
Utilizes the previous is_breg_access_indirect function to determine if
the register + offset stores the variable itself or the struct it points
to, save the information in die_var_type.is_reg_var_addr.

Since we are storing the real types in the stack state, we need to do a
type dereference when is_reg_var_addr is set to false for stack/frame
registers.

For other gp registers, skip the variable when the register is a pointer
to the type. If we want to accept these variables, we might also utilize
is_reg_var_addr in a different way, we need to mark that register as a
pointer to the type.

Reviewed-by: Namhyung Kim <namhyung@kernel.org>
Signed-off-by: Zecheng Li <zecheng@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Xu Liu <xliuprof@google.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/annotate-data.c
tools/perf/util/dwarf-aux.c
tools/perf/util/dwarf-aux.h

index 1ef2edbc71d91a508fc77c4a8cea92f8ff52eb0d..258157cc43c20941d343682a22f3fa427d93fc49 100644 (file)
@@ -868,6 +868,11 @@ static void update_var_state(struct type_state *state, struct data_loc_info *dlo
                        int offset = var->offset;
                        struct type_state_stack *stack;
 
+                       /* If the reg location holds the pointer value, dereference the type */
+                       if (!var->is_reg_var_addr && is_pointer_type(&mem_die) &&
+                               __die_get_real_type(&mem_die, &mem_die) == NULL)
+                               continue;
+
                        if (var->reg != DWARF_REG_FB)
                                offset -= fb_offset;
 
@@ -893,6 +898,10 @@ static void update_var_state(struct type_state *state, struct data_loc_info *dlo
 
                        reg = &state->regs[var->reg];
 
+                       /* For gp registers, skip the address registers for now */
+                       if (var->is_reg_var_addr)
+                               continue;
+
                        if (reg->ok && reg->kind == TSR_KIND_TYPE &&
                            !is_better_type(&reg->type, &mem_die))
                                continue;
index 449bc9ad7affc1a928f9357c2fb4d9a63195a9ac..6fd2db5d938117295bd7066694e7efac42e12789 100644 (file)
@@ -1627,13 +1627,22 @@ static int __die_collect_vars_cb(Dwarf_Die *die_mem, void *arg)
        if (!check_allowed_ops(ops, nops))
                return DIE_FIND_CB_SIBLING;
 
-       if (die_get_real_type(die_mem, &type_die) == NULL)
+       if (__die_get_real_type(die_mem, &type_die) == NULL)
                return DIE_FIND_CB_SIBLING;
 
        vt = malloc(sizeof(*vt));
        if (vt == NULL)
                return DIE_FIND_CB_END;
 
+       /* Usually a register holds the value of a variable */
+       vt->is_reg_var_addr = false;
+
+       if (((ops->atom >= DW_OP_breg0 && ops->atom <= DW_OP_breg31) ||
+             ops->atom == DW_OP_bregx || ops->atom == DW_OP_fbreg) &&
+             !is_breg_access_indirect(ops, nops))
+               /* The register contains an address of the variable. */
+               vt->is_reg_var_addr = true;
+
        vt->die_off = dwarf_dieoffset(&type_die);
        vt->addr = start;
        vt->reg = reg_from_dwarf_op(ops);
index 892c8c5c23fc069f18d6633987eb774967e34b6a..cd481ec9c5a1c703225c2e6f1e17b421398e0103 100644 (file)
@@ -148,6 +148,8 @@ struct die_var_type {
        u64 addr;
        int reg;
        int offset;
+       /* Whether the register holds a address to the type */
+       bool is_reg_var_addr;
 };
 
 /* Return type info of a member at offset */