Skip to content

Commit d0d001d

Browse files
authored
[lldb] Support shared cache relative objc method types (#163663)
Support the types and name field in the relative method list to be relative to a buffer in the shared cache, not relative to the field in the method list itself. A new magic bit, 0x20000000, is attached to method lists where the types are encoded in this way. This is covered by the existing tests when running against a shared cache that uses this encoding. rdar://147545351
1 parent 705b996 commit d0d001d

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
lines changed

lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCClassDescriptorV2.cpp

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ bool ClassDescriptorV2::method_list_t::Read(Process *process,
260260
uint32_t entsize = extractor.GetU32_unchecked(&cursor);
261261
m_is_small = (entsize & 0x80000000) != 0;
262262
m_has_direct_selector = (entsize & 0x40000000) != 0;
263+
m_has_relative_types = (entsize & 0x20000000) != 0;
263264
m_entsize = entsize & 0xfffc;
264265
m_count = extractor.GetU32_unchecked(&cursor);
265266
m_first_ptr = addr + cursor;
@@ -269,8 +270,9 @@ bool ClassDescriptorV2::method_list_t::Read(Process *process,
269270

270271
llvm::SmallVector<ClassDescriptorV2::method_t, 0>
271272
ClassDescriptorV2::ReadMethods(llvm::ArrayRef<lldb::addr_t> addresses,
272-
lldb::addr_t relative_selector_base_addr,
273-
bool is_small, bool has_direct_sel) const {
273+
lldb::addr_t relative_string_base_addr,
274+
bool is_small, bool has_direct_sel,
275+
bool has_relative_types) const {
274276
lldb_private::Process *process = m_runtime.GetProcess();
275277
if (!process)
276278
return {};
@@ -297,17 +299,18 @@ ClassDescriptorV2::ReadMethods(llvm::ArrayRef<lldb::addr_t> addresses,
297299
process->GetByteOrder(),
298300
process->GetAddressByteSize());
299301
methods.push_back(method_t());
300-
methods.back().Read(extractor, process, addr, relative_selector_base_addr,
301-
is_small, has_direct_sel);
302+
methods.back().Read(extractor, process, addr, relative_string_base_addr,
303+
is_small, has_direct_sel, has_relative_types);
302304
}
303305

304306
return methods;
305307
}
306308

307309
bool ClassDescriptorV2::method_t::Read(DataExtractor &extractor,
308310
Process *process, lldb::addr_t addr,
309-
lldb::addr_t relative_selector_base_addr,
310-
bool is_small, bool has_direct_sel) {
311+
lldb::addr_t relative_string_base_addr,
312+
bool is_small, bool has_direct_sel,
313+
bool has_relative_types) {
311314
lldb::offset_t cursor = 0;
312315

313316
if (is_small) {
@@ -323,10 +326,13 @@ bool ClassDescriptorV2::method_t::Read(DataExtractor &extractor,
323326
m_name_ptr = process->ReadPointerFromMemory(m_name_ptr, error);
324327
if (error.Fail())
325328
return false;
326-
} else if (relative_selector_base_addr != LLDB_INVALID_ADDRESS) {
327-
m_name_ptr = relative_selector_base_addr + nameref_offset;
329+
} else if (relative_string_base_addr != LLDB_INVALID_ADDRESS) {
330+
m_name_ptr = relative_string_base_addr + nameref_offset;
328331
}
329-
m_types_ptr = addr + 4 + types_offset;
332+
if (has_relative_types)
333+
m_types_ptr = relative_string_base_addr + types_offset;
334+
else
335+
m_types_ptr = addr + 4 + types_offset;
330336
m_imp_ptr = addr + 8 + imp_offset;
331337
} else {
332338
m_name_ptr = extractor.GetAddress_unchecked(&cursor);
@@ -481,7 +487,8 @@ bool ClassDescriptorV2::ProcessMethodList(
481487

482488
llvm::SmallVector<method_t, 0> methods =
483489
ReadMethods(addresses, m_runtime.GetRelativeSelectorBaseAddr(),
484-
method_list.m_is_small, method_list.m_has_direct_selector);
490+
method_list.m_is_small, method_list.m_has_direct_selector,
491+
method_list.m_has_relative_types);
485492

486493
for (const auto &method : methods)
487494
if (instance_method_func(method.m_name.c_str(), method.m_types.c_str()))

lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCClassDescriptorV2.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ class ClassDescriptorV2 : public ObjCLanguageRuntime::ClassDescriptor {
143143
uint16_t m_entsize;
144144
bool m_is_small;
145145
bool m_has_direct_selector;
146+
bool m_has_relative_types;
146147
uint32_t m_count;
147148
lldb::addr_t m_first_ptr;
148149

@@ -173,14 +174,14 @@ class ClassDescriptorV2 : public ObjCLanguageRuntime::ClassDescriptor {
173174
}
174175

175176
bool Read(DataExtractor &extractor, Process *process, lldb::addr_t addr,
176-
lldb::addr_t relative_selector_base_addr, bool is_small,
177-
bool has_direct_sel);
177+
lldb::addr_t relative_string_base_addr, bool is_small,
178+
bool has_direct_sel, bool has_relative_types);
178179
};
179180

180181
llvm::SmallVector<method_t, 0>
181182
ReadMethods(llvm::ArrayRef<lldb::addr_t> addresses,
182-
lldb::addr_t relative_selector_base_addr, bool is_small,
183-
bool has_direct_sel) const;
183+
lldb::addr_t relative_string_base_addr, bool is_small,
184+
bool has_direct_sel, bool has_relative_types) const;
184185

185186
struct ivar_list_t {
186187
uint32_t m_entsize;

0 commit comments

Comments
 (0)