Author: Jim Ingham Date: 2023-08-04T09:55:59-07:00 New Revision: 4185656625a249832ff67f628bd00e5278721c96
URL: https://github.com/llvm/llvm-project/commit/4185656625a249832ff67f628bd00e5278721c96 DIFF: https://github.com/llvm/llvm-project/commit/4185656625a249832ff67f628bd00e5278721c96.diff LOG: Fix the NSIndexSet data formatter for changes in macOS Sonoma. Added: Modified: lldb/source/Plugins/Language/ObjC/Cocoa.cpp Removed: ################################################################################ diff --git a/lldb/source/Plugins/Language/ObjC/Cocoa.cpp b/lldb/source/Plugins/Language/ObjC/Cocoa.cpp index 374ac763ab183d..f1a7e04bc9d1bf 100644 --- a/lldb/source/Plugins/Language/ObjC/Cocoa.cpp +++ b/lldb/source/Plugins/Language/ObjC/Cocoa.cpp @@ -237,7 +237,8 @@ bool lldb_private::formatters::NSIndexSetSummaryProvider( if (!process_sp) return false; - ObjCLanguageRuntime *runtime = ObjCLanguageRuntime::Get(*process_sp); + AppleObjCRuntime *runtime = llvm::dyn_cast_or_null<AppleObjCRuntime>( + ObjCLanguageRuntime::Get(*process_sp)); if (!runtime) return false; @@ -264,20 +265,56 @@ bool lldb_private::formatters::NSIndexSetSummaryProvider( do { if (class_name == "NSIndexSet" || class_name == "NSMutableIndexSet") { + // Foundation version 2000 added a bitmask if the index set fit in 64 bits + // and a Tagged Pointer version if the bitmask is small enough to fit in + // the tagged pointer payload. + // It also changed the layout (but not the size) of the set descriptor. + + // First check whether this is a tagged pointer. The bitmask will be in + // the payload of the tagged pointer. + uint64_t payload; + if (runtime->GetFoundationVersion() >= 2000 + && descriptor->GetTaggedPointerInfo(nullptr, nullptr, &payload)) { + count = llvm::popcount(payload); + break; + } + // The first 32 bits describe the index set in all cases: Status error; uint32_t mode = process_sp->ReadUnsignedIntegerFromMemory( - valobj_addr + ptr_size, 4, 0, error); + valobj_addr + ptr_size, 4, 0, error); if (error.Fail()) return false; - // this means the set is empty - count = 0 - if ((mode & 1) == 1) { - count = 0; - break; + // Now check if the index is held in a bitmask in the object: + if (runtime->GetFoundationVersion() >= 2000) { + // The first two bits are "isSingleRange" and "isBitfield". If this is + // a bitfield we handle it here, otherwise set mode appropriately and + // the rest of the treatment is in common. + if ((mode & 2) == 2) { + // The bitfield is a 64 bit uint at the beginning of the data var. + uint64_t bitfield = process_sp->ReadUnsignedIntegerFromMemory( + valobj_addr + 2 * ptr_size, 8, 0, error); + if (error.Fail()) + return false; + count = llvm::popcount(bitfield); + break; + } + // It wasn't a bitfield, so read the isSingleRange from its new loc: + if ((mode & 1) == 1) + mode = 1; // this means the set only has one range + else + mode = 2; // this means the set has multiple ranges + } else { + // this means the set is empty - count = 0 + if ((mode & 1) == 1) { + count = 0; + break; + } + + if ((mode & 2) == 2) + mode = 1; // this means the set only has one range + else + mode = 2; // this means the set has multiple ranges } - if ((mode & 2) == 2) - mode = 1; // this means the set only has one range - else - mode = 2; // this means the set has multiple ranges if (mode == 1) { count = process_sp->ReadUnsignedIntegerFromMemory( valobj_addr + 3 * ptr_size, ptr_size, 0, error); _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits