Skip to content

Commit

Permalink
perf probe: Change function definition check due to broken DWARF
Browse files Browse the repository at this point in the history
Since some gcc generates a broken DWARF which lacks DW_AT_declaration
attribute from the subprogram DIE of function prototype.
(https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97060)

So, in addition to the DW_AT_declaration check, we also check the
subprogram DIE has DW_AT_inline or actual entry pc.

Committer testing:

  # cat /etc/fedora-release
  Fedora release 33 (Thirty Three)
  #

Before:

  # perf test vfs_getname
  78: Use vfs_getname probe to get syscall args filenames             : FAILED!
  79: Check open filename arg using perf trace + vfs_getname          : FAILED!
  81: Add vfs_getname probe to get syscall args filenames             : FAILED!
  #

After:

  # perf test vfs_getname
  78: Use vfs_getname probe to get syscall args filenames             : Ok
  79: Check open filename arg using perf trace + vfs_getname          : Ok
  81: Add vfs_getname probe to get syscall args filenames             : Ok
  #

Reported-by: Thomas Richter <[email protected]>
Signed-off-by: Masami Hiramatsu <[email protected]>
Tested-by: Arnaldo Carvalho de Melo <[email protected]>
Cc: Sumanth Korikkar <[email protected]>
Link: http://lore.kernel.org/lkml/160645613571.2824037.7441351537890235895.stgit@devnote2
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
  • Loading branch information
mhiramat authored and acmel committed Nov 27, 2020
1 parent ab4200c commit a9ffd04
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
20 changes: 18 additions & 2 deletions tools/perf/util/dwarf-aux.c
Original file line number Diff line number Diff line change
Expand Up @@ -356,9 +356,25 @@ bool die_is_signed_type(Dwarf_Die *tp_die)
bool die_is_func_def(Dwarf_Die *dw_die)
{
Dwarf_Attribute attr;
Dwarf_Addr addr = 0;

if (dwarf_tag(dw_die) != DW_TAG_subprogram)
return false;

if (dwarf_attr(dw_die, DW_AT_declaration, &attr))
return false;

return (dwarf_tag(dw_die) == DW_TAG_subprogram &&
dwarf_attr(dw_die, DW_AT_declaration, &attr) == NULL);
/*
* DW_AT_declaration can be lost from function declaration
* by gcc's bug #97060.
* So we need to check this subprogram DIE has DW_AT_inline
* or an entry address.
*/
if (!dwarf_attr(dw_die, DW_AT_inline, &attr) &&
die_entrypc(dw_die, &addr) < 0)
return false;

return true;
}

/**
Expand Down
3 changes: 1 addition & 2 deletions tools/perf/util/probe-finder.c
Original file line number Diff line number Diff line change
Expand Up @@ -1885,8 +1885,7 @@ static int line_range_search_cb(Dwarf_Die *sp_die, void *data)
if (lr->file && strtailcmp(lr->file, dwarf_decl_file(sp_die)))
return DWARF_CB_OK;

if (die_is_func_def(sp_die) &&
die_match_name(sp_die, lr->function)) {
if (die_match_name(sp_die, lr->function) && die_is_func_def(sp_die)) {
lf->fname = dwarf_decl_file(sp_die);
dwarf_decl_line(sp_die, &lr->offset);
pr_debug("fname: %s, lineno:%d\n", lf->fname, lr->offset);
Expand Down

0 comments on commit a9ffd04

Please sign in to comment.