Skip to content

Commit 91e2f53

Browse files
mhiramatacmel
authored andcommitted
perf probe: Fix to show function entry line as probe-able
Fix die_walk_lines() to list the function entry line correctly. Since the dwarf_entrypc() does not return the entry pc if the DIE has only range attribute, __die_walk_funclines() fails to list the declaration line (entry line) in that case. To solve this issue, this introduces die_entrypc() which correctly returns the entry PC (the first address range) even if the DIE has only range attribute. With this fix die_walk_lines() shows the function entry line is able to probe correctly. Fixes: 4cc9cec ("perf probe: Introduce lines walker interface") Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Namhyung Kim <namhyung@kernel.org> Link: http://lore.kernel.org/lkml/157190837419.1859.4619125803596816752.stgit@devnote2 Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent acb6a70 commit 91e2f53

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

‎tools/perf/util/dwarf-aux.c‎

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,28 @@ bool die_is_func_def(Dwarf_Die *dw_die)
307307
dwarf_attr(dw_die, DW_AT_declaration, &attr) == NULL);
308308
}
309309

310+
/**
311+
* die_entrypc - Returns entry PC (the lowest address) of a DIE
312+
* @dw_die: a DIE
313+
* @addr: where to store entry PC
314+
*
315+
* Since dwarf_entrypc() does not return entry PC if the DIE has only address
316+
* range, we have to use this to retrieve the lowest address from the address
317+
* range attribute.
318+
*/
319+
int die_entrypc(Dwarf_Die *dw_die, Dwarf_Addr *addr)
320+
{
321+
Dwarf_Addr base, end;
322+
323+
if (!addr)
324+
return -EINVAL;
325+
326+
if (dwarf_entrypc(dw_die, addr) == 0)
327+
return 0;
328+
329+
return dwarf_ranges(dw_die, 0, &base, addr, &end) < 0 ? -ENOENT : 0;
330+
}
331+
310332
/**
311333
* die_is_func_instance - Ensure that this DIE is an instance of a subprogram
312334
* @dw_die: a DIE
@@ -713,7 +735,7 @@ static int __die_walk_funclines(Dwarf_Die *sp_die, bool recursive,
713735
/* Handle function declaration line */
714736
fname = dwarf_decl_file(sp_die);
715737
if (fname && dwarf_decl_line(sp_die, &lineno) == 0 &&
716-
dwarf_entrypc(sp_die, &addr) == 0) {
738+
die_entrypc(sp_die, &addr) == 0) {
717739
lw.retval = callback(fname, lineno, addr, data);
718740
if (lw.retval != 0)
719741
goto done;

‎tools/perf/util/dwarf-aux.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ int cu_walk_functions_at(Dwarf_Die *cu_die, Dwarf_Addr addr,
2929
/* Get DW_AT_linkage_name (should be NULL for C binary) */
3030
const char *die_get_linkage_name(Dwarf_Die *dw_die);
3131

32+
/* Get the lowest PC in DIE (including range list) */
33+
int die_entrypc(Dwarf_Die *dw_die, Dwarf_Addr *addr);
34+
3235
/* Ensure that this DIE is a subprogram and definition (not declaration) */
3336
bool die_is_func_def(Dwarf_Die *dw_die);
3437

0 commit comments

Comments
 (0)