When you are very early in process startup, before the system libraries have been initialized, and you run a simple expression, on Darwin systems, the Objective-C runtime plugin will run two utility functions to fetch the list of Objective-C class names in the inferior process. These function calls can cause problems when the process launch is this early, and the user expression may have been a simple one like "p globalvar=1" which would be harmless and not require a jitted expression.
This patch adds code to debugserver to use libdyld calls to find the process launch state, returns it in a JSON reply for a "jGetDyldProcessState" packet. This is passed up to DynamicLoaderMacOS::IsFullyInitialized() which checks for three specific process states that happen early in process startup, before system library initialization is completed.
Thread::SafeToCallFunctions() currently, on macOS, checks to see if the current thread is in __select, and does not run utility functions if it is. This patch updates SafeToCallFunctions() to also call DynamicLoader::IsFullyInitialized(), and avoid running utility functions if that is the case.
Then there are updates to AppleObjCRuntimeV2 to check the threads for SafeToCallFunctions() before scanning for dynamic objective-c classes, or the static shared cache objective-c classes.
I added a test case which stops process launch on the first malloc() call, runs a simple expression, and confirms (via the types log) that we did not read the objc class lists. Then it continues to main(), runs the simple expression again, and confirms (via types log) that it did read the objc class list.
The patch looks a bit big, mostly from piping the data from MachProcess::GetDyldProcessState() up to DynamicLoaderMacOS::IsFullyInitialized() through a handful of layers.
[begin bikeshedding]
Could we be more descriptive? Right now this sounds unactionable, which to be fair, it kind of is.
How about "could not execute support code to read Objective-C class data because it's not yet safe to do so and will be retried later.
[end bikeshedding]
Regardless we should say "class data" to match the other warnings or change those to say "class names".