Coverage Report

Created: 2022-01-18 06:27

/Users/buildslave/jenkins/workspace/coverage/llvm-project/lldb/source/Plugins/Language/ObjC/NSSet.cpp
Line
Count
Source (jump to first uncovered line)
1
//===-- NSSet.cpp ---------------------------------------------------------===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
9
#include "NSSet.h"
10
#include "CFBasicHash.h"
11
12
#include "Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.h"
13
#include "Plugins/TypeSystem/Clang/TypeSystemClang.h"
14
#include "lldb/Core/ValueObject.h"
15
#include "lldb/Core/ValueObjectConstResult.h"
16
#include "lldb/DataFormatters/FormattersHelpers.h"
17
#include "lldb/Target/Language.h"
18
#include "lldb/Target/Target.h"
19
#include "lldb/Utility/DataBufferHeap.h"
20
#include "lldb/Utility/Endian.h"
21
#include "lldb/Utility/Status.h"
22
#include "lldb/Utility/Stream.h"
23
24
using namespace lldb;
25
using namespace lldb_private;
26
using namespace lldb_private::formatters;
27
28
std::map<ConstString, CXXFunctionSummaryFormat::Callback> &
29
0
NSSet_Additionals::GetAdditionalSummaries() {
30
0
  static std::map<ConstString, CXXFunctionSummaryFormat::Callback> g_map;
31
0
  return g_map;
32
0
}
33
34
std::map<ConstString, CXXSyntheticChildren::CreateFrontEndCallback> &
35
0
NSSet_Additionals::GetAdditionalSynthetics() {
36
0
  static std::map<ConstString, CXXSyntheticChildren::CreateFrontEndCallback>
37
0
      g_map;
38
0
  return g_map;
39
0
}
40
41
namespace lldb_private {
42
namespace formatters {
43
class NSSetISyntheticFrontEnd : public SyntheticChildrenFrontEnd {
44
public:
45
  NSSetISyntheticFrontEnd(lldb::ValueObjectSP valobj_sp);
46
47
  ~NSSetISyntheticFrontEnd() override;
48
49
  size_t CalculateNumChildren() override;
50
51
  lldb::ValueObjectSP GetChildAtIndex(size_t idx) override;
52
53
  bool Update() override;
54
55
  bool MightHaveChildren() override;
56
57
  size_t GetIndexOfChildWithName(ConstString name) override;
58
59
private:
60
  struct DataDescriptor_32 {
61
    uint32_t _used : 26;
62
    uint32_t _szidx : 6;
63
  };
64
65
  struct DataDescriptor_64 {
66
    uint64_t _used : 58;
67
    uint32_t _szidx : 6;
68
  };
69
70
  struct SetItemDescriptor {
71
    lldb::addr_t item_ptr;
72
    lldb::ValueObjectSP valobj_sp;
73
  };
74
75
  ExecutionContextRef m_exe_ctx_ref;
76
  uint8_t m_ptr_size;
77
  DataDescriptor_32 *m_data_32;
78
  DataDescriptor_64 *m_data_64;
79
  lldb::addr_t m_data_ptr;
80
  std::vector<SetItemDescriptor> m_children;
81
};
82
83
class NSCFSetSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
84
public:
85
  NSCFSetSyntheticFrontEnd(lldb::ValueObjectSP valobj_sp);
86
87
  size_t CalculateNumChildren() override;
88
89
  lldb::ValueObjectSP GetChildAtIndex(size_t idx) override;
90
91
  bool Update() override;
92
93
  bool MightHaveChildren() override;
94
95
  size_t GetIndexOfChildWithName(ConstString name) override;
96
97
private:
98
  struct SetItemDescriptor {
99
    lldb::addr_t item_ptr;
100
    lldb::ValueObjectSP valobj_sp;
101
  };
102
103
  ExecutionContextRef m_exe_ctx_ref;
104
  uint8_t m_ptr_size;
105
  lldb::ByteOrder m_order;
106
107
  CFBasicHash m_hashtable;
108
109
  CompilerType m_pair_type;
110
  std::vector<SetItemDescriptor> m_children;
111
};
112
113
template <typename D32, typename D64>
114
class GenericNSSetMSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
115
public:
116
  GenericNSSetMSyntheticFrontEnd(lldb::ValueObjectSP valobj_sp);
117
118
  ~GenericNSSetMSyntheticFrontEnd() override;
119
120
  size_t CalculateNumChildren() override;
121
122
  lldb::ValueObjectSP GetChildAtIndex(size_t idx) override;
123
124
  bool Update() override;
125
126
  bool MightHaveChildren() override;
127
128
  size_t GetIndexOfChildWithName(ConstString name) override;
129
130
private:
131
132
  struct SetItemDescriptor {
133
    lldb::addr_t item_ptr;
134
    lldb::ValueObjectSP valobj_sp;
135
  };
136
137
  ExecutionContextRef m_exe_ctx_ref;
138
  uint8_t m_ptr_size;
139
  D32 *m_data_32;
140
  D64 *m_data_64;
141
  std::vector<SetItemDescriptor> m_children;
142
};
143
  
144
namespace Foundation1300 {
145
  struct DataDescriptor_32 {
146
    uint32_t _used : 26;
147
    uint32_t _size;
148
    uint32_t _mutations;
149
    uint32_t _objs_addr;
150
  };
151
  
152
  struct DataDescriptor_64 {
153
    uint64_t _used : 58;
154
    uint64_t _size;
155
    uint64_t _mutations;
156
    uint64_t _objs_addr;
157
  };
158
  
159
  using NSSetMSyntheticFrontEnd =
160
      GenericNSSetMSyntheticFrontEnd<DataDescriptor_32, DataDescriptor_64>;
161
}
162
  
163
namespace Foundation1428 {
164
  struct DataDescriptor_32 {
165
    uint32_t _used : 26;
166
    uint32_t _size;
167
    uint32_t _objs_addr;
168
    uint32_t _mutations;
169
  };
170
  
171
  struct DataDescriptor_64 {
172
    uint64_t _used : 58;
173
    uint64_t _size;
174
    uint64_t _objs_addr;
175
    uint64_t _mutations;
176
  };
177
  
178
  using NSSetMSyntheticFrontEnd =
179
      GenericNSSetMSyntheticFrontEnd<DataDescriptor_32, DataDescriptor_64>;
180
}
181
  
182
namespace Foundation1437 {
183
  struct DataDescriptor_32 {
184
    uint32_t _cow;
185
    // __table storage
186
    uint32_t _objs_addr;
187
    uint32_t _muts;
188
    uint32_t _used : 26;
189
    uint32_t _szidx : 6;
190
  };
191
  
192
  struct DataDescriptor_64 {
193
    uint64_t _cow;
194
    // __Table storage
195
    uint64_t _objs_addr;
196
    uint32_t _muts;
197
    uint32_t _used : 26;
198
    uint32_t _szidx : 6;
199
  };
200
  
201
  using NSSetMSyntheticFrontEnd =
202
      GenericNSSetMSyntheticFrontEnd<DataDescriptor_32, DataDescriptor_64>;
203
  
204
  template <typename DD>
205
  uint64_t
206
  __NSSetMSize_Impl(lldb_private::Process &process, lldb::addr_t valobj_addr,
207
48
                    Status &error) {
208
48
    const lldb::addr_t start_of_descriptor =
209
48
        valobj_addr + process.GetAddressByteSize();
210
48
    DD descriptor = DD();
211
48
    process.ReadMemory(start_of_descriptor, &descriptor, sizeof(descriptor),
212
48
                       error);
213
48
    if (error.Fail()) {
214
0
      return 0;
215
0
    }
216
48
    return descriptor._used;
217
48
  }
Unexecuted instantiation: unsigned long long lldb_private::formatters::Foundation1437::__NSSetMSize_Impl<lldb_private::formatters::Foundation1437::DataDescriptor_32>(lldb_private::Process&, unsigned long long, lldb_private::Status&)
unsigned long long lldb_private::formatters::Foundation1437::__NSSetMSize_Impl<lldb_private::formatters::Foundation1437::DataDescriptor_64>(lldb_private::Process&, unsigned long long, lldb_private::Status&)
Line
Count
Source
207
48
                    Status &error) {
208
48
    const lldb::addr_t start_of_descriptor =
209
48
        valobj_addr + process.GetAddressByteSize();
210
48
    DD descriptor = DD();
211
48
    process.ReadMemory(start_of_descriptor, &descriptor, sizeof(descriptor),
212
48
                       error);
213
48
    if (error.Fail()) {
214
0
      return 0;
215
0
    }
216
48
    return descriptor._used;
217
48
  }
218
  
219
  uint64_t
220
  __NSSetMSize(lldb_private::Process &process, lldb::addr_t valobj_addr,
221
48
               Status &error) {
222
48
    if (process.GetAddressByteSize() == 4) {
223
0
      return __NSSetMSize_Impl<DataDescriptor_32>(process, valobj_addr, error);
224
48
    } else {
225
48
      return __NSSetMSize_Impl<DataDescriptor_64>(process, valobj_addr, error);
226
48
    }
227
48
  }
228
}
229
  
230
class NSSetCodeRunningSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
231
public:
232
  NSSetCodeRunningSyntheticFrontEnd(lldb::ValueObjectSP valobj_sp);
233
234
  ~NSSetCodeRunningSyntheticFrontEnd() override;
235
236
  size_t CalculateNumChildren() override;
237
238
  lldb::ValueObjectSP GetChildAtIndex(size_t idx) override;
239
240
  bool Update() override;
241
242
  bool MightHaveChildren() override;
243
244
  size_t GetIndexOfChildWithName(ConstString name) override;
245
};
246
} // namespace formatters
247
} // namespace lldb_private
248
249
template <bool cf_style>
250
bool lldb_private::formatters::NSSetSummaryProvider(
251
102
    ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
252
102
  static ConstString g_TypeHint("NSSet");
253
254
102
  ProcessSP process_sp = valobj.GetProcessSP();
255
102
  if (!process_sp)
256
0
    return false;
257
258
102
  ObjCLanguageRuntime *runtime = ObjCLanguageRuntime::Get(*process_sp);
259
260
102
  if (!runtime)
261
0
    return false;
262
263
102
  ObjCLanguageRuntime::ClassDescriptorSP descriptor(
264
102
      runtime->GetClassDescriptor(valobj));
265
266
102
  if (!descriptor || 
!descriptor->IsValid()98
)
267
4
    return false;
268
269
98
  uint32_t ptr_size = process_sp->GetAddressByteSize();
270
98
  bool is_64bit = (ptr_size == 8);
271
272
98
  lldb::addr_t valobj_addr = valobj.GetValueAsUnsigned(0);
273
274
98
  if (!valobj_addr)
275
8
    return false;
276
277
90
  uint64_t value = 0;
278
279
90
  ConstString class_name(descriptor->GetClassName());
280
281
90
  static const ConstString g_SetI("__NSSetI");
282
90
  static const ConstString g_OrderedSetI("__NSOrderedSetI");
283
90
  static const ConstString g_SetM("__NSSetM");
284
90
  static const ConstString g_SetCF("__NSCFSet");
285
90
  static const ConstString g_SetCFRef("CFSetRef");
286
287
90
  if (class_name.IsEmpty())
288
0
    return false;
289
290
90
  if (class_name == g_SetI || 
class_name == g_OrderedSetI72
) {
291
24
    Status error;
292
24
    value = process_sp->ReadUnsignedIntegerFromMemory(valobj_addr + ptr_size,
293
24
                                                      ptr_size, 0, error);
294
24
    if (error.Fail())
295
0
      return false;
296
24
    value &= (is_64bit ? ~0xFC00000000000000UL : 
~0xFC000000U0
);
297
66
  } else if (class_name == g_SetM) {
298
48
    AppleObjCRuntime *apple_runtime =
299
48
        llvm::dyn_cast_or_null<AppleObjCRuntime>(runtime);
300
48
    Status error;
301
48
    if (apple_runtime && apple_runtime->GetFoundationVersion() >= 1437) {
302
48
      value = Foundation1437::__NSSetMSize(*process_sp, valobj_addr, error);
303
48
    } else {
304
0
      value = process_sp->ReadUnsignedIntegerFromMemory(valobj_addr + ptr_size,
305
0
                                                        ptr_size, 0, error);
306
0
      value &= (is_64bit ? ~0xFC00000000000000UL : ~0xFC000000U);
307
0
    }
308
48
    if (error.Fail())
309
0
      return false;
310
48
  } else 
if (18
class_name == g_SetCF18
||
class_name == g_SetCFRef0
) {
311
18
    ExecutionContext exe_ctx(process_sp);
312
18
    CFBasicHash cfbh;
313
18
    if (!cfbh.Update(valobj_addr, exe_ctx))
314
0
      return false;
315
18
    value = cfbh.GetCount();
316
18
  } else {
317
0
    auto &map(NSSet_Additionals::GetAdditionalSummaries());
318
0
    auto iter = map.find(class_name), end = map.end();
319
0
    if (iter != end)
320
0
      return iter->second(valobj, stream, options);
321
0
    else
322
0
      return false;
323
0
  }
324
325
90
  std::string prefix, suffix;
326
90
  if (Language *language = Language::FindPlugin(options.GetLanguage())) {
327
90
    if (!language->GetFormatterPrefixSuffix(valobj, g_TypeHint, prefix,
328
90
                                            suffix)) {
329
90
      prefix.clear();
330
90
      suffix.clear();
331
90
    }
332
90
  }
333
334
90
  stream.Printf("%s%" PRIu64 " %s%s%s", prefix.c_str(), value, "element",
335
90
                value == 1 ? 
""0
: "s", suffix.c_str());
336
90
  return true;
337
90
}
bool lldb_private::formatters::NSSetSummaryProvider<true>(lldb_private::ValueObject&, lldb_private::Stream&, lldb_private::TypeSummaryOptions const&)
Line
Count
Source
251
9
    ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
252
9
  static ConstString g_TypeHint("NSSet");
253
254
9
  ProcessSP process_sp = valobj.GetProcessSP();
255
9
  if (!process_sp)
256
0
    return false;
257
258
9
  ObjCLanguageRuntime *runtime = ObjCLanguageRuntime::Get(*process_sp);
259
260
9
  if (!runtime)
261
0
    return false;
262
263
9
  ObjCLanguageRuntime::ClassDescriptorSP descriptor(
264
9
      runtime->GetClassDescriptor(valobj));
265
266
9
  if (!descriptor || !descriptor->IsValid())
267
0
    return false;
268
269
9
  uint32_t ptr_size = process_sp->GetAddressByteSize();
270
9
  bool is_64bit = (ptr_size == 8);
271
272
9
  lldb::addr_t valobj_addr = valobj.GetValueAsUnsigned(0);
273
274
9
  if (!valobj_addr)
275
0
    return false;
276
277
9
  uint64_t value = 0;
278
279
9
  ConstString class_name(descriptor->GetClassName());
280
281
9
  static const ConstString g_SetI("__NSSetI");
282
9
  static const ConstString g_OrderedSetI("__NSOrderedSetI");
283
9
  static const ConstString g_SetM("__NSSetM");
284
9
  static const ConstString g_SetCF("__NSCFSet");
285
9
  static const ConstString g_SetCFRef("CFSetRef");
286
287
9
  if (class_name.IsEmpty())
288
0
    return false;
289
290
9
  if (class_name == g_SetI || class_name == g_OrderedSetI) {
291
0
    Status error;
292
0
    value = process_sp->ReadUnsignedIntegerFromMemory(valobj_addr + ptr_size,
293
0
                                                      ptr_size, 0, error);
294
0
    if (error.Fail())
295
0
      return false;
296
0
    value &= (is_64bit ? ~0xFC00000000000000UL : ~0xFC000000U);
297
9
  } else if (class_name == g_SetM) {
298
0
    AppleObjCRuntime *apple_runtime =
299
0
        llvm::dyn_cast_or_null<AppleObjCRuntime>(runtime);
300
0
    Status error;
301
0
    if (apple_runtime && apple_runtime->GetFoundationVersion() >= 1437) {
302
0
      value = Foundation1437::__NSSetMSize(*process_sp, valobj_addr, error);
303
0
    } else {
304
0
      value = process_sp->ReadUnsignedIntegerFromMemory(valobj_addr + ptr_size,
305
0
                                                        ptr_size, 0, error);
306
0
      value &= (is_64bit ? ~0xFC00000000000000UL : ~0xFC000000U);
307
0
    }
308
0
    if (error.Fail())
309
0
      return false;
310
9
  } else if (class_name == g_SetCF || 
class_name == g_SetCFRef0
) {
311
9
    ExecutionContext exe_ctx(process_sp);
312
9
    CFBasicHash cfbh;
313
9
    if (!cfbh.Update(valobj_addr, exe_ctx))
314
0
      return false;
315
9
    value = cfbh.GetCount();
316
9
  } else {
317
0
    auto &map(NSSet_Additionals::GetAdditionalSummaries());
318
0
    auto iter = map.find(class_name), end = map.end();
319
0
    if (iter != end)
320
0
      return iter->second(valobj, stream, options);
321
0
    else
322
0
      return false;
323
0
  }
324
325
9
  std::string prefix, suffix;
326
9
  if (Language *language = Language::FindPlugin(options.GetLanguage())) {
327
9
    if (!language->GetFormatterPrefixSuffix(valobj, g_TypeHint, prefix,
328
9
                                            suffix)) {
329
9
      prefix.clear();
330
9
      suffix.clear();
331
9
    }
332
9
  }
333
334
9
  stream.Printf("%s%" PRIu64 " %s%s%s", prefix.c_str(), value, "element",
335
9
                value == 1 ? 
""0
: "s", suffix.c_str());
336
9
  return true;
337
9
}
bool lldb_private::formatters::NSSetSummaryProvider<false>(lldb_private::ValueObject&, lldb_private::Stream&, lldb_private::TypeSummaryOptions const&)
Line
Count
Source
251
93
    ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
252
93
  static ConstString g_TypeHint("NSSet");
253
254
93
  ProcessSP process_sp = valobj.GetProcessSP();
255
93
  if (!process_sp)
256
0
    return false;
257
258
93
  ObjCLanguageRuntime *runtime = ObjCLanguageRuntime::Get(*process_sp);
259
260
93
  if (!runtime)
261
0
    return false;
262
263
93
  ObjCLanguageRuntime::ClassDescriptorSP descriptor(
264
93
      runtime->GetClassDescriptor(valobj));
265
266
93
  if (!descriptor || 
!descriptor->IsValid()89
)
267
4
    return false;
268
269
89
  uint32_t ptr_size = process_sp->GetAddressByteSize();
270
89
  bool is_64bit = (ptr_size == 8);
271
272
89
  lldb::addr_t valobj_addr = valobj.GetValueAsUnsigned(0);
273
274
89
  if (!valobj_addr)
275
8
    return false;
276
277
81
  uint64_t value = 0;
278
279
81
  ConstString class_name(descriptor->GetClassName());
280
281
81
  static const ConstString g_SetI("__NSSetI");
282
81
  static const ConstString g_OrderedSetI("__NSOrderedSetI");
283
81
  static const ConstString g_SetM("__NSSetM");
284
81
  static const ConstString g_SetCF("__NSCFSet");
285
81
  static const ConstString g_SetCFRef("CFSetRef");
286
287
81
  if (class_name.IsEmpty())
288
0
    return false;
289
290
81
  if (class_name == g_SetI || 
class_name == g_OrderedSetI63
) {
291
24
    Status error;
292
24
    value = process_sp->ReadUnsignedIntegerFromMemory(valobj_addr + ptr_size,
293
24
                                                      ptr_size, 0, error);
294
24
    if (error.Fail())
295
0
      return false;
296
24
    value &= (is_64bit ? ~0xFC00000000000000UL : 
~0xFC000000U0
);
297
57
  } else if (class_name == g_SetM) {
298
48
    AppleObjCRuntime *apple_runtime =
299
48
        llvm::dyn_cast_or_null<AppleObjCRuntime>(runtime);
300
48
    Status error;
301
48
    if (apple_runtime && apple_runtime->GetFoundationVersion() >= 1437) {
302
48
      value = Foundation1437::__NSSetMSize(*process_sp, valobj_addr, error);
303
48
    } else {
304
0
      value = process_sp->ReadUnsignedIntegerFromMemory(valobj_addr + ptr_size,
305
0
                                                        ptr_size, 0, error);
306
0
      value &= (is_64bit ? ~0xFC00000000000000UL : ~0xFC000000U);
307
0
    }
308
48
    if (error.Fail())
309
0
      return false;
310
48
  } else 
if (9
class_name == g_SetCF9
||
class_name == g_SetCFRef0
) {
311
9
    ExecutionContext exe_ctx(process_sp);
312
9
    CFBasicHash cfbh;
313
9
    if (!cfbh.Update(valobj_addr, exe_ctx))
314
0
      return false;
315
9
    value = cfbh.GetCount();
316
9
  } else {
317
0
    auto &map(NSSet_Additionals::GetAdditionalSummaries());
318
0
    auto iter = map.find(class_name), end = map.end();
319
0
    if (iter != end)
320
0
      return iter->second(valobj, stream, options);
321
0
    else
322
0
      return false;
323
0
  }
324
325
81
  std::string prefix, suffix;
326
81
  if (Language *language = Language::FindPlugin(options.GetLanguage())) {
327
81
    if (!language->GetFormatterPrefixSuffix(valobj, g_TypeHint, prefix,
328
81
                                            suffix)) {
329
81
      prefix.clear();
330
81
      suffix.clear();
331
81
    }
332
81
  }
333
334
81
  stream.Printf("%s%" PRIu64 " %s%s%s", prefix.c_str(), value, "element",
335
81
                value == 1 ? 
""0
: "s", suffix.c_str());
336
81
  return true;
337
81
}
338
339
SyntheticChildrenFrontEnd *
340
lldb_private::formatters::NSSetSyntheticFrontEndCreator(
341
132
    CXXSyntheticChildren *synth, lldb::ValueObjectSP valobj_sp) {
342
132
  lldb::ProcessSP process_sp(valobj_sp->GetProcessSP());
343
132
  if (!process_sp)
344
0
    return nullptr;
345
132
  ObjCLanguageRuntime *runtime = ObjCLanguageRuntime::Get(*process_sp);
346
132
  if (!runtime)
347
0
    return nullptr;
348
349
132
  CompilerType valobj_type(valobj_sp->GetCompilerType());
350
132
  Flags flags(valobj_type.GetTypeInfo());
351
352
132
  if (flags.IsClear(eTypeIsPointer)) {
353
12
    Status error;
354
12
    valobj_sp = valobj_sp->AddressOf(error);
355
12
    if (error.Fail() || !valobj_sp)
356
0
      return nullptr;
357
12
  }
358
359
132
  ObjCLanguageRuntime::ClassDescriptorSP descriptor(
360
132
      runtime->GetClassDescriptor(*valobj_sp));
361
362
132
  if (!descriptor || !descriptor->IsValid())
363
0
    return nullptr;
364
365
132
  ConstString class_name = descriptor->GetClassName();
366
367
132
  static const ConstString g_SetI("__NSSetI");
368
132
  static const ConstString g_OrderedSetI("__NSOrderedSetI");
369
132
  static const ConstString g_SetM("__NSSetM");
370
132
  static const ConstString g_SetCF("__NSCFSet");
371
132
  static const ConstString g_SetCFRef("CFSetRef");
372
373
132
  if (class_name.IsEmpty())
374
0
    return nullptr;
375
376
132
  if (class_name == g_SetI || 
class_name == g_OrderedSetI108
) {
377
42
    return (new NSSetISyntheticFrontEnd(valobj_sp));
378
90
  } else if (class_name == g_SetM) {
379
66
    AppleObjCRuntime *apple_runtime =
380
66
        llvm::dyn_cast_or_null<AppleObjCRuntime>(runtime);
381
66
    if (apple_runtime) {
382
66
      if (apple_runtime->GetFoundationVersion() >= 1437)
383
66
        return (new Foundation1437::NSSetMSyntheticFrontEnd(valobj_sp));
384
0
      else if (apple_runtime->GetFoundationVersion() >= 1428)
385
0
        return (new Foundation1428::NSSetMSyntheticFrontEnd(valobj_sp));
386
0
      else
387
0
        return (new Foundation1300::NSSetMSyntheticFrontEnd(valobj_sp));
388
66
    } else {
389
0
      return (new Foundation1300::NSSetMSyntheticFrontEnd(valobj_sp));
390
0
    }
391
66
  } else 
if (24
class_name == g_SetCF24
||
class_name == g_SetCFRef0
) {
392
24
    return (new NSCFSetSyntheticFrontEnd(valobj_sp));
393
24
  } else {
394
0
    auto &map(NSSet_Additionals::GetAdditionalSynthetics());
395
0
    auto iter = map.find(class_name), end = map.end();
396
0
    if (iter != end)
397
0
      return iter->second(synth, valobj_sp);
398
0
    return nullptr;
399
0
  }
400
132
}
401
402
lldb_private::formatters::NSSetISyntheticFrontEnd::NSSetISyntheticFrontEnd(
403
    lldb::ValueObjectSP valobj_sp)
404
    : SyntheticChildrenFrontEnd(*valobj_sp), m_exe_ctx_ref(), m_ptr_size(8),
405
42
      m_data_32(nullptr), m_data_64(nullptr) {
406
42
  if (valobj_sp)
407
42
    Update();
408
42
}
409
410
42
lldb_private::formatters::NSSetISyntheticFrontEnd::~NSSetISyntheticFrontEnd() {
411
42
  delete m_data_32;
412
42
  m_data_32 = nullptr;
413
42
  delete m_data_64;
414
42
  m_data_64 = nullptr;
415
42
}
416
417
size_t
418
lldb_private::formatters::NSSetISyntheticFrontEnd::GetIndexOfChildWithName(
419
0
    ConstString name) {
420
0
  const char *item_name = name.GetCString();
421
0
  uint32_t idx = ExtractIndexFromString(item_name);
422
0
  if (idx < UINT32_MAX && idx >= CalculateNumChildren())
423
0
    return UINT32_MAX;
424
0
  return idx;
425
0
}
426
427
size_t
428
54
lldb_private::formatters::NSSetISyntheticFrontEnd::CalculateNumChildren() {
429
54
  if (!m_data_32 && !m_data_64)
430
0
    return 0;
431
54
  return (m_data_32 ? 
m_data_32->_used0
: m_data_64->_used);
432
54
}
433
434
72
bool lldb_private::formatters::NSSetISyntheticFrontEnd::Update() {
435
72
  m_children.clear();
436
72
  delete m_data_32;
437
72
  m_data_32 = nullptr;
438
72
  delete m_data_64;
439
72
  m_data_64 = nullptr;
440
72
  m_ptr_size = 0;
441
72
  ValueObjectSP valobj_sp = m_backend.GetSP();
442
72
  if (!valobj_sp)
443
0
    return false;
444
72
  if (!valobj_sp)
445
0
    return false;
446
72
  m_exe_ctx_ref = valobj_sp->GetExecutionContextRef();
447
72
  lldb::ProcessSP process_sp(valobj_sp->GetProcessSP());
448
72
  if (!process_sp)
449
0
    return false;
450
72
  m_ptr_size = process_sp->GetAddressByteSize();
451
72
  uint64_t data_location = valobj_sp->GetValueAsUnsigned(0) + m_ptr_size;
452
72
  Status error;
453
72
  if (m_ptr_size == 4) {
454
0
    m_data_32 = new DataDescriptor_32();
455
0
    process_sp->ReadMemory(data_location, m_data_32, sizeof(DataDescriptor_32),
456
0
                           error);
457
72
  } else {
458
72
    m_data_64 = new DataDescriptor_64();
459
72
    process_sp->ReadMemory(data_location, m_data_64, sizeof(DataDescriptor_64),
460
72
                           error);
461
72
  }
462
72
  if (error.Fail())
463
0
    return false;
464
72
  m_data_ptr = data_location + m_ptr_size;
465
72
  return false;
466
72
}
467
468
0
bool lldb_private::formatters::NSSetISyntheticFrontEnd::MightHaveChildren() {
469
0
  return true;
470
0
}
471
472
lldb::ValueObjectSP
473
42
lldb_private::formatters::NSSetISyntheticFrontEnd::GetChildAtIndex(size_t idx) {
474
42
  uint32_t num_children = CalculateNumChildren();
475
476
42
  if (idx >= num_children)
477
0
    return lldb::ValueObjectSP();
478
479
42
  ProcessSP process_sp = m_exe_ctx_ref.GetProcessSP();
480
42
  if (!process_sp)
481
0
    return lldb::ValueObjectSP();
482
483
42
  if (m_children.empty()) {
484
    // do the scan phase
485
12
    lldb::addr_t obj_at_idx = 0;
486
487
12
    uint32_t tries = 0;
488
12
    uint32_t test_idx = 0;
489
490
72
    while (tries < num_children) {
491
60
      obj_at_idx = m_data_ptr + (test_idx * m_ptr_size);
492
60
      if (!process_sp)
493
0
        return lldb::ValueObjectSP();
494
60
      Status error;
495
60
      obj_at_idx = process_sp->ReadPointerFromMemory(obj_at_idx, error);
496
60
      if (error.Fail())
497
0
        return lldb::ValueObjectSP();
498
499
60
      test_idx++;
500
501
60
      if (!obj_at_idx)
502
18
        continue;
503
42
      tries++;
504
505
42
      SetItemDescriptor descriptor = {obj_at_idx, lldb::ValueObjectSP()};
506
507
42
      m_children.push_back(descriptor);
508
42
    }
509
12
  }
510
511
42
  if (idx >= m_children.size()) // should never happen
512
0
    return lldb::ValueObjectSP();
513
514
42
  SetItemDescriptor &set_item = m_children[idx];
515
42
  if (!set_item.valobj_sp) {
516
42
    auto ptr_size = process_sp->GetAddressByteSize();
517
42
    DataBufferHeap buffer(ptr_size, 0);
518
42
    switch (ptr_size) {
519
0
    case 0: // architecture has no clue - fail
520
0
      return lldb::ValueObjectSP();
521
0
    case 4:
522
0
      *reinterpret_cast<uint32_t *>(buffer.GetBytes()) =
523
0
          static_cast<uint32_t>(set_item.item_ptr);
524
0
      break;
525
42
    case 8:
526
42
      *reinterpret_cast<uint64_t *>(buffer.GetBytes()) =
527
42
          static_cast<uint64_t>(set_item.item_ptr);
528
42
      break;
529
0
    default:
530
0
      lldbassert(false && "pointer size is not 4 nor 8");
531
42
    }
532
42
    StreamString idx_name;
533
42
    idx_name.Printf("[%" PRIu64 "]", (uint64_t)idx);
534
535
42
    DataExtractor data(buffer.GetBytes(), buffer.GetByteSize(),
536
42
                       process_sp->GetByteOrder(),
537
42
                       process_sp->GetAddressByteSize());
538
539
42
    set_item.valobj_sp = CreateValueObjectFromData(
540
42
        idx_name.GetString(), data, m_exe_ctx_ref,
541
42
        m_backend.GetCompilerType().GetBasicTypeFromAST(
542
42
            lldb::eBasicTypeObjCID));
543
42
  }
544
42
  return set_item.valobj_sp;
545
42
}
546
547
lldb_private::formatters::NSCFSetSyntheticFrontEnd::NSCFSetSyntheticFrontEnd(
548
    lldb::ValueObjectSP valobj_sp)
549
    : SyntheticChildrenFrontEnd(*valobj_sp), m_exe_ctx_ref(), m_ptr_size(8),
550
24
      m_order(lldb::eByteOrderInvalid), m_hashtable(), m_pair_type() {}
551
552
size_t
553
lldb_private::formatters::NSCFSetSyntheticFrontEnd::GetIndexOfChildWithName(
554
0
    ConstString name) {
555
0
  const char *item_name = name.GetCString();
556
0
  const uint32_t idx = ExtractIndexFromString(item_name);
557
0
  if (idx < UINT32_MAX && idx >= CalculateNumChildren())
558
0
    return UINT32_MAX;
559
0
  return idx;
560
0
}
561
562
size_t
563
18
lldb_private::formatters::NSCFSetSyntheticFrontEnd::CalculateNumChildren() {
564
18
  if (!m_hashtable.IsValid())
565
0
    return 0;
566
18
  return m_hashtable.GetCount();
567
18
}
568
569
24
bool lldb_private::formatters::NSCFSetSyntheticFrontEnd::Update() {
570
24
  m_children.clear();
571
24
  ValueObjectSP valobj_sp = m_backend.GetSP();
572
24
  m_ptr_size = 0;
573
24
  if (!valobj_sp)
574
0
    return false;
575
24
  m_exe_ctx_ref = valobj_sp->GetExecutionContextRef();
576
577
24
  lldb::ProcessSP process_sp(valobj_sp->GetProcessSP());
578
24
  if (!process_sp)
579
0
    return false;
580
24
  m_ptr_size = process_sp->GetAddressByteSize();
581
24
  m_order = process_sp->GetByteOrder();
582
24
  return m_hashtable.Update(valobj_sp->GetValueAsUnsigned(0), m_exe_ctx_ref);
583
24
}
584
585
0
bool lldb_private::formatters::NSCFSetSyntheticFrontEnd::MightHaveChildren() {
586
0
  return true;
587
0
}
588
589
lldb::ValueObjectSP
590
lldb_private::formatters::NSCFSetSyntheticFrontEnd::GetChildAtIndex(
591
12
    size_t idx) {
592
12
  lldb::addr_t m_values_ptr = m_hashtable.GetValuePointer();
593
594
12
  const uint32_t num_children = CalculateNumChildren();
595
596
12
  if (idx >= num_children)
597
0
    return lldb::ValueObjectSP();
598
599
12
  if (m_children.empty()) {
600
6
    ProcessSP process_sp = m_exe_ctx_ref.GetProcessSP();
601
6
    if (!process_sp)
602
0
      return lldb::ValueObjectSP();
603
604
6
    Status error;
605
6
    lldb::addr_t val_at_idx = 0;
606
607
6
    uint32_t tries = 0;
608
6
    uint32_t test_idx = 0;
609
610
    // Iterate over inferior memory, reading value pointers by shifting the
611
    // cursor by test_index * m_ptr_size. Returns an empty ValueObject if a read
612
    // fails, otherwise, continue until the number of tries matches the number
613
    // of childen.
614
24
    while (tries < num_children) {
615
18
      val_at_idx = m_values_ptr + (test_idx * m_ptr_size);
616
617
18
      val_at_idx = process_sp->ReadPointerFromMemory(val_at_idx, error);
618
18
      if (error.Fail())
619
0
        return lldb::ValueObjectSP();
620
621
18
      test_idx++;
622
623
18
      if (!val_at_idx)
624
6
        continue;
625
12
      tries++;
626
627
12
      SetItemDescriptor descriptor = {val_at_idx, lldb::ValueObjectSP()};
628
629
12
      m_children.push_back(descriptor);
630
12
    }
631
6
  }
632
633
12
  if (idx >= m_children.size()) // should never happen
634
0
    return lldb::ValueObjectSP();
635
636
12
  SetItemDescriptor &set_item = m_children[idx];
637
12
  if (!set_item.valobj_sp) {
638
639
12
    DataBufferSP buffer_sp(new DataBufferHeap(m_ptr_size, 0));
640
641
12
    switch (m_ptr_size) {
642
0
    case 0: // architecture has no clue - fail
643
0
      return lldb::ValueObjectSP();
644
0
    case 4:
645
0
      *reinterpret_cast<uint32_t *>(buffer_sp->GetBytes()) =
646
0
          static_cast<uint32_t>(set_item.item_ptr);
647
0
      break;
648
12
    case 8:
649
12
      *reinterpret_cast<uint64_t *>(buffer_sp->GetBytes()) =
650
12
          static_cast<uint64_t>(set_item.item_ptr);
651
12
      break;
652
0
    default:
653
0
      lldbassert(false && "pointer size is not 4 nor 8");
654
12
    }
655
12
    StreamString idx_name;
656
12
    idx_name.Printf("[%" PRIu64 "]", (uint64_t)idx);
657
658
12
    DataExtractor data(buffer_sp, m_order, m_ptr_size);
659
660
12
    set_item.valobj_sp = CreateValueObjectFromData(
661
12
        idx_name.GetString(), data, m_exe_ctx_ref,
662
12
        m_backend.GetCompilerType().GetBasicTypeFromAST(
663
12
            lldb::eBasicTypeObjCID));
664
12
  }
665
666
12
  return set_item.valobj_sp;
667
12
}
668
669
template <typename D32, typename D64>
670
lldb_private::formatters::
671
  GenericNSSetMSyntheticFrontEnd<D32, D64>::GenericNSSetMSyntheticFrontEnd(
672
    lldb::ValueObjectSP valobj_sp)
673
    : SyntheticChildrenFrontEnd(*valobj_sp), m_exe_ctx_ref(), m_ptr_size(8),
674
66
      m_data_32(nullptr), m_data_64(nullptr) {
675
66
  if (valobj_sp)
676
66
    Update();
677
66
}
lldb_private::formatters::GenericNSSetMSyntheticFrontEnd<lldb_private::formatters::Foundation1437::DataDescriptor_32, lldb_private::formatters::Foundation1437::DataDescriptor_64>::GenericNSSetMSyntheticFrontEnd(std::__1::shared_ptr<lldb_private::ValueObject>)
Line
Count
Source
674
66
      m_data_32(nullptr), m_data_64(nullptr) {
675
66
  if (valobj_sp)
676
66
    Update();
677
66
}
Unexecuted instantiation: lldb_private::formatters::GenericNSSetMSyntheticFrontEnd<lldb_private::formatters::Foundation1428::DataDescriptor_32, lldb_private::formatters::Foundation1428::DataDescriptor_64>::GenericNSSetMSyntheticFrontEnd(std::__1::shared_ptr<lldb_private::ValueObject>)
Unexecuted instantiation: lldb_private::formatters::GenericNSSetMSyntheticFrontEnd<lldb_private::formatters::Foundation1300::DataDescriptor_32, lldb_private::formatters::Foundation1300::DataDescriptor_64>::GenericNSSetMSyntheticFrontEnd(std::__1::shared_ptr<lldb_private::ValueObject>)
678
679
template <typename D32, typename D64>
680
lldb_private::formatters::
681
66
  GenericNSSetMSyntheticFrontEnd<D32, D64>::~GenericNSSetMSyntheticFrontEnd<D32, D64>() {
682
66
  delete m_data_32;
683
66
  m_data_32 = nullptr;
684
66
  delete m_data_64;
685
66
  m_data_64 = nullptr;
686
66
}
lldb_private::formatters::GenericNSSetMSyntheticFrontEnd<lldb_private::formatters::Foundation1437::DataDescriptor_32, lldb_private::formatters::Foundation1437::DataDescriptor_64>::~GenericNSSetMSyntheticFrontEnd()
Line
Count
Source
681
66
  GenericNSSetMSyntheticFrontEnd<D32, D64>::~GenericNSSetMSyntheticFrontEnd<D32, D64>() {
682
66
  delete m_data_32;
683
66
  m_data_32 = nullptr;
684
66
  delete m_data_64;
685
66
  m_data_64 = nullptr;
686
66
}
Unexecuted instantiation: lldb_private::formatters::GenericNSSetMSyntheticFrontEnd<lldb_private::formatters::Foundation1428::DataDescriptor_32, lldb_private::formatters::Foundation1428::DataDescriptor_64>::~GenericNSSetMSyntheticFrontEnd()
Unexecuted instantiation: lldb_private::formatters::GenericNSSetMSyntheticFrontEnd<lldb_private::formatters::Foundation1300::DataDescriptor_32, lldb_private::formatters::Foundation1300::DataDescriptor_64>::~GenericNSSetMSyntheticFrontEnd()
687
688
template <typename D32, typename D64>
689
size_t
690
lldb_private::formatters::
691
  GenericNSSetMSyntheticFrontEnd<D32, D64>::GetIndexOfChildWithName(
692
0
    ConstString name) {
693
0
  const char *item_name = name.GetCString();
694
0
  uint32_t idx = ExtractIndexFromString(item_name);
695
0
  if (idx < UINT32_MAX && idx >= CalculateNumChildren())
696
0
    return UINT32_MAX;
697
0
  return idx;
698
0
}
Unexecuted instantiation: lldb_private::formatters::GenericNSSetMSyntheticFrontEnd<lldb_private::formatters::Foundation1437::DataDescriptor_32, lldb_private::formatters::Foundation1437::DataDescriptor_64>::GetIndexOfChildWithName(lldb_private::ConstString)
Unexecuted instantiation: lldb_private::formatters::GenericNSSetMSyntheticFrontEnd<lldb_private::formatters::Foundation1428::DataDescriptor_32, lldb_private::formatters::Foundation1428::DataDescriptor_64>::GetIndexOfChildWithName(lldb_private::ConstString)
Unexecuted instantiation: lldb_private::formatters::GenericNSSetMSyntheticFrontEnd<lldb_private::formatters::Foundation1300::DataDescriptor_32, lldb_private::formatters::Foundation1300::DataDescriptor_64>::GetIndexOfChildWithName(lldb_private::ConstString)
699
700
template <typename D32, typename D64>
701
size_t
702
lldb_private::formatters::
703
120
  GenericNSSetMSyntheticFrontEnd<D32, D64>::CalculateNumChildren() {
704
120
  if (!m_data_32 && !m_data_64)
705
0
    return 0;
706
120
  return (m_data_32 ? 
m_data_32->_used0
: m_data_64->_used);
707
120
}
lldb_private::formatters::GenericNSSetMSyntheticFrontEnd<lldb_private::formatters::Foundation1437::DataDescriptor_32, lldb_private::formatters::Foundation1437::DataDescriptor_64>::CalculateNumChildren()
Line
Count
Source
703
120
  GenericNSSetMSyntheticFrontEnd<D32, D64>::CalculateNumChildren() {
704
120
  if (!m_data_32 && !m_data_64)
705
0
    return 0;
706
120
  return (m_data_32 ? 
m_data_32->_used0
: m_data_64->_used);
707
120
}
Unexecuted instantiation: lldb_private::formatters::GenericNSSetMSyntheticFrontEnd<lldb_private::formatters::Foundation1428::DataDescriptor_32, lldb_private::formatters::Foundation1428::DataDescriptor_64>::CalculateNumChildren()
Unexecuted instantiation: lldb_private::formatters::GenericNSSetMSyntheticFrontEnd<lldb_private::formatters::Foundation1300::DataDescriptor_32, lldb_private::formatters::Foundation1300::DataDescriptor_64>::CalculateNumChildren()
708
709
template <typename D32, typename D64>
710
bool
711
lldb_private::formatters::
712
114
  GenericNSSetMSyntheticFrontEnd<D32, D64>::Update() {
713
114
  m_children.clear();
714
114
  ValueObjectSP valobj_sp = m_backend.GetSP();
715
114
  m_ptr_size = 0;
716
114
  delete m_data_32;
717
114
  m_data_32 = nullptr;
718
114
  delete m_data_64;
719
114
  m_data_64 = nullptr;
720
114
  if (!valobj_sp)
721
0
    return false;
722
114
  if (!valobj_sp)
723
0
    return false;
724
114
  m_exe_ctx_ref = valobj_sp->GetExecutionContextRef();
725
114
  lldb::ProcessSP process_sp(valobj_sp->GetProcessSP());
726
114
  if (!process_sp)
727
0
    return false;
728
114
  m_ptr_size = process_sp->GetAddressByteSize();
729
114
  uint64_t data_location = valobj_sp->GetValueAsUnsigned(0) + m_ptr_size;
730
114
  Status error;
731
114
  if (m_ptr_size == 4) {
732
0
    m_data_32 = new D32();
733
0
    process_sp->ReadMemory(data_location, m_data_32, sizeof(D32),
734
0
                           error);
735
114
  } else {
736
114
    m_data_64 = new D64();
737
114
    process_sp->ReadMemory(data_location, m_data_64, sizeof(D64),
738
114
                           error);
739
114
  }
740
114
  if (error.Fail())
741
0
    return false;
742
114
  return false;
743
114
}
lldb_private::formatters::GenericNSSetMSyntheticFrontEnd<lldb_private::formatters::Foundation1437::DataDescriptor_32, lldb_private::formatters::Foundation1437::DataDescriptor_64>::Update()
Line
Count
Source
712
114
  GenericNSSetMSyntheticFrontEnd<D32, D64>::Update() {
713
114
  m_children.clear();
714
114
  ValueObjectSP valobj_sp = m_backend.GetSP();
715
114
  m_ptr_size = 0;
716
114
  delete m_data_32;
717
114
  m_data_32 = nullptr;
718
114
  delete m_data_64;
719
114
  m_data_64 = nullptr;
720
114
  if (!valobj_sp)
721
0
    return false;
722
114
  if (!valobj_sp)
723
0
    return false;
724
114
  m_exe_ctx_ref = valobj_sp->GetExecutionContextRef();
725
114
  lldb::ProcessSP process_sp(valobj_sp->GetProcessSP());
726
114
  if (!process_sp)
727
0
    return false;
728
114
  m_ptr_size = process_sp->GetAddressByteSize();
729
114
  uint64_t data_location = valobj_sp->GetValueAsUnsigned(0) + m_ptr_size;
730
114
  Status error;
731
114
  if (m_ptr_size == 4) {
732
0
    m_data_32 = new D32();
733
0
    process_sp->ReadMemory(data_location, m_data_32, sizeof(D32),
734
0
                           error);
735
114
  } else {
736
114
    m_data_64 = new D64();
737
114
    process_sp->ReadMemory(data_location, m_data_64, sizeof(D64),
738
114
                           error);
739
114
  }
740
114
  if (error.Fail())
741
0
    return false;
742
114
  return false;
743
114
}
Unexecuted instantiation: lldb_private::formatters::GenericNSSetMSyntheticFrontEnd<lldb_private::formatters::Foundation1428::DataDescriptor_32, lldb_private::formatters::Foundation1428::DataDescriptor_64>::Update()
Unexecuted instantiation: lldb_private::formatters::GenericNSSetMSyntheticFrontEnd<lldb_private::formatters::Foundation1300::DataDescriptor_32, lldb_private::formatters::Foundation1300::DataDescriptor_64>::Update()
744
745
template <typename D32, typename D64>
746
bool
747
lldb_private::formatters::
748
0
  GenericNSSetMSyntheticFrontEnd<D32, D64>::MightHaveChildren() {
749
0
  return true;
750
0
}
Unexecuted instantiation: lldb_private::formatters::GenericNSSetMSyntheticFrontEnd<lldb_private::formatters::Foundation1437::DataDescriptor_32, lldb_private::formatters::Foundation1437::DataDescriptor_64>::MightHaveChildren()
Unexecuted instantiation: lldb_private::formatters::GenericNSSetMSyntheticFrontEnd<lldb_private::formatters::Foundation1428::DataDescriptor_32, lldb_private::formatters::Foundation1428::DataDescriptor_64>::MightHaveChildren()
Unexecuted instantiation: lldb_private::formatters::GenericNSSetMSyntheticFrontEnd<lldb_private::formatters::Foundation1300::DataDescriptor_32, lldb_private::formatters::Foundation1300::DataDescriptor_64>::MightHaveChildren()
751
752
template <typename D32, typename D64>
753
lldb::ValueObjectSP
754
lldb_private::formatters::
755
102
  GenericNSSetMSyntheticFrontEnd<D32, D64>::GetChildAtIndex(size_t idx) {
756
102
  lldb::addr_t m_objs_addr =
757
102
      (m_data_32 ? 
m_data_32->_objs_addr0
: m_data_64->_objs_addr);
758
759
102
  uint32_t num_children = CalculateNumChildren();
760
761
102
  if (idx >= num_children)
762
0
    return lldb::ValueObjectSP();
763
764
102
  ProcessSP process_sp = m_exe_ctx_ref.GetProcessSP();
765
102
  if (!process_sp)
766
0
    return lldb::ValueObjectSP();
767
768
102
  if (m_children.empty()) {
769
    // do the scan phase
770
18
    lldb::addr_t obj_at_idx = 0;
771
772
18
    uint32_t tries = 0;
773
18
    uint32_t test_idx = 0;
774
775
240
    while (tries < num_children) {
776
222
      obj_at_idx = m_objs_addr + (test_idx * m_ptr_size);
777
222
      if (!process_sp)
778
0
        return lldb::ValueObjectSP();
779
222
      Status error;
780
222
      obj_at_idx = process_sp->ReadPointerFromMemory(obj_at_idx, error);
781
222
      if (error.Fail())
782
0
        return lldb::ValueObjectSP();
783
784
222
      test_idx++;
785
786
222
      if (!obj_at_idx)
787
120
        continue;
788
102
      tries++;
789
790
102
      SetItemDescriptor descriptor = {obj_at_idx, lldb::ValueObjectSP()};
791
792
102
      m_children.push_back(descriptor);
793
102
    }
794
18
  }
795
796
102
  if (idx >= m_children.size()) // should never happen
797
0
    return lldb::ValueObjectSP();
798
799
102
  SetItemDescriptor &set_item = m_children[idx];
800
102
  if (!set_item.valobj_sp) {
801
102
    auto ptr_size = process_sp->GetAddressByteSize();
802
102
    DataBufferHeap buffer(ptr_size, 0);
803
102
    switch (ptr_size) {
804
0
    case 0: // architecture has no clue?? - fail
805
0
      return lldb::ValueObjectSP();
806
0
    case 4:
807
0
      *((uint32_t *)buffer.GetBytes()) = (uint32_t)set_item.item_ptr;
808
0
      break;
809
102
    case 8:
810
102
      *((uint64_t *)buffer.GetBytes()) = (uint64_t)set_item.item_ptr;
811
102
      break;
812
0
    default:
813
0
      assert(false && "pointer size is not 4 nor 8 - get out of here ASAP");
814
102
    }
815
102
    StreamString idx_name;
816
102
    idx_name.Printf("[%" PRIu64 "]", (uint64_t)idx);
817
818
102
    DataExtractor data(buffer.GetBytes(), buffer.GetByteSize(),
819
102
                       process_sp->GetByteOrder(),
820
102
                       process_sp->GetAddressByteSize());
821
822
102
    set_item.valobj_sp = CreateValueObjectFromData(
823
102
        idx_name.GetString(), data, m_exe_ctx_ref,
824
102
        m_backend.GetCompilerType().GetBasicTypeFromAST(
825
102
            lldb::eBasicTypeObjCID));
826
102
  }
827
102
  return set_item.valobj_sp;
828
102
}
lldb_private::formatters::GenericNSSetMSyntheticFrontEnd<lldb_private::formatters::Foundation1437::DataDescriptor_32, lldb_private::formatters::Foundation1437::DataDescriptor_64>::GetChildAtIndex(unsigned long)
Line
Count
Source
755
102
  GenericNSSetMSyntheticFrontEnd<D32, D64>::GetChildAtIndex(size_t idx) {
756
102
  lldb::addr_t m_objs_addr =
757
102
      (m_data_32 ? 
m_data_32->_objs_addr0
: m_data_64->_objs_addr);
758
759
102
  uint32_t num_children = CalculateNumChildren();
760
761
102
  if (idx >= num_children)
762
0
    return lldb::ValueObjectSP();
763
764
102
  ProcessSP process_sp = m_exe_ctx_ref.GetProcessSP();
765
102
  if (!process_sp)
766
0
    return lldb::ValueObjectSP();
767
768
102
  if (m_children.empty()) {
769
    // do the scan phase
770
18
    lldb::addr_t obj_at_idx = 0;
771
772
18
    uint32_t tries = 0;
773
18
    uint32_t test_idx = 0;
774
775
240
    while (tries < num_children) {
776
222
      obj_at_idx = m_objs_addr + (test_idx * m_ptr_size);
777
222
      if (!process_sp)
778
0
        return lldb::ValueObjectSP();
779
222
      Status error;
780
222
      obj_at_idx = process_sp->ReadPointerFromMemory(obj_at_idx, error);
781
222
      if (error.Fail())
782
0
        return lldb::ValueObjectSP();
783
784
222
      test_idx++;
785
786
222
      if (!obj_at_idx)
787
120
        continue;
788
102
      tries++;
789
790
102
      SetItemDescriptor descriptor = {obj_at_idx, lldb::ValueObjectSP()};
791
792
102
      m_children.push_back(descriptor);
793
102
    }
794
18
  }
795
796
102
  if (idx >= m_children.size()) // should never happen
797
0
    return lldb::ValueObjectSP();
798
799
102
  SetItemDescriptor &set_item = m_children[idx];
800
102
  if (!set_item.valobj_sp) {
801
102
    auto ptr_size = process_sp->GetAddressByteSize();
802
102
    DataBufferHeap buffer(ptr_size, 0);
803
102
    switch (ptr_size) {
804
0
    case 0: // architecture has no clue?? - fail
805
0
      return lldb::ValueObjectSP();
806
0
    case 4:
807
0
      *((uint32_t *)buffer.GetBytes()) = (uint32_t)set_item.item_ptr;
808
0
      break;
809
102
    case 8:
810
102
      *((uint64_t *)buffer.GetBytes()) = (uint64_t)set_item.item_ptr;
811
102
      break;
812
0
    default:
813
0
      assert(false && "pointer size is not 4 nor 8 - get out of here ASAP");
814
102
    }
815
102
    StreamString idx_name;
816
102
    idx_name.Printf("[%" PRIu64 "]", (uint64_t)idx);
817
818
102
    DataExtractor data(buffer.GetBytes(), buffer.GetByteSize(),
819
102
                       process_sp->GetByteOrder(),
820
102
                       process_sp->GetAddressByteSize());
821
822
102
    set_item.valobj_sp = CreateValueObjectFromData(
823
102
        idx_name.GetString(), data, m_exe_ctx_ref,
824
102
        m_backend.GetCompilerType().GetBasicTypeFromAST(
825
102
            lldb::eBasicTypeObjCID));
826
102
  }
827
102
  return set_item.valobj_sp;
828
102
}
Unexecuted instantiation: lldb_private::formatters::GenericNSSetMSyntheticFrontEnd<lldb_private::formatters::Foundation1428::DataDescriptor_32, lldb_private::formatters::Foundation1428::DataDescriptor_64>::GetChildAtIndex(unsigned long)
Unexecuted instantiation: lldb_private::formatters::GenericNSSetMSyntheticFrontEnd<lldb_private::formatters::Foundation1300::DataDescriptor_32, lldb_private::formatters::Foundation1300::DataDescriptor_64>::GetChildAtIndex(unsigned long)
829
830
template bool lldb_private::formatters::NSSetSummaryProvider<true>(
831
    ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options);
832
833
template bool lldb_private::formatters::NSSetSummaryProvider<false>(
834
    ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options);