Skip to content

Commit

Permalink
perf probe: Support DW_AT_const_value constant value
Browse files Browse the repository at this point in the history
Support DW_AT_const_value for variable assignment instead of location.
Note that this requires ftrace supporting immediate value.

Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Ravi Bangoria <ravi.bangoria@linux.ibm.com>
Cc: Steven Rostedt (VMware) <rostedt@goodmis.org>
Cc: Tom Zanussi <tom.zanussi@linux.intel.com>
Link: http://lore.kernel.org/lkml/157406476012.24476.16096289871757175775.stgit@devnote2
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
  • Loading branch information
Masami Hiramatsu authored and Arnaldo Carvalho de Melo committed Nov 18, 2019
1 parent 7236354 commit 66f69b2
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
7 changes: 7 additions & 0 deletions tools/perf/util/probe-file.c
Original file line number Diff line number Diff line change
Expand Up @@ -1008,6 +1008,7 @@ enum ftrace_readme {
FTRACE_README_UPROBE_REF_CTR,
FTRACE_README_USER_ACCESS,
FTRACE_README_MULTIPROBE_EVENT,
FTRACE_README_IMMEDIATE_VALUE,
FTRACE_README_END,
};

Expand All @@ -1022,6 +1023,7 @@ static struct {
DEFINE_TYPE(FTRACE_README_UPROBE_REF_CTR, "*ref_ctr_offset*"),
DEFINE_TYPE(FTRACE_README_USER_ACCESS, "*[u]<offset>*"),
DEFINE_TYPE(FTRACE_README_MULTIPROBE_EVENT, "*Create/append/*"),
DEFINE_TYPE(FTRACE_README_IMMEDIATE_VALUE, "*\\imm-value,*"),
};

static bool scan_ftrace_readme(enum ftrace_readme type)
Expand Down Expand Up @@ -1092,3 +1094,8 @@ bool multiprobe_event_is_supported(void)
{
return scan_ftrace_readme(FTRACE_README_MULTIPROBE_EVENT);
}

bool immediate_value_is_supported(void)
{
return scan_ftrace_readme(FTRACE_README_IMMEDIATE_VALUE);
}
1 change: 1 addition & 0 deletions tools/perf/util/probe-file.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ bool kretprobe_offset_is_supported(void);
bool uprobe_ref_ctr_is_supported(void);
bool user_access_is_supported(void);
bool multiprobe_event_is_supported(void);
bool immediate_value_is_supported(void);
#else /* ! HAVE_LIBELF_SUPPORT */
static inline struct probe_cache *probe_cache__new(const char *tgt __maybe_unused, struct nsinfo *nsi __maybe_unused)
{
Expand Down
11 changes: 11 additions & 0 deletions tools/perf/util/probe-finder.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,17 @@ static int convert_variable_location(Dwarf_Die *vr_die, Dwarf_Addr addr,
if (dwarf_attr(vr_die, DW_AT_external, &attr) != NULL)
goto static_var;

/* Constant value */
if (dwarf_attr(vr_die, DW_AT_const_value, &attr) &&
immediate_value_is_supported()) {
Dwarf_Sword snum;

dwarf_formsdata(&attr, &snum);
ret = asprintf(&tvar->value, "\\%ld", (long)snum);

return ret < 0 ? -ENOMEM : 0;
}

/* TODO: handle more than 1 exprs */
if (dwarf_attr(vr_die, DW_AT_location, &attr) == NULL)
return -EINVAL; /* Broken DIE ? */
Expand Down

0 comments on commit 66f69b2

Please sign in to comment.