Commit 72ed62bd authored by Linus Torvalds's avatar Linus Torvalds

Merge branch 'perf-fixes-for-linus' of...

Merge branch 'perf-fixes-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip

* 'perf-fixes-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip:
  perf probe: Filter out redundant inline-instances
  perf probe: Search concrete out-of-line instances
  perf probe: Avoid searching variables in intermediate scopes
  perf probe: Fix to search local variables in appropriate scope
  perf probe: Warn when more than one line are given
  perf probe: Fix to walk all inline instances
  perf probe: Fix to search nested inlined functions in CU
  perf probe: Fix line walker to check CU correctly
  perf probe: Fix a memory leak for scopes array
  perf: fix temporary file ownership check
  perf report: Use properly build_id kernel binaries
  perf top browser: Remove spurious helpline update
parents 6cac9529 bdc2209f
......@@ -134,10 +134,18 @@ static int opt_show_lines(const struct option *opt __used,
{
int ret = 0;
if (str)
if (!str)
return 0;
if (params.show_lines) {
pr_warning("Warning: more than one --line options are"
" detected. Only the first one is valid.\n");
return 0;
}
params.show_lines = true;
ret = parse_line_range_desc(str, &params.line_range);
INIT_LIST_HEAD(&params.line_range.line_list);
params.show_lines = true;
return ret;
}
......
......@@ -96,6 +96,39 @@ int cu_find_lineinfo(Dwarf_Die *cu_die, unsigned long addr,
return *lineno ?: -ENOENT;
}
static int __die_find_inline_cb(Dwarf_Die *die_mem, void *data);
/**
* cu_walk_functions_at - Walk on function DIEs at given address
* @cu_die: A CU DIE
* @addr: An address
* @callback: A callback which called with found DIEs
* @data: A user data
*
* Walk on function DIEs at given @addr in @cu_die. Passed DIEs
* should be subprogram or inlined-subroutines.
*/
int cu_walk_functions_at(Dwarf_Die *cu_die, Dwarf_Addr addr,
int (*callback)(Dwarf_Die *, void *), void *data)
{
Dwarf_Die die_mem;
Dwarf_Die *sc_die;
int ret = -ENOENT;
/* Inlined function could be recursive. Trace it until fail */
for (sc_die = die_find_realfunc(cu_die, addr, &die_mem);
sc_die != NULL;
sc_die = die_find_child(sc_die, __die_find_inline_cb, &addr,
&die_mem)) {
ret = callback(sc_die, data);
if (ret)
break;
}
return ret;
}
/**
* die_compare_name - Compare diename and tname
* @dw_die: a DIE
......@@ -198,6 +231,19 @@ static int die_get_attr_udata(Dwarf_Die *tp_die, unsigned int attr_name,
return 0;
}
/* Get attribute and translate it as a sdata */
static int die_get_attr_sdata(Dwarf_Die *tp_die, unsigned int attr_name,
Dwarf_Sword *result)
{
Dwarf_Attribute attr;
if (dwarf_attr(tp_die, attr_name, &attr) == NULL ||
dwarf_formsdata(&attr, result) != 0)
return -ENOENT;
return 0;
}
/**
* die_is_signed_type - Check whether a type DIE is signed or not
* @tp_die: a DIE of a type
......@@ -250,6 +296,50 @@ int die_get_data_member_location(Dwarf_Die *mb_die, Dwarf_Word *offs)
return 0;
}
/* Get the call file index number in CU DIE */
static int die_get_call_fileno(Dwarf_Die *in_die)
{
Dwarf_Sword idx;
if (die_get_attr_sdata(in_die, DW_AT_call_file, &idx) == 0)
return (int)idx;
else
return -ENOENT;
}
/* Get the declared file index number in CU DIE */
static int die_get_decl_fileno(Dwarf_Die *pdie)
{
Dwarf_Sword idx;
if (die_get_attr_sdata(pdie, DW_AT_decl_file, &idx) == 0)
return (int)idx;
else
return -ENOENT;
}
/**
* die_get_call_file - Get callsite file name of inlined function instance
* @in_die: a DIE of an inlined function instance
*
* Get call-site file name of @in_die. This means from which file the inline
* function is called.
*/
const char *die_get_call_file(Dwarf_Die *in_die)
{
Dwarf_Die cu_die;
Dwarf_Files *files;
int idx;
idx = die_get_call_fileno(in_die);
if (idx < 0 || !dwarf_diecu(in_die, &cu_die, NULL, NULL) ||
dwarf_getsrcfiles(&cu_die, &files, NULL) != 0)
return NULL;
return dwarf_filesrc(files, idx, NULL, NULL);
}
/**
* die_find_child - Generic DIE search function in DIE tree
* @rt_die: a root DIE
......@@ -374,9 +464,78 @@ Dwarf_Die *die_find_inlinefunc(Dwarf_Die *sp_die, Dwarf_Addr addr,
return die_mem;
}
struct __instance_walk_param {
void *addr;
int (*callback)(Dwarf_Die *, void *);
void *data;
int retval;
};
static int __die_walk_instances_cb(Dwarf_Die *inst, void *data)
{
struct __instance_walk_param *iwp = data;
Dwarf_Attribute attr_mem;
Dwarf_Die origin_mem;
Dwarf_Attribute *attr;
Dwarf_Die *origin;
int tmp;
attr = dwarf_attr(inst, DW_AT_abstract_origin, &attr_mem);
if (attr == NULL)
return DIE_FIND_CB_CONTINUE;
origin = dwarf_formref_die(attr, &origin_mem);
if (origin == NULL || origin->addr != iwp->addr)
return DIE_FIND_CB_CONTINUE;
/* Ignore redundant instances */
if (dwarf_tag(inst) == DW_TAG_inlined_subroutine) {
dwarf_decl_line(origin, &tmp);
if (die_get_call_lineno(inst) == tmp) {
tmp = die_get_decl_fileno(origin);
if (die_get_call_fileno(inst) == tmp)
return DIE_FIND_CB_CONTINUE;
}
}
iwp->retval = iwp->callback(inst, iwp->data);
return (iwp->retval) ? DIE_FIND_CB_END : DIE_FIND_CB_CONTINUE;
}
/**
* die_walk_instances - Walk on instances of given DIE
* @or_die: an abstract original DIE
* @callback: a callback function which is called with instance DIE
* @data: user data
*
* Walk on the instances of give @in_die. @in_die must be an inlined function
* declartion. This returns the return value of @callback if it returns
* non-zero value, or -ENOENT if there is no instance.
*/
int die_walk_instances(Dwarf_Die *or_die, int (*callback)(Dwarf_Die *, void *),
void *data)
{
Dwarf_Die cu_die;
Dwarf_Die die_mem;
struct __instance_walk_param iwp = {
.addr = or_die->addr,
.callback = callback,
.data = data,
.retval = -ENOENT,
};
if (dwarf_diecu(or_die, &cu_die, NULL, NULL) == NULL)
return -ENOENT;
die_find_child(&cu_die, __die_walk_instances_cb, &iwp, &die_mem);
return iwp.retval;
}
/* Line walker internal parameters */
struct __line_walk_param {
const char *fname;
bool recursive;
line_walk_callback_t callback;
void *data;
int retval;
......@@ -385,39 +544,56 @@ struct __line_walk_param {
static int __die_walk_funclines_cb(Dwarf_Die *in_die, void *data)
{
struct __line_walk_param *lw = data;
Dwarf_Addr addr;
Dwarf_Addr addr = 0;
const char *fname;
int lineno;
if (dwarf_tag(in_die) == DW_TAG_inlined_subroutine) {
fname = die_get_call_file(in_die);
lineno = die_get_call_lineno(in_die);
if (lineno > 0 && dwarf_entrypc(in_die, &addr) == 0) {
lw->retval = lw->callback(lw->fname, lineno, addr,
lw->data);
if (fname && lineno > 0 && dwarf_entrypc(in_die, &addr) == 0) {
lw->retval = lw->callback(fname, lineno, addr, lw->data);
if (lw->retval != 0)
return DIE_FIND_CB_END;
}
}
if (!lw->recursive)
/* Don't need to search recursively */
return DIE_FIND_CB_SIBLING;
if (addr) {
fname = dwarf_decl_file(in_die);
if (fname && dwarf_decl_line(in_die, &lineno) == 0) {
lw->retval = lw->callback(fname, lineno, addr, lw->data);
if (lw->retval != 0)
return DIE_FIND_CB_END;
}
}
/* Continue to search nested inlined function call-sites */
return DIE_FIND_CB_CONTINUE;
}
/* Walk on lines of blocks included in given DIE */
static int __die_walk_funclines(Dwarf_Die *sp_die,
static int __die_walk_funclines(Dwarf_Die *sp_die, bool recursive,
line_walk_callback_t callback, void *data)
{
struct __line_walk_param lw = {
.recursive = recursive,
.callback = callback,
.data = data,
.retval = 0,
};
Dwarf_Die die_mem;
Dwarf_Addr addr;
const char *fname;
int lineno;
/* Handle function declaration line */
lw.fname = dwarf_decl_file(sp_die);
if (lw.fname && dwarf_decl_line(sp_die, &lineno) == 0 &&
fname = dwarf_decl_file(sp_die);
if (fname && dwarf_decl_line(sp_die, &lineno) == 0 &&
dwarf_entrypc(sp_die, &addr) == 0) {
lw.retval = callback(lw.fname, lineno, addr, data);
lw.retval = callback(fname, lineno, addr, data);
if (lw.retval != 0)
goto done;
}
......@@ -430,7 +606,7 @@ static int __die_walk_culines_cb(Dwarf_Die *sp_die, void *data)
{
struct __line_walk_param *lw = data;
lw->retval = __die_walk_funclines(sp_die, lw->callback, lw->data);
lw->retval = __die_walk_funclines(sp_die, true, lw->callback, lw->data);
if (lw->retval != 0)
return DWARF_CB_ABORT;
......@@ -439,7 +615,7 @@ static int __die_walk_culines_cb(Dwarf_Die *sp_die, void *data)
/**
* die_walk_lines - Walk on lines inside given DIE
* @rt_die: a root DIE (CU or subprogram)
* @rt_die: a root DIE (CU, subprogram or inlined_subroutine)
* @callback: callback routine
* @data: user data
*
......@@ -460,12 +636,12 @@ int die_walk_lines(Dwarf_Die *rt_die, line_walk_callback_t callback, void *data)
size_t nlines, i;
/* Get the CU die */
if (dwarf_tag(rt_die) == DW_TAG_subprogram)
if (dwarf_tag(rt_die) != DW_TAG_compile_unit)
cu_die = dwarf_diecu(rt_die, &die_mem, NULL, NULL);
else
cu_die = rt_die;
if (!cu_die) {
pr_debug2("Failed to get CU from subprogram\n");
pr_debug2("Failed to get CU from given DIE.\n");
return -EINVAL;
}
......@@ -509,7 +685,11 @@ int die_walk_lines(Dwarf_Die *rt_die, line_walk_callback_t callback, void *data)
* subroutines. We have to check functions list or given function.
*/
if (rt_die != cu_die)
ret = __die_walk_funclines(rt_die, callback, data);
/*
* Don't need walk functions recursively, because nested
* inlined functions don't have lines of the specified DIE.
*/
ret = __die_walk_funclines(rt_die, false, callback, data);
else {
struct __line_walk_param param = {
.callback = callback,
......
......@@ -34,12 +34,19 @@ extern const char *cu_get_comp_dir(Dwarf_Die *cu_die);
extern int cu_find_lineinfo(Dwarf_Die *cudie, unsigned long addr,
const char **fname, int *lineno);
/* Walk on funcitons at given address */
extern int cu_walk_functions_at(Dwarf_Die *cu_die, Dwarf_Addr addr,
int (*callback)(Dwarf_Die *, void *), void *data);
/* Compare diename and tname */
extern bool die_compare_name(Dwarf_Die *dw_die, const char *tname);
/* Get callsite line number of inline-function instance */
extern int die_get_call_lineno(Dwarf_Die *in_die);
/* Get callsite file name of inlined function instance */
extern const char *die_get_call_file(Dwarf_Die *in_die);
/* Get type die */
extern Dwarf_Die *die_get_type(Dwarf_Die *vr_die, Dwarf_Die *die_mem);
......@@ -73,6 +80,10 @@ extern Dwarf_Die *die_find_realfunc(Dwarf_Die *cu_die, Dwarf_Addr addr,
extern Dwarf_Die *die_find_inlinefunc(Dwarf_Die *sp_die, Dwarf_Addr addr,
Dwarf_Die *die_mem);
/* Walk on the instances of given DIE */
extern int die_walk_instances(Dwarf_Die *in_die,
int (*callback)(Dwarf_Die *, void *), void *data);
/* Walker on lines (Note: line number will not be sorted) */
typedef int (* line_walk_callback_t) (const char *fname, int lineno,
Dwarf_Addr addr, void *data);
......
......@@ -726,7 +726,16 @@ static int perf_header__read_build_ids_abi_quirk(struct perf_header *header,
return -1;
bev.header = old_bev.header;
bev.pid = 0;
/*
* As the pid is the missing value, we need to fill
* it properly. The header.misc value give us nice hint.
*/
bev.pid = HOST_KERNEL_ID;
if (bev.header.misc == PERF_RECORD_MISC_GUEST_USER ||
bev.header.misc == PERF_RECORD_MISC_GUEST_KERNEL)
bev.pid = DEFAULT_GUEST_KERNEL_ID;
memcpy(bev.build_id, old_bev.build_id, sizeof(bev.build_id));
__event_process_build_id(&bev, filename, session);
......
This diff is collapsed.
......@@ -57,7 +57,7 @@ struct probe_finder {
struct perf_probe_event *pev; /* Target probe event */
/* Callback when a probe point is found */
int (*callback)(Dwarf_Die *sp_die, struct probe_finder *pf);
int (*callback)(Dwarf_Die *sc_die, struct probe_finder *pf);
/* For function searching */
int lno; /* Line number */
......
......@@ -1506,7 +1506,7 @@ int dso__load(struct dso *dso, struct map *map, symbol_filter_t filter)
if (strncmp(dso->name, "/tmp/perf-", 10) == 0) {
struct stat st;
if (stat(dso->name, &st) < 0)
if (lstat(dso->name, &st) < 0)
return -1;
if (st.st_uid && (st.st_uid != geteuid())) {
......@@ -2181,27 +2181,22 @@ size_t machines__fprintf_dsos_buildid(struct rb_root *machines,
return ret;
}
struct dso *dso__new_kernel(const char *name)
static struct dso*
dso__kernel_findnew(struct machine *machine, const char *name,
const char *short_name, int dso_type)
{
struct dso *dso = dso__new(name ?: "[kernel.kallsyms]");
if (dso != NULL) {
dso__set_short_name(dso, "[kernel]");
dso->kernel = DSO_TYPE_KERNEL;
}
return dso;
}
/*
* The kernel dso could be created by build_id processing.
*/
struct dso *dso = __dsos__findnew(&machine->kernel_dsos, name);
static struct dso *dso__new_guest_kernel(struct machine *machine,
const char *name)
{
char bf[PATH_MAX];
struct dso *dso = dso__new(name ?: machine__mmap_name(machine, bf,
sizeof(bf)));
/*
* We need to run this in all cases, since during the build_id
* processing we had no idea this was the kernel dso.
*/
if (dso != NULL) {
dso__set_short_name(dso, "[guest.kernel]");
dso->kernel = DSO_TYPE_GUEST_KERNEL;
dso__set_short_name(dso, short_name);
dso->kernel = dso_type;
}
return dso;
......@@ -2219,24 +2214,36 @@ void dso__read_running_kernel_build_id(struct dso *dso, struct machine *machine)
dso->has_build_id = true;
}
static struct dso *machine__create_kernel(struct machine *machine)
static struct dso *machine__get_kernel(struct machine *machine)
{
const char *vmlinux_name = NULL;
struct dso *kernel;
if (machine__is_host(machine)) {
vmlinux_name = symbol_conf.vmlinux_name;
kernel = dso__new_kernel(vmlinux_name);
if (!vmlinux_name)
vmlinux_name = "[kernel.kallsyms]";
kernel = dso__kernel_findnew(machine, vmlinux_name,
"[kernel]",
DSO_TYPE_KERNEL);
} else {
char bf[PATH_MAX];
if (machine__is_default_guest(machine))
vmlinux_name = symbol_conf.default_guest_vmlinux_name;
kernel = dso__new_guest_kernel(machine, vmlinux_name);
if (!vmlinux_name)
vmlinux_name = machine__mmap_name(machine, bf,
sizeof(bf));
kernel = dso__kernel_findnew(machine, vmlinux_name,
"[guest.kernel]",
DSO_TYPE_GUEST_KERNEL);
}
if (kernel != NULL) {
if (kernel != NULL && (!kernel->has_build_id))
dso__read_running_kernel_build_id(kernel, machine);
dsos__add(&machine->kernel_dsos, kernel);
}
return kernel;
}
......@@ -2340,7 +2347,7 @@ void machine__destroy_kernel_maps(struct machine *machine)
int machine__create_kernel_maps(struct machine *machine)
{
struct dso *kernel = machine__create_kernel(machine);
struct dso *kernel = machine__get_kernel(machine);
if (kernel == NULL ||
__machine__create_kernel_maps(machine, kernel) < 0)
......
......@@ -155,7 +155,6 @@ struct dso {
};
struct dso *dso__new(const char *name);
struct dso *dso__new_kernel(const char *name);
void dso__delete(struct dso *dso);
int dso__name_len(const struct dso *dso);
......
......@@ -208,6 +208,5 @@ int perf_top__tui_browser(struct perf_top *top)
},
};
ui_helpline__push("Press <- or ESC to exit");
return perf_top_browser__run(&browser);
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment