LLDB mainline
AppleObjCClassDescriptorV2.cpp
Go to the documentation of this file.
1//===-- AppleObjCClassDescriptorV2.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
10
12#include "lldb/Target/ABI.h"
15#include "lldb/Utility/Log.h"
17#include "llvm/ADT/Sequence.h"
18
19using namespace lldb;
20using namespace lldb_private;
21
23 Process *process, std::unique_ptr<objc_class_t> &objc_class) const {
24 objc_class = std::make_unique<objc_class_t>();
25
26 bool ret = objc_class->Read(process, m_objc_class_ptr);
27
28 if (!ret)
29 objc_class.reset();
30
31 return ret;
32}
33
35 switch (process->GetAddressByteSize()) {
36 case 4:
37 return 0xfffffffcUL;
38 case 8:
39 return 0x00007ffffffffff8UL;
40 default:
41 break;
42 }
43
45}
46
48 lldb::addr_t addr) {
49 size_t ptr_size = process->GetAddressByteSize();
50
51 size_t objc_class_size = ptr_size // uintptr_t isa;
52 + ptr_size // Class superclass;
53 + ptr_size // void *cache;
54 + ptr_size // IMP *vtable;
55 + ptr_size; // uintptr_t data_NEVER_USE;
56
57 DataBufferHeap objc_class_buf(objc_class_size, '\0');
59
60 process->ReadMemory(addr, objc_class_buf.GetBytes(), objc_class_size, error);
61 if (error.Fail()) {
62 return false;
63 }
64
65 DataExtractor extractor(objc_class_buf.GetBytes(), objc_class_size,
66 process->GetByteOrder(),
67 process->GetAddressByteSize());
68
69 lldb::offset_t cursor = 0;
70
71 m_isa = extractor.GetAddress_unchecked(&cursor); // uintptr_t isa;
72 m_superclass = extractor.GetAddress_unchecked(&cursor); // Class superclass;
73 m_cache_ptr = extractor.GetAddress_unchecked(&cursor); // void *cache;
74 m_vtable_ptr = extractor.GetAddress_unchecked(&cursor); // IMP *vtable;
75 lldb::addr_t data_NEVER_USE =
76 extractor.GetAddress_unchecked(&cursor); // uintptr_t data_NEVER_USE;
77
78 m_flags = (uint8_t)(data_NEVER_USE & (lldb::addr_t)3);
79 m_data_ptr = data_NEVER_USE & GetClassDataMask(process);
80
81 if (ABISP abi_sp = process->GetABI()) {
82 m_isa = abi_sp->FixCodeAddress(m_isa);
83 m_superclass = abi_sp->FixCodeAddress(m_superclass);
84 m_data_ptr = abi_sp->FixCodeAddress(m_data_ptr);
85 }
86 return true;
87}
88
90 size_t ptr_size = process->GetAddressByteSize();
91
92 size_t size = sizeof(uint32_t) // uint32_t flags;
93 + sizeof(uint32_t) // uint32_t version;
94 + ptr_size // const class_ro_t *ro;
95 + ptr_size // union { method_list_t **method_lists;
96 // method_list_t *method_list; };
97 + ptr_size // struct chained_property_list *properties;
98 + ptr_size // const protocol_list_t **protocols;
99 + ptr_size // Class firstSubclass;
100 + ptr_size; // Class nextSiblingClass;
101
102 DataBufferHeap buffer(size, '\0');
104
105 process->ReadMemory(addr, buffer.GetBytes(), size, error);
106 if (error.Fail()) {
107 return false;
108 }
109
110 DataExtractor extractor(buffer.GetBytes(), size, process->GetByteOrder(),
111 process->GetAddressByteSize());
112
113 lldb::offset_t cursor = 0;
114
115 m_flags = extractor.GetU32_unchecked(&cursor);
116 m_version = extractor.GetU32_unchecked(&cursor);
117 m_ro_ptr = extractor.GetAddress_unchecked(&cursor);
118 if (ABISP abi_sp = process->GetABI())
119 m_ro_ptr = abi_sp->FixCodeAddress(m_ro_ptr);
120 m_method_list_ptr = extractor.GetAddress_unchecked(&cursor);
121 m_properties_ptr = extractor.GetAddress_unchecked(&cursor);
122 m_firstSubclass = extractor.GetAddress_unchecked(&cursor);
123 m_nextSiblingClass = extractor.GetAddress_unchecked(&cursor);
124
125 if (m_ro_ptr & 1) {
126 DataBufferHeap buffer(ptr_size, '\0');
127 process->ReadMemory(m_ro_ptr ^ 1, buffer.GetBytes(), ptr_size, error);
128 if (error.Fail())
129 return false;
130 cursor = 0;
131 DataExtractor extractor(buffer.GetBytes(), ptr_size,
132 process->GetByteOrder(),
133 process->GetAddressByteSize());
134 m_ro_ptr = extractor.GetAddress_unchecked(&cursor);
135 if (ABISP abi_sp = process->GetABI())
136 m_ro_ptr = abi_sp->FixCodeAddress(m_ro_ptr);
137 }
138
139 return true;
140}
141
143 size_t ptr_size = process->GetAddressByteSize();
144
145 size_t size = sizeof(uint32_t) // uint32_t flags;
146 + sizeof(uint32_t) // uint32_t instanceStart;
147 + sizeof(uint32_t) // uint32_t instanceSize;
148 + (ptr_size == 8 ? sizeof(uint32_t)
149 : 0) // uint32_t reserved; // __LP64__ only
150 + ptr_size // const uint8_t *ivarLayout;
151 + ptr_size // const char *name;
152 + ptr_size // const method_list_t *baseMethods;
153 + ptr_size // const protocol_list_t *baseProtocols;
154 + ptr_size // const ivar_list_t *ivars;
155 + ptr_size // const uint8_t *weakIvarLayout;
156 + ptr_size; // const property_list_t *baseProperties;
157
158 DataBufferHeap buffer(size, '\0');
160
161 process->ReadMemory(addr, buffer.GetBytes(), size, error);
162 if (error.Fail()) {
163 return false;
164 }
165
166 DataExtractor extractor(buffer.GetBytes(), size, process->GetByteOrder(),
167 process->GetAddressByteSize());
168
169 lldb::offset_t cursor = 0;
170
171 m_flags = extractor.GetU32_unchecked(&cursor);
172 m_instanceStart = extractor.GetU32_unchecked(&cursor);
173 m_instanceSize = extractor.GetU32_unchecked(&cursor);
174 if (ptr_size == 8)
175 m_reserved = extractor.GetU32_unchecked(&cursor);
176 else
177 m_reserved = 0;
178 m_ivarLayout_ptr = extractor.GetAddress_unchecked(&cursor);
179 m_name_ptr = extractor.GetAddress_unchecked(&cursor);
180 m_baseMethods_ptr = extractor.GetAddress_unchecked(&cursor);
181 m_baseProtocols_ptr = extractor.GetAddress_unchecked(&cursor);
182 m_ivars_ptr = extractor.GetAddress_unchecked(&cursor);
183 m_weakIvarLayout_ptr = extractor.GetAddress_unchecked(&cursor);
184 m_baseProperties_ptr = extractor.GetAddress_unchecked(&cursor);
185
186 DataBufferHeap name_buf(1024, '\0');
187
188 process->ReadCStringFromMemory(m_name_ptr, (char *)name_buf.GetBytes(),
189 name_buf.GetByteSize(), error);
190
191 if (error.Fail()) {
192 return false;
193 }
194
195 m_name.assign((char *)name_buf.GetBytes());
196
197 return true;
198}
199
201 Process *process, const objc_class_t &objc_class,
202 std::unique_ptr<class_ro_t> &class_ro,
203 std::unique_ptr<class_rw_t> &class_rw) const {
204 class_ro.reset();
205 class_rw.reset();
206
208 uint32_t class_row_t_flags = process->ReadUnsignedIntegerFromMemory(
209 objc_class.m_data_ptr, sizeof(uint32_t), 0, error);
210 if (!error.Success())
211 return false;
212
213 if (class_row_t_flags & RW_REALIZED) {
214 class_rw = std::make_unique<class_rw_t>();
215
216 if (!class_rw->Read(process, objc_class.m_data_ptr)) {
217 class_rw.reset();
218 return false;
219 }
220
221 class_ro = std::make_unique<class_ro_t>();
222
223 if (!class_ro->Read(process, class_rw->m_ro_ptr)) {
224 class_rw.reset();
225 class_ro.reset();
226 return false;
227 }
228 } else {
229 class_ro = std::make_unique<class_ro_t>();
230
231 if (!class_ro->Read(process, objc_class.m_data_ptr)) {
232 class_ro.reset();
233 return false;
234 }
235 }
236
237 return true;
238}
239
241 lldb::addr_t addr) {
242 size_t size = sizeof(uint32_t) // uint32_t entsize_NEVER_USE;
243 + sizeof(uint32_t); // uint32_t count;
244
245 DataBufferHeap buffer(size, '\0');
247
248 if (ABISP abi_sp = process->GetABI())
249 addr = abi_sp->FixCodeAddress(addr);
250 process->ReadMemory(addr, buffer.GetBytes(), size, error);
251 if (error.Fail()) {
252 return false;
253 }
254
255 DataExtractor extractor(buffer.GetBytes(), size, process->GetByteOrder(),
256 process->GetAddressByteSize());
257
258 lldb::offset_t cursor = 0;
259
260 uint32_t entsize = extractor.GetU32_unchecked(&cursor);
261 m_is_small = (entsize & 0x80000000) != 0;
262 m_has_direct_selector = (entsize & 0x40000000) != 0;
263 m_has_relative_types = (entsize & 0x20000000) != 0;
264 m_entsize = entsize & 0xfffc;
265 m_count = extractor.GetU32_unchecked(&cursor);
266 m_first_ptr = addr + cursor;
267
268 return true;
269}
270
271llvm::SmallVector<ClassDescriptorV2::method_t, 0>
272ClassDescriptorV2::ReadMethods(llvm::ArrayRef<lldb::addr_t> addresses,
273 lldb::addr_t relative_string_base_addr,
274 bool is_small, bool has_direct_sel,
275 bool has_relative_types) const {
276 lldb_private::Process *process = m_runtime.GetProcess();
277 if (!process)
278 return {};
279
280 const size_t size = method_t::GetSize(process, is_small);
281 const size_t num_methods = addresses.size();
282
283 llvm::SmallVector<uint8_t, 0> buffer(num_methods * size, 0);
284
285 llvm::SmallVector<Range<addr_t, size_t>> mem_ranges =
286 llvm::to_vector(llvm::map_range(llvm::seq(num_methods), [&](size_t idx) {
287 return Range<addr_t, size_t>(addresses[idx], size);
288 }));
289
290 llvm::SmallVector<llvm::MutableArrayRef<uint8_t>> read_results =
291 process->ReadMemoryRanges(mem_ranges, buffer);
292
293 llvm::SmallVector<method_t, 0> methods;
294 methods.reserve(num_methods);
295 for (auto [addr, memory] : llvm::zip(addresses, read_results)) {
296 // Ignore partial reads.
297 if (memory.size() != size)
298 continue;
299
300 DataExtractor extractor(memory.data(), size, process->GetByteOrder(),
301 process->GetAddressByteSize());
302 methods.push_back(method_t());
303 methods.back().Read(extractor, process, addr, relative_string_base_addr,
304 is_small, has_direct_sel, has_relative_types);
305 }
306
307 return methods;
308}
309
311 Process *process, lldb::addr_t addr,
312 lldb::addr_t relative_string_base_addr,
313 bool is_small, bool has_direct_sel,
314 bool has_relative_types) {
315 lldb::offset_t cursor = 0;
316
317 if (is_small) {
318 uint32_t nameref_offset = extractor.GetU32_unchecked(&cursor);
319 uint32_t types_offset = extractor.GetU32_unchecked(&cursor);
320 uint32_t imp_offset = extractor.GetU32_unchecked(&cursor);
321
322 m_name_ptr = addr + nameref_offset;
323
325 if (!has_direct_sel) {
326 // The SEL offset points to a SELRef. We need to dereference twice.
328 if (error.Fail())
329 return false;
330 } else if (relative_string_base_addr != LLDB_INVALID_ADDRESS) {
331 m_name_ptr = relative_string_base_addr + nameref_offset;
332 }
333 if (has_relative_types)
334 m_types_ptr = relative_string_base_addr + types_offset;
335 else
336 m_types_ptr = addr + 4 + types_offset;
337 m_imp_ptr = addr + 8 + imp_offset;
338 } else {
339 m_name_ptr = extractor.GetAddress_unchecked(&cursor);
340 m_types_ptr = extractor.GetAddress_unchecked(&cursor);
341 m_imp_ptr = extractor.GetAddress_unchecked(&cursor);
342 }
343
346 if (error.Fail())
347 return false;
348
350 return error.Success();
351}
352
354 size_t size = sizeof(uint32_t) // uint32_t entsize;
355 + sizeof(uint32_t); // uint32_t count;
356
357 DataBufferHeap buffer(size, '\0');
359
360 process->ReadMemory(addr, buffer.GetBytes(), size, error);
361 if (error.Fail()) {
362 return false;
363 }
364
365 DataExtractor extractor(buffer.GetBytes(), size, process->GetByteOrder(),
366 process->GetAddressByteSize());
367
368 lldb::offset_t cursor = 0;
369
370 m_entsize = extractor.GetU32_unchecked(&cursor);
371 m_count = extractor.GetU32_unchecked(&cursor);
372 m_first_ptr = addr + cursor;
373
374 return true;
375}
376
378 size_t size = GetSize(process);
379
380 DataBufferHeap buffer(size, '\0');
382
383 process->ReadMemory(addr, buffer.GetBytes(), size, error);
384 if (error.Fail()) {
385 return false;
386 }
387
388 DataExtractor extractor(buffer.GetBytes(), size, process->GetByteOrder(),
389 process->GetAddressByteSize());
390
391 lldb::offset_t cursor = 0;
392
393 m_offset_ptr = extractor.GetAddress_unchecked(&cursor);
394 m_name_ptr = extractor.GetAddress_unchecked(&cursor);
395 m_type_ptr = extractor.GetAddress_unchecked(&cursor);
396 m_alignment = extractor.GetU32_unchecked(&cursor);
397 m_size = extractor.GetU32_unchecked(&cursor);
398
400 if (error.Fail()) {
401 return false;
402 }
403
405 return !error.Fail();
406}
407
409 lldb::addr_t addr) {
410 Log *log = GetLog(LLDBLog::Types);
411 size_t size = sizeof(uint64_t); // m_image_index : 16
412 // m_list_offset : 48
413
414 DataBufferHeap buffer(size, '\0');
416
417 process->ReadMemory(addr, buffer.GetBytes(), size, error);
418 // FIXME: Propagate this error up
419 if (error.Fail()) {
420 LLDB_LOG(log, "Failed to read relative_list_entry_t at address {0:x}",
421 addr);
422 return false;
423 }
424
425 DataExtractor extractor(buffer.GetBytes(), size, process->GetByteOrder(),
426 process->GetAddressByteSize());
427 lldb::offset_t cursor = 0;
428 uint64_t raw_entry = extractor.GetU64_unchecked(&cursor);
429 m_image_index = raw_entry & 0xFFFF;
430 m_list_offset = llvm::SignExtend64<48>(raw_entry >> 16);
431 return true;
432}
433
435 lldb::addr_t addr) {
436 Log *log = GetLog(LLDBLog::Types);
437 size_t size = sizeof(uint32_t) // m_entsize
438 + sizeof(uint32_t); // m_count
439
440 DataBufferHeap buffer(size, '\0');
442
443 // FIXME: Propagate this error up
444 process->ReadMemory(addr, buffer.GetBytes(), size, error);
445 if (error.Fail()) {
446 LLDB_LOG(log, "Failed to read relative_list_list_t at address 0x" PRIx64,
447 addr);
448 return false;
449 }
450
451 DataExtractor extractor(buffer.GetBytes(), size, process->GetByteOrder(),
452 process->GetAddressByteSize());
453 lldb::offset_t cursor = 0;
454 m_entsize = extractor.GetU32_unchecked(&cursor);
455 m_count = extractor.GetU32_unchecked(&cursor);
456 m_first_ptr = addr + cursor;
457 return true;
458}
459
460std::optional<ClassDescriptorV2::method_list_t>
462 lldb::addr_t method_list_ptr) const {
463 Log *log = GetLog(LLDBLog::Types);
465 if (!method_list.Read(process, method_list_ptr))
466 return std::nullopt;
467
468 const size_t method_size = method_t::GetSize(process, method_list.m_is_small);
469 if (method_list.m_entsize != method_size) {
470 LLDB_LOG(log,
471 "method_list_t at address 0x" PRIx64 " has an entsize of " PRIu16
472 " but method size should be " PRIu64,
473 method_list_ptr, method_list.m_entsize, method_size);
474 return std::nullopt;
475 }
476
477 return method_list;
478}
479
481 std::function<bool(const char *, const char *)> const &instance_method_func,
482 ClassDescriptorV2::method_list_t &method_list) const {
483 auto idx_to_method_addr = [&](uint32_t idx) {
484 return method_list.m_first_ptr + (idx * method_list.m_entsize);
485 };
486 llvm::SmallVector<addr_t> addresses = llvm::to_vector(llvm::map_range(
487 llvm::seq<uint32_t>(method_list.m_count), idx_to_method_addr));
488
489 llvm::SmallVector<method_t, 0> methods =
490 ReadMethods(addresses, m_runtime.GetRelativeSelectorBaseAddr(),
491 method_list.m_is_small, method_list.m_has_direct_selector,
492 method_list.m_has_relative_types);
493
494 for (const auto &method : methods)
495 if (instance_method_func(method.m_name.c_str(), method.m_types.c_str()))
496 break;
497 return true;
498}
499
500// The relevant data structures:
501// - relative_list_list_t
502// - uint32_t count
503// - uint32_t entsize
504// - Followed by <count> number of relative_list_entry_t of size <entsize>
505//
506// - relative_list_entry_t
507// - uint64_t image_index : 16
508// - int64_t list_offset : 48
509// - Note: The above 2 fit into 8 bytes always
510//
511// image_index corresponds to an image in the shared cache
512// list_offset is used to calculate the address of the method_list_t we want
514 std::function<bool(const char *, const char *)> const &instance_method_func,
515 lldb::addr_t relative_method_list_ptr) const {
516 lldb_private::Process *process = m_runtime.GetProcess();
517 auto relative_method_lists = std::make_unique<relative_list_list_t>();
518
519 // 1. Process the count and entsize of the relative_list_list_t
520 if (!relative_method_lists->Read(process, relative_method_list_ptr))
521 return false;
522
523 auto entry = std::make_unique<relative_list_entry_t>();
524 for (uint32_t i = 0; i < relative_method_lists->m_count; i++) {
525 // 2. Extract the image index and the list offset from the
526 // relative_list_entry_t
527 const lldb::addr_t entry_addr = relative_method_lists->m_first_ptr +
528 (i * relative_method_lists->m_entsize);
529 if (!entry->Read(process, entry_addr))
530 return false;
531
532 // 3. Calculate the pointer to the method_list_t from the
533 // relative_list_entry_t
534 const lldb::addr_t method_list_addr = entry_addr + entry->m_list_offset;
535
536 // 4. Get the method_list_t from the pointer
537 std::optional<method_list_t> method_list =
538 GetMethodList(process, method_list_addr);
539 if (!method_list)
540 return false;
541
542 // 5. Cache the result so we don't need to reconstruct it later.
543 m_image_to_method_lists[entry->m_image_index].emplace_back(*method_list);
544
545 // 6. If the relevant image is loaded, add the methods to the Decl
546 if (!m_runtime.IsSharedCacheImageLoaded(entry->m_image_index))
547 continue;
548
549 if (!ProcessMethodList(instance_method_func, *method_list))
550 return false;
551 }
552
553 // We need to keep track of the last time we updated so we can re-update the
554 // type information in the future
555 m_last_version_updated = m_runtime.GetSharedCacheImageHeaderVersion();
556
557 return true;
558}
559
561 std::function<void(ObjCLanguageRuntime::ObjCISA)> const &superclass_func,
562 std::function<bool(const char *, const char *)> const &instance_method_func,
563 std::function<bool(const char *, const char *)> const &class_method_func,
564 std::function<bool(const char *, const char *, lldb::addr_t,
565 uint64_t)> const &ivar_func) const {
566 lldb_private::Process *process = m_runtime.GetProcess();
567
568 std::unique_ptr<objc_class_t> objc_class;
569 std::unique_ptr<class_ro_t> class_ro;
570 std::unique_ptr<class_rw_t> class_rw;
571
572 if (!Read_objc_class(process, objc_class))
573 return false;
574 if (!Read_class_row(process, *objc_class, class_ro, class_rw))
575 return false;
576
577 static ConstString NSObject_name("NSObject");
578
579 if (m_name != NSObject_name && superclass_func)
580 superclass_func(objc_class->m_superclass);
581
582 if (instance_method_func) {
583 // This is a relative list of lists
584 if (class_ro->m_baseMethods_ptr & 1) {
585 if (!ProcessRelativeMethodLists(instance_method_func,
586 class_ro->m_baseMethods_ptr ^ 1))
587 return false;
588 } else {
589 std::optional<method_list_t> base_method_list =
590 GetMethodList(process, class_ro->m_baseMethods_ptr);
591 if (base_method_list &&
592 !ProcessMethodList(instance_method_func, *base_method_list))
593 return false;
594 }
595 }
596
597 if (class_method_func) {
599
600 // We don't care about the metaclass's superclass, or its class methods.
601 // Its instance methods are our class methods.
602
603 if (metaclass) {
604 metaclass->Describe(
605 std::function<void(ObjCLanguageRuntime::ObjCISA)>(nullptr),
606 class_method_func,
607 std::function<bool(const char *, const char *)>(nullptr),
608 std::function<bool(const char *, const char *, lldb::addr_t,
609 uint64_t)>(nullptr));
610 }
611 }
612
613 if (ivar_func) {
614 if (class_ro->m_ivars_ptr != 0) {
615 ivar_list_t ivar_list;
616 if (!ivar_list.Read(process, class_ro->m_ivars_ptr))
617 return false;
618
619 if (ivar_list.m_entsize != ivar_t::GetSize(process))
620 return false;
621
622 ivar_t ivar;
623
624 for (uint32_t i = 0, e = ivar_list.m_count; i < e; ++i) {
625 ivar.Read(process, ivar_list.m_first_ptr + (i * ivar_list.m_entsize));
626
627 if (ivar_func(ivar.m_name.c_str(), ivar.m_type.c_str(),
628 ivar.m_offset_ptr, ivar.m_size))
629 break;
630 }
631 }
632 }
633
634 return true;
635}
636
638 if (!m_name) {
639 lldb_private::Process *process = m_runtime.GetProcess();
640
641 if (process) {
642 std::unique_ptr<objc_class_t> objc_class;
643 std::unique_ptr<class_ro_t> class_ro;
644 std::unique_ptr<class_rw_t> class_rw;
645
646 if (!Read_objc_class(process, objc_class))
647 return m_name;
648 if (!Read_class_row(process, *objc_class, class_ro, class_rw))
649 return m_name;
650
651 m_name = ConstString(class_ro->m_name.c_str());
652 }
653 }
654 return m_name;
655}
656
658 lldb_private::Process *process = m_runtime.GetProcess();
659
660 if (!process)
662
663 std::unique_ptr<objc_class_t> objc_class;
664
665 if (!Read_objc_class(process, objc_class))
667
668 return m_runtime.ObjCLanguageRuntime::GetClassDescriptorFromISA(
669 objc_class->m_superclass);
670}
671
673 lldb_private::Process *process = m_runtime.GetProcess();
674
675 if (!process)
677
678 std::unique_ptr<objc_class_t> objc_class;
679
680 if (!Read_objc_class(process, objc_class))
682
683 lldb::addr_t candidate_isa = m_runtime.GetPointerISA(objc_class->m_isa);
684
686 new ClassDescriptorV2(m_runtime, candidate_isa, nullptr));
687}
688
690 lldb_private::Process *process = m_runtime.GetProcess();
691
692 if (process) {
693 std::unique_ptr<objc_class_t> objc_class;
694 std::unique_ptr<class_ro_t> class_ro;
695 std::unique_ptr<class_rw_t> class_rw;
696
697 if (!Read_objc_class(process, objc_class))
698 return 0;
699 if (!Read_class_row(process, *objc_class, class_ro, class_rw))
700 return 0;
701
702 return class_ro->m_instanceSize;
703 }
704
705 return 0;
706}
707
708// From the ObjC runtime.
709static uint8_t IS_SWIFT_STABLE = 1U << 1;
710
712 std::unique_ptr<objc_class_t> objc_class;
713 if (auto *process = m_runtime.GetProcess())
714 if (Read_objc_class(process, objc_class))
715 if (objc_class->m_flags & IS_SWIFT_STABLE)
717
719}
720
722
724
729
731 ClassDescriptorV2 &descriptor) {
732 if (m_filled)
733 return;
734 std::lock_guard<std::recursive_mutex> guard(m_mutex);
735 Log *log = GetLog(LLDBLog::Types);
736 LLDB_LOGV(log, "class_name = {0}", descriptor.GetClassName());
737 m_filled = true;
738 ObjCLanguageRuntime::EncodingToTypeSP encoding_to_type_sp(
739 runtime.GetEncodingToType());
740 Process *process(runtime.GetProcess());
741 if (!encoding_to_type_sp)
742 return;
743 descriptor.Describe(nullptr, nullptr, nullptr, [this, process,
744 encoding_to_type_sp,
745 log](const char *name,
746 const char *type,
747 lldb::addr_t offset_ptr,
748 uint64_t size) -> bool {
749 const bool for_expression = false;
750 const bool stop_loop = false;
751 LLDB_LOGV(log, "name = {0}, encoding = {1}, offset_ptr = {2:x}, size = {3}",
752 name, type, offset_ptr, size);
753 CompilerType ivar_type =
754 encoding_to_type_sp->RealizeType(type, for_expression);
755 if (ivar_type) {
756 LLDB_LOGV(log,
757 "name = {0}, encoding = {1}, offset_ptr = {2:x}, size = "
758 "{3}, type_size = {4}",
759 name, type, offset_ptr, size,
760 expectedToOptional(ivar_type.GetByteSize(nullptr)).value_or(0));
761 Scalar offset_scalar;
763 const int offset_ptr_size = 4;
764 const bool is_signed = false;
765 size_t read = process->ReadScalarIntegerFromMemory(
766 offset_ptr, offset_ptr_size, is_signed, offset_scalar, error);
767 if (error.Success() && 4 == read) {
768 LLDB_LOGV(log, "offset_ptr = {0:x} --> {1}", offset_ptr,
769 offset_scalar.SInt());
770 m_ivars.push_back(
771 {ConstString(name), ivar_type, size, offset_scalar.SInt()});
772 } else
773 LLDB_LOGV(log, "offset_ptr = {0:x} --> read fail, read = %{1}",
774 offset_ptr, read);
775 }
776 return stop_loop;
777 });
778}
779
static lldb::addr_t GetClassDataMask(Process *process)
static uint8_t IS_SWIFT_STABLE
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
Definition Log.h:369
#define LLDB_LOGV(log,...)
Definition Log.h:383
EncodingToTypeSP GetEncodingToType() override
void fill(AppleObjCRuntimeV2 &runtime, ClassDescriptorV2 &descriptor)
ObjCLanguageRuntime::ClassDescriptorSP GetSuperclass() override
llvm::SmallVector< method_t, 0 > ReadMethods(llvm::ArrayRef< lldb::addr_t > addresses, lldb::addr_t relative_string_base_addr, bool is_small, bool has_direct_sel, bool has_relative_types) const
bool Describe(std::function< void(ObjCLanguageRuntime::ObjCISA)> const &superclass_func, std::function< bool(const char *, const char *)> const &instance_method_func, std::function< bool(const char *, const char *)> const &class_method_func, std::function< bool(const char *, const char *, lldb::addr_t, uint64_t)> const &ivar_func) const override
friend class lldb_private::AppleObjCRuntimeV2
bool Read_class_row(Process *process, const objc_class_t &objc_class, std::unique_ptr< class_ro_t > &class_ro, std::unique_ptr< class_rw_t > &class_rw) const
bool ProcessRelativeMethodLists(std::function< bool(const char *, const char *)> const &instance_method_func, lldb::addr_t relative_method_list_ptr) const
ClassDescriptorV2(AppleObjCRuntimeV2 &runtime, ObjCLanguageRuntime::ObjCISA isa, const char *name)
bool ProcessMethodList(std::function< bool(const char *, const char *)> const &instance_method_func, method_list_t &method_list) const
bool Read_objc_class(Process *process, std::unique_ptr< objc_class_t > &objc_class) const
std::optional< uint64_t > m_last_version_updated
std::map< uint16_t, std::vector< method_list_t > > m_image_to_method_lists
ObjCLanguageRuntime::ClassDescriptorSP GetMetaclass() const override
lldb::LanguageType GetImplementationLanguage() const override
Determine whether this class is implemented in Swift.
std::optional< method_list_t > GetMethodList(Process *process, lldb::addr_t method_list_ptr) const
Generic representation of a type in a programming language.
llvm::Expected< uint64_t > GetByteSize(ExecutionContextScope *exe_scope) const
Return the size of the type in bytes.
A uniqued constant string class.
Definition ConstString.h:40
A subclass of DataBuffer that stores a data buffer on the heap.
lldb::offset_t GetByteSize() const override
Get the number of bytes in the data buffer.
An data extractor class.
uint32_t GetU32_unchecked(lldb::offset_t *offset_ptr) const
uint64_t GetAddress_unchecked(lldb::offset_t *offset_ptr) const
uint64_t GetU64_unchecked(lldb::offset_t *offset_ptr) const
std::shared_ptr< ClassDescriptor > ClassDescriptorSP
std::shared_ptr< EncodingToType > EncodingToTypeSP
A plug-in interface definition class for debugging a process.
Definition Process.h:357
size_t ReadScalarIntegerFromMemory(lldb::addr_t addr, uint32_t byte_size, bool is_signed, Scalar &scalar, Status &error)
Definition Process.cpp:2438
size_t ReadCStringFromMemory(lldb::addr_t vm_addr, char *cstr, size_t cstr_max_len, Status &error)
Read a NULL terminated C string from memory.
Definition Process.cpp:2162
virtual size_t ReadMemory(lldb::addr_t vm_addr, void *buf, size_t size, Status &error)
Read of memory from a process.
Definition Process.cpp:1930
lldb::ByteOrder GetByteOrder() const
Definition Process.cpp:3659
uint64_t ReadUnsignedIntegerFromMemory(lldb::addr_t load_addr, size_t byte_size, uint64_t fail_value, Status &error)
Reads an unsigned integer of the specified byte size from process memory.
Definition Process.cpp:2281
lldb::addr_t ReadPointerFromMemory(lldb::addr_t vm_addr, Status &error)
Definition Process.cpp:2303
uint32_t GetAddressByteSize() const
Definition Process.cpp:3663
virtual llvm::SmallVector< llvm::MutableArrayRef< uint8_t > > ReadMemoryRanges(llvm::ArrayRef< Range< lldb::addr_t, size_t > > ranges, llvm::MutableArrayRef< uint8_t > buffer)
Read from multiple memory ranges and write the results into buffer.
Definition Process.cpp:1975
const lldb::ABISP & GetABI()
Definition Process.cpp:1481
Process * GetProcess()
Definition Runtime.h:22
int SInt(int fail_value=0) const
Definition Scalar.cpp:349
An error handling class.
Definition Status.h:118
uint8_t * GetBytes()
Get a pointer to the data.
Definition DataBuffer.h:108
#define LLDB_INVALID_ADDRESS
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
Definition Log.h:332
std::shared_ptr< lldb_private::ABI > ABISP
uint64_t offset_t
Definition lldb-types.h:85
LanguageType
Programming language type.
@ eLanguageTypeSwift
Swift.
@ eLanguageTypeObjC
Objective-C.
uint64_t addr_t
Definition lldb-types.h:80
bool Read(Process *process, lldb::addr_t addr)
bool Read(Process *process, lldb::addr_t addr)
bool Read(Process *process, lldb::addr_t addr)
bool Read(Process *process, lldb::addr_t addr)
static size_t GetSize(Process *process, bool is_small)
bool Read(DataExtractor &extractor, Process *process, lldb::addr_t addr, lldb::addr_t relative_string_base_addr, bool is_small, bool has_direct_sel, bool has_relative_types)
bool Read(Process *process, lldb::addr_t addr)
uint16_t m_image_index
int64_t m_list_offset
bool Read(Process *process, lldb::addr_t addr)