This is an archive of the discontinued LLVM Phabricator instance.

lldb PlatformDarwinKernel, delay local filesystem scan until needed
ClosedPublic

Authored by jasonmolenda on May 15 2023, 3:22 PM.

Details

Summary

The darwin kernel debugging platform plugin has a feature where it will scan a list of directories on the local filesystem for kernel binaries and kexts, loadable kernel extensions. When it finds a kernel/kext with a given UUID, it looks over the list of binaries it found, and loads them automatically.

In https://reviews.llvm.org/D133680 I added a feature to PlatformDarwinKernel where the platform is force-created, and then a method is called on it with an address in memory. If the address is a Mach-O fileset, it looks for a kernel in the fileset and returns the address of the kernel binary. This allows for generic code (live debugging, corefile loading) to handle this platform-specific case in a generic way.

In the ctor for PlatformDarwinKernel, I was doing this local filesystem scan. And if a generic bit of code is force creating this platform to run that method for each binary, we could end up iterating over the local filesystem multiple times. In extreme cases, it was a noticeable perf hit.

This patch moves the filesystem scan out of the ctor and into a method which is called in the two places where this platform actually needs the list of binaries. It grabs a mutex before doing the scan, to avoid a race if multiple threads print the platform status or try to find a kext/kernel on the local filesystem. There isn't any change in behavior beyond the performance difference when this platform is force-created multiple times in a debug session.

Diff Detail

Event Timeline

jasonmolenda created this revision.May 15 2023, 3:22 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 15 2023, 3:22 PM
jasonmolenda requested review of this revision.May 15 2023, 3:22 PM
JDevlieghere requested changes to this revision.May 15 2023, 5:05 PM

You can do this simpler with a single std::once_flag.

lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp
710–715
lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.h
199–200
This revision now requires changes to proceed.May 15 2023, 5:05 PM

You can do this simpler with a single std::once_flag.

+1

I like the idea of this patch a lot! LGTM otherwise.

Ah, makes sense, will update.

Update patch to use a std::once operation instead of hand-rolling it, as suggested by Jonas and Alex.

JDevlieghere accepted this revision.May 16 2023, 6:07 PM
This revision is now accepted and ready to land.May 16 2023, 6:07 PM