Skip to content

Commit 4a6ce9a

Browse files
Zecheng Liacmel
authored andcommitted
perf dwarf-aux: Better variable collection for insn tracking
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>
1 parent 8c6d842 commit 4a6ce9a

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

tools/perf/util/annotate-data.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -868,6 +868,11 @@ static void update_var_state(struct type_state *state, struct data_loc_info *dlo
868868
int offset = var->offset;
869869
struct type_state_stack *stack;
870870

871+
/* If the reg location holds the pointer value, dereference the type */
872+
if (!var->is_reg_var_addr && is_pointer_type(&mem_die) &&
873+
__die_get_real_type(&mem_die, &mem_die) == NULL)
874+
continue;
875+
871876
if (var->reg != DWARF_REG_FB)
872877
offset -= fb_offset;
873878

@@ -893,6 +898,10 @@ static void update_var_state(struct type_state *state, struct data_loc_info *dlo
893898

894899
reg = &state->regs[var->reg];
895900

901+
/* For gp registers, skip the address registers for now */
902+
if (var->is_reg_var_addr)
903+
continue;
904+
896905
if (reg->ok && reg->kind == TSR_KIND_TYPE &&
897906
!is_better_type(&reg->type, &mem_die))
898907
continue;

tools/perf/util/dwarf-aux.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1627,13 +1627,22 @@ static int __die_collect_vars_cb(Dwarf_Die *die_mem, void *arg)
16271627
if (!check_allowed_ops(ops, nops))
16281628
return DIE_FIND_CB_SIBLING;
16291629

1630-
if (die_get_real_type(die_mem, &type_die) == NULL)
1630+
if (__die_get_real_type(die_mem, &type_die) == NULL)
16311631
return DIE_FIND_CB_SIBLING;
16321632

16331633
vt = malloc(sizeof(*vt));
16341634
if (vt == NULL)
16351635
return DIE_FIND_CB_END;
16361636

1637+
/* Usually a register holds the value of a variable */
1638+
vt->is_reg_var_addr = false;
1639+
1640+
if (((ops->atom >= DW_OP_breg0 && ops->atom <= DW_OP_breg31) ||
1641+
ops->atom == DW_OP_bregx || ops->atom == DW_OP_fbreg) &&
1642+
!is_breg_access_indirect(ops, nops))
1643+
/* The register contains an address of the variable. */
1644+
vt->is_reg_var_addr = true;
1645+
16371646
vt->die_off = dwarf_dieoffset(&type_die);
16381647
vt->addr = start;
16391648
vt->reg = reg_from_dwarf_op(ops);

tools/perf/util/dwarf-aux.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ struct die_var_type {
148148
u64 addr;
149149
int reg;
150150
int offset;
151+
/* Whether the register holds a address to the type */
152+
bool is_reg_var_addr;
151153
};
152154

153155
/* Return type info of a member at offset */

0 commit comments

Comments
 (0)