Page MenuHomeFreeBSD

libpmcstat: Teach pmcstat_image_get_elf_params about debug files
Changes PlannedPublic

Authored by jrtc27 on Apr 17 2023, 7:50 PM.
Tags
None
Referenced Files
Unknown Object (File)
Mon, Feb 9, 4:49 AM
Unknown Object (File)
Sun, Feb 8, 7:22 AM
Unknown Object (File)
Sat, Jan 31, 6:08 PM
Unknown Object (File)
Nov 27 2025, 3:28 AM
Unknown Object (File)
Nov 24 2025, 5:31 PM
Unknown Object (File)
Nov 24 2025, 5:00 AM
Unknown Object (File)
Nov 23 2025, 3:17 PM
Unknown Object (File)
Nov 15 2025, 6:53 AM
Subscribers

Details

Summary

libpmcstat scans the image (executable or library) for symbol tables in
order to be able to symbolicate callgraphs. However, we strip objects by
default, relying on separate debug files in /usr/lib/debug to provide
full symbol information to debuggers, and libpmcstat does not scan these
currently (though pmcstat itself does for other purposes). Thus, fix
this deficiency by also scanning a corresponding debug file, should it
exist, for symbols. This makes system-wide profiling of base much more
useful.

MFC after: 1 month

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 50971
Build 47862: arc lint + arc unit

Event Timeline

Oh, humm. We should probably be honoring the debug link (.gnu_debuglink section). Fix the kernel modules path thing would avoid a combinatorics explosion here since you would just have the !kernel-modules case to deal with. What GDB does when looking for separate files is something like this:

  • debug_file = read_section('.gnu_debuglink')
  • check dirname(executable) + debug_file
  • check /usr/lib/debug + dirname(executable) + debug_file

Checking the link would fix the problem you ran into with hardlinks (clang vs clang++, etc.) since the link would always be "clang.debug".

In D39626#902584, @jhb wrote:

Oh, humm. We should probably be honoring the debug link (.gnu_debuglink section). Fix the kernel modules path thing would avoid a combinatorics explosion here since you would just have the !kernel-modules case to deal with. What GDB does when looking for separate files is something like this:

  • debug_file = read_section('.gnu_debuglink')
  • check dirname(executable) + debug_file
  • check /usr/lib/debug + dirname(executable) + debug_file

Checking the link would fix the problem you ran into with hardlinks (clang vs clang++, etc.) since the link would always be "clang.debug".

That does indeed sound nicer, and explains why we don't need to have /usr/lib/debug links with GDB.

This revision is now accepted and ready to land.May 12 2023, 6:10 AM

In-progress rework to use .gnu_debuglink, but that requires no ABI changes, especially not to the kernel

As mentioned on IRC, I think we should create _PATH_DEBUG_PREFIX or something similar to hide the /usr/lib/debug path.

And yes, it's also a build time configurable, same as /usr/local, and the _PATH_ variable for /usr/local/ also doesn't currently support being overriden. We should fix these in a separate commit,
and just use a _PATH define variable here to limit how many places it needs to be cleaned up when we wish to make it configurable.