@@ -503,26 +503,59 @@ SymbolFileCTF::CreateFunction(const CTFFunction &ctf_function) {
503
503
llvm::Expected<lldb::TypeSP>
504
504
SymbolFileCTF::CreateRecord (const CTFRecord &ctf_record) {
505
505
const clang::TagTypeKind tag_kind = TranslateRecordKind (ctf_record.kind );
506
-
507
506
CompilerType record_type =
508
507
m_ast->CreateRecordType (nullptr , OptionalClangModuleID (), eAccessPublic,
509
508
ctf_record.name .data (), tag_kind, eLanguageTypeC);
509
+ m_compiler_types[record_type.GetOpaqueQualType ()] = &ctf_record;
510
+ Declaration decl;
511
+ return MakeType (ctf_record.uid , ConstString (ctf_record.name ), ctf_record.size ,
512
+ nullptr , LLDB_INVALID_UID, lldb_private::Type::eEncodingIsUID,
513
+ decl, record_type, lldb_private::Type::ResolveState::Forward);
514
+ }
515
+
516
+ bool SymbolFileCTF::CompleteType (CompilerType &compiler_type) {
517
+ // Check if we have a CTF type for the given incomplete compiler type.
518
+ auto it = m_compiler_types.find (compiler_type.GetOpaqueQualType ());
519
+ if (it == m_compiler_types.end ())
520
+ return false ;
521
+
522
+ const CTFType *ctf_type = it->second ;
523
+ assert (ctf_type && " m_compiler_types should only contain valid CTF types" );
524
+
525
+ // We only support resolving record types.
526
+ assert (ctf_type->kind == CTFType::Kind::eStruct ||
527
+ ctf_type->kind == CTFType::Kind::eUnion);
510
528
511
- m_ast->StartTagDeclarationDefinition (record_type);
512
- for (const CTFRecord::Field &field : ctf_record.fields ) {
513
- if (Type *field_type = ResolveTypeUID (field.type )) {
514
- const uint32_t field_size = field_type->GetByteSize (nullptr ).value_or (0 );
515
- TypeSystemClang::AddFieldToRecordType (record_type, field.name ,
516
- field_type->GetFullCompilerType (),
517
- eAccessPublic, field_size);
529
+ // Cast to the appropriate CTF type.
530
+ const CTFRecord *ctf_record = static_cast <const CTFRecord *>(ctf_type);
531
+
532
+ // If any of the fields are incomplete, we cannot complete the type.
533
+ for (const CTFRecord::Field &field : ctf_record->fields ) {
534
+ if (!ResolveTypeUID (field.type )) {
535
+ LLDB_LOG (GetLog (LLDBLog::Symbols),
536
+ " Cannot complete type {0} because field {1} is incomplete" ,
537
+ ctf_type->uid , field.type );
538
+ return false ;
518
539
}
519
540
}
520
- m_ast->CompleteTagDeclarationDefinition (record_type);
521
541
522
- Declaration decl;
523
- return MakeType (ctf_record.uid , ConstString (ctf_record.name ), ctf_record.size ,
524
- nullptr , LLDB_INVALID_UID, lldb_private::Type::eEncodingIsUID,
525
- decl, record_type, lldb_private::Type::ResolveState::Full);
542
+ // Complete the record type.
543
+ m_ast->StartTagDeclarationDefinition (compiler_type);
544
+ for (const CTFRecord::Field &field : ctf_record->fields ) {
545
+ Type *field_type = ResolveTypeUID (field.type );
546
+ assert (field_type && " field must be complete" );
547
+ const uint32_t field_size = field_type->GetByteSize (nullptr ).value_or (0 );
548
+ TypeSystemClang::AddFieldToRecordType (compiler_type, field.name ,
549
+ field_type->GetFullCompilerType (),
550
+ eAccessPublic, field_size);
551
+ }
552
+ m_ast->CompleteTagDeclarationDefinition (compiler_type);
553
+
554
+ // Now that the compiler type is no longer incomplete we don't need to
555
+ // remember it anymore.
556
+ m_compiler_types.erase (compiler_type.GetOpaqueQualType ());
557
+
558
+ return true ;
526
559
}
527
560
528
561
llvm::Expected<lldb::TypeSP>
@@ -960,7 +993,6 @@ lldb_private::Type *SymbolFileCTF::ResolveTypeUID(lldb::user_id_t type_uid) {
960
993
if (!ctf_type)
961
994
return nullptr ;
962
995
963
- m_types[type_uid] = TypeSP ();
964
996
Log *log = GetLog (LLDBLog::Symbols);
965
997
966
998
llvm::Expected<TypeSP> type_or_error = CreateType (ctf_type);
0 commit comments