RE: [PATCH v2] perf/probe: Search both .eh_frame and .debug_frame sections for probe location

From: åæéå / HIRAMATUïMASAMI
Date: Tue Jan 12 2016 - 06:04:41 EST


Hi Hemant,

>From: Hemant Kumar [mailto:hemant@xxxxxxxxxxxxxxxxxx]
>
>perf probe through debuginfo__find_probes() in util/probe-finder.c
>checks for the functions' frame descriptions in either .eh_frame section
>of an ELF or the .debug_frame. The check is based on whether either one
>of these sections is present. Depending on distro, toolchain defaults,
>architetcutre, build flags, etc., CFI might be found in either .eh_frame
>and/or .debug_frame. Sometimes, it may happen that, .eh_frame, even if
>present, may not be complete and may miss some descriptions. Therefore,
>to be sure, to find the CFI covering an address we will always have to
>investigate both if available.

OK, so we'd better check both cfi's.
[...]
>+/* Find probe points from debuginfo */
>+static int debuginfo__find_probes(struct debuginfo *dbg,
>+ struct probe_finder *pf)
>+{
>+ int ret = 0;
>+
>+#if _ELFUTILS_PREREQ(0, 142)
>+ Elf *elf;
>+ GElf_Ehdr ehdr;
>+ GElf_Shdr shdr;
>+
>+ if (pf->cfi_eh || pf->cfi_dbg)
>+ return debuginfo__find_probe_location(dbg, pf);
>+
>+ /* Get the call frame information from this dwarf */
>+ elf = dwarf_getelf(dbg->dbg);
>+ if (elf == NULL)
>+ return -EINVAL;
>+
>+ if (gelf_getehdr(elf, &ehdr) == NULL)
>+ return -EINVAL;
>+
>+ if (elf_section_by_name(elf, &ehdr, &shdr, ".eh_frame", NULL) &&
>+ shdr.sh_type == SHT_PROGBITS) {
>+ pf->cfi_eh = dwarf_getcfi_elf(elf);
>+ } else {
>+ pf->cfi_dbg = dwarf_getcfi(dbg->dbg);
>+ }

Hmm, if you want to check both of those cfi's, don't we have to do below?

if (elf_section_by_name(elf, &ehdr, &shdr, ".eh_frame", NULL) &&
shdr.sh_type == SHT_PROGBITS)
pf->cfi_eh = dwarf_getcfi_elf(elf);

pf->cfi_dbg = dwarf_getcfi(dbg->dbg);

Then, both of pf->cfi_* will be filled (if the elf has ".eh_frame").

Thanks!