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.