Skip to content

Commit

Permalink
Add support for the NSMutableDictionary variant: "__NSFrozenDictionaryM"
Browse files Browse the repository at this point in the history
This was an oversight of the commit: bb93483 that
added support for the Frozen variants.  Also added a test case for the way that
currently produces one of these variants (a copy).
  • Loading branch information
jimingham committed Jun 25, 2021
1 parent 8d5bf07 commit 4eabb12
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
7 changes: 5 additions & 2 deletions lldb/source/Plugins/Language/ObjC/NSDictionary.cpp
Expand Up @@ -410,6 +410,7 @@ bool lldb_private::formatters::NSDictionarySummaryProvider(
static const ConstString g_DictionaryM("__NSDictionaryM");
static const ConstString g_DictionaryMLegacy("__NSDictionaryM_Legacy");
static const ConstString g_DictionaryMImmutable("__NSDictionaryM_Immutable");
static const ConstString g_DictionaryMFrozen("__NSFrozenDictionaryM");
static const ConstString g_Dictionary1("__NSSingleEntryDictionaryI");
static const ConstString g_Dictionary0("__NSDictionary0");
static const ConstString g_DictionaryCF("__CFDictionary");
Expand All @@ -427,7 +428,8 @@ bool lldb_private::formatters::NSDictionarySummaryProvider(
return false;

value &= (is_64bit ? ~0xFC00000000000000UL : ~0xFC000000U);
} else if (class_name == g_DictionaryM || class_name == g_DictionaryMLegacy) {
} else if (class_name == g_DictionaryM || class_name == g_DictionaryMLegacy
|| class_name == g_DictionaryMFrozen) {
AppleObjCRuntime *apple_runtime =
llvm::dyn_cast_or_null<AppleObjCRuntime>(runtime);
Status error;
Expand Down Expand Up @@ -509,6 +511,7 @@ lldb_private::formatters::NSDictionarySyntheticFrontEndCreator(
static const ConstString g_DictionaryM("__NSDictionaryM");
static const ConstString g_Dictionary1("__NSSingleEntryDictionaryI");
static const ConstString g_DictionaryImmutable("__NSDictionaryM_Immutable");
static const ConstString g_DictionaryMFrozen("__NSFrozenDictionaryM");
static const ConstString g_DictionaryMLegacy("__NSDictionaryM_Legacy");
static const ConstString g_Dictionary0("__NSDictionary0");
static const ConstString g_DictionaryCF("__CFDictionary");
Expand All @@ -520,7 +523,7 @@ lldb_private::formatters::NSDictionarySyntheticFrontEndCreator(

if (class_name == g_DictionaryI) {
return (new NSDictionaryISyntheticFrontEnd(valobj_sp));
} else if (class_name == g_DictionaryM) {
} else if (class_name == g_DictionaryM || class_name == g_DictionaryMFrozen) {
if (runtime->GetFoundationVersion() >= 1437) {
return (new Foundation1437::NSDictionaryMSyntheticFrontEnd(valobj_sp));
} else if (runtime->GetFoundationVersion() >= 1428) {
Expand Down
Expand Up @@ -20,7 +20,7 @@ def test_nscontainers_with_run_command(self):

def nscontainers_data_formatter_commands(self):
self.expect(
'frame variable newArray nsDictionary newDictionary nscfDictionary cfDictionaryRef newMutableDictionary newMutableDictionaryRef cfarray_ref mutable_array_ref',
'frame variable newArray nsDictionary newDictionary nscfDictionary cfDictionaryRef newMutableDictionary copyDictionary newMutableDictionaryRef cfarray_ref mutable_array_ref',
substrs=[
'(NSArray *) newArray = ',
' @"50 elements"',
Expand All @@ -34,6 +34,8 @@ def nscontainers_data_formatter_commands(self):
' 2 key/value pairs',
'(NSDictionary *) newMutableDictionary = ',
' 21 key/value pairs',
'(NSMutableDictionary *) copyDictionary = ',
' 21 key/value pairs',
'(CFMutableDictionaryRef) newMutableDictionaryRef = ',
' 21 key/value pairs',
'(CFArrayRef) cfarray_ref = ',
Expand All @@ -42,6 +44,9 @@ def nscontainers_data_formatter_commands(self):
' @"11 elements"',
])

self.expect('frame var -d run-target copyDictionary[10]',
substrs=['@"bar9"', '@"foo"'])

self.expect(
'frame variable -d run-target *nscfDictionary',
patterns=[
Expand Down
Expand Up @@ -476,6 +476,10 @@ int main(int argc, const char *argv[]) {
[newMutableDictionary setObject:@"foo" forKey:@"bar19"];
[newMutableDictionary setObject:@"foo" forKey:@"bar20"];

/* Copying an NSMutableDictionary makes a different member of the
class cluster, so let's also make a copy of this one: */
NSMutableDictionary *copyDictionary = [newMutableDictionary copy];

CFMutableDictionaryRef newMutableDictionaryRef = CFDictionaryCreateMutableCopy(kCFAllocatorDefault, 0, newMutableDictionary);

id cfKeys[4] = {@"foo", @"bar", @"baz", @"quux"};
Expand Down

0 comments on commit 4eabb12

Please sign in to comment.