Skip to content

Commit 39dcaca

Browse files
committed
[lldb][ValueObject][NFC] Move Objective-C lookup code into helpers
In preparation to moving them into the Objective-C LanguageRuntime plugin.
1 parent e10cce2 commit 39dcaca

File tree

3 files changed

+60
-48
lines changed

3 files changed

+60
-48
lines changed

lldb/include/lldb/ValueObject/ValueObject.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,6 +1104,9 @@ class ValueObject {
11041104

11051105
private:
11061106
virtual CompilerType MaybeCalculateCompleteType();
1107+
CompilerType LookupInRuntime(ConstString class_name, Process &process);
1108+
CompilerType LookupInModulesVendor(ConstString class_name, Target &process);
1109+
11071110
void UpdateChildrenAddressType() {
11081111
GetRoot()->DoUpdateChildrenAddressType(*this);
11091112
}

lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -446,14 +446,10 @@ ObjCLanguageRuntime::GetRuntimeType(CompilerType base_type) {
446446
if (!complete_objc_class_type_sp)
447447
return std::nullopt;
448448

449-
CompilerType complete_class(
450-
complete_objc_class_type_sp->GetFullCompilerType());
451-
if (complete_class.GetCompleteType()) {
452-
if (is_pointer_type)
453-
return complete_class.GetPointerType();
454-
else
455-
return complete_class;
456-
}
449+
if (CompilerType complete_class =
450+
complete_objc_class_type_sp->GetFullCompilerType();
451+
complete_class.GetCompleteType())
452+
return is_pointer_type ? complete_class.GetPointerType() : complete_class;
457453

458454
return std::nullopt;
459455
}

lldb/source/ValueObject/ValueObject.cpp

Lines changed: 53 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,51 @@ void ValueObject::ClearDynamicTypeInformation() {
249249
SetSyntheticChildren(lldb::SyntheticChildrenSP());
250250
}
251251

252+
CompilerType ValueObject::LookupInModulesVendor(ConstString class_name,
253+
Target &target) {
254+
assert(class_name);
255+
256+
auto *persistent_state = llvm::cast<ClangPersistentVariables>(
257+
target.GetPersistentExpressionStateForLanguage(lldb::eLanguageTypeC));
258+
if (!persistent_state)
259+
return {};
260+
261+
auto clang_modules_decl_vendor_sp =
262+
persistent_state->GetClangModulesDeclVendor();
263+
if (!clang_modules_decl_vendor_sp)
264+
return {};
265+
266+
auto types = clang_modules_decl_vendor_sp->FindTypes(
267+
class_name, /*max_matches*/ UINT32_MAX);
268+
if (types.empty())
269+
return {};
270+
271+
return types.front();
272+
}
273+
274+
CompilerType ValueObject::LookupInRuntime(ConstString class_name,
275+
Process &process) {
276+
auto *objc_language_runtime = ObjCLanguageRuntime::Get(process);
277+
if (!objc_language_runtime)
278+
return {};
279+
280+
auto *runtime_vendor = objc_language_runtime->GetDeclVendor();
281+
if (!runtime_vendor)
282+
return {};
283+
284+
std::vector<CompilerDecl> compiler_decls;
285+
runtime_vendor->FindDecls(class_name, false, UINT32_MAX, compiler_decls);
286+
if (compiler_decls.empty())
287+
return {};
288+
289+
auto *ctx =
290+
llvm::dyn_cast<TypeSystemClang>(compiler_decls[0].GetTypeSystem());
291+
if (!ctx)
292+
return {};
293+
294+
return ctx->GetTypeForDecl(compiler_decls[0].GetOpaqueDecl());
295+
}
296+
252297
CompilerType ValueObject::MaybeCalculateCompleteType() {
253298
CompilerType compiler_type(GetCompilerTypeImpl());
254299

@@ -277,7 +322,6 @@ CompilerType ValueObject::MaybeCalculateCompleteType() {
277322
}
278323
}
279324

280-
std::vector<clang::NamedDecl *> decls;
281325
CompilerType class_type;
282326
bool is_pointer_type = false;
283327
if (TypeSystemClang::IsObjCObjectPointerType(compiler_type, &class_type))
@@ -291,49 +335,18 @@ CompilerType ValueObject::MaybeCalculateCompleteType() {
291335
if (!class_name)
292336
return compiler_type;
293337

294-
// try the modules
295-
if (TargetSP target_sp = GetTargetSP()) {
296-
auto *persistent_state = llvm::cast<ClangPersistentVariables>(
297-
target_sp->GetPersistentExpressionStateForLanguage(lldb::eLanguageTypeC));
298-
if (!persistent_state)
299-
return compiler_type;
300-
301-
if (auto clang_modules_decl_vendor =
302-
persistent_state->GetClangModulesDeclVendor()) {
303-
ConstString key_cs(class_name);
304-
auto types = clang_modules_decl_vendor->FindTypes(
305-
key_cs, /*max_matches*/ UINT32_MAX);
306-
if (!types.empty()) {
307-
auto module_type = types.front();
308-
m_override_type =
309-
is_pointer_type ? module_type.GetPointerType() : module_type;
310-
}
311-
312-
if (m_override_type.IsValid())
313-
return m_override_type;
338+
if (auto target_sp = GetTargetSP()) {
339+
if (CompilerType found = LookupInModulesVendor(class_name, *target_sp)) {
340+
m_override_type = is_pointer_type ? found.GetPointerType() : found;
341+
return m_override_type;
314342
}
315343
}
316344

317-
// then try the runtime
318-
if (auto *objc_language_runtime = ObjCLanguageRuntime::Get(*process_sp)) {
319-
if (auto *runtime_vendor = objc_language_runtime->GetDeclVendor()) {
320-
std::vector<CompilerDecl> compiler_decls;
321-
runtime_vendor->FindDecls(class_name, false, UINT32_MAX, compiler_decls);
322-
if (!compiler_decls.empty()) {
323-
auto *ctx =
324-
llvm::dyn_cast<TypeSystemClang>(compiler_decls[0].GetTypeSystem());
325-
if (ctx) {
326-
CompilerType runtime_type =
327-
ctx->GetTypeForDecl(compiler_decls[0].GetOpaqueDecl());
328-
m_override_type =
329-
is_pointer_type ? runtime_type.GetPointerType() : runtime_type;
330-
}
331-
}
332-
333-
if (m_override_type.IsValid())
334-
return m_override_type;
335-
}
345+
if (CompilerType found = LookupInRuntime(class_name, *process_sp)) {
346+
m_override_type = is_pointer_type ? found.GetPointerType() : found;
347+
return m_override_type;
336348
}
349+
337350
return compiler_type;
338351
}
339352

0 commit comments

Comments
 (0)