Re: [PATCH v2 3/3] tools/perf: Fix to get declared file name from clang DWARF5

From: Georg Müller
Date: Thu Jun 15 2023 - 10:03:35 EST


Hi all,

I have found a solution for this bug and will post a patch later today.

Am 09.06.23 um 14:21 schrieb Georg Müller:

Am 01.11.22 um 14:48 schrieb Masami Hiramatsu (Google):
From: Masami Hiramatsu (Google) <mhiramat@xxxxxxxxxx>

Fix to get the declared file name even if it uses file index 0
in DWARF5, using custom die_get_decl_file() function.


this patch breaks perf probe on fedora 38.


The problem is that die_get_file_name() uses the wrong cu_die.

I was pointed to the solution by reading elfutils commit e1db5cdc9:

dwarf_decl_file uses dwarf_attr_integrate to get the DW_AT_decl_file
attribute. This means the attribute might come from a different DIE
in a different CU. If so, we need to use the CU associated with the
attribute, not the original DIE, to resolve the file name.

The correct cu_die has to be obtained via

dwarf_attr_integrate(dw_die, DW_AT_decl_file, &attr_mem)

and then cu_die from the cu from attr_mem (dwarf_cu_die(attr_mem.cu, &cu_die, ...)
to obtain it) has to be used.

Best regards,
Georg