[lldb] Use objc_getRealizedClassList_trylock on macOS Ventura and later
authorJonas Devlieghere <jonas@devlieghere.com>
Wed, 8 Jun 2022 18:32:36 +0000 (11:32 -0700)
committerJonas Devlieghere <jonas@devlieghere.com>
Wed, 8 Jun 2022 18:34:27 +0000 (11:34 -0700)
commitfc43703481d858351a72d7ea6f439f4f682ba351
tree089a16d42f13562e9369b91f6ab049d7e5709804
parent0371ddf9adbec24d87a14ff21362132e5b598042
[lldb] Use objc_getRealizedClassList_trylock on macOS Ventura and later

In order to avoid stranding the Objective-C runtime lock, we switched
from objc_copyRealizedClassList to its non locking variant
objc_copyRealizedClassList_nolock. Not taking the lock was relatively
safe because we run this expression on one thread only, but it was still
possible that someone was in the middle of modifying this list while we
were trying to read it. Worst case that would result in a crash in the
inferior without side-effects and we'd unwind and try again later.

With the introduction of macOS Ventura, we can use
objc_getRealizedClassList_trylock instead. It has semantics similar to
objc_copyRealizedClassList_nolock, but instead of not locking at all,
the function returns if the lock is already taken, which avoids the
aforementioned crash without stranding the Objective-C runtime lock.
Because LLDB gets to allocate the underlying memory we also avoid
stranding the malloc lock.

rdar://89373233

Differential revision: https://reviews.llvm.org/D127252
lldb/packages/Python/lldbsuite/test/decorators.py
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h
lldb/test/API/lang/objc/conflicting-class-list-function-from-user/TestObjCClassListFunctionFromUser.py