virtual bool GetDebugInfoHadFrameVariableErrors() const = 0;
virtual void SetDebugInfoHadFrameVariableErrors() = 0;
+ virtual lldb::TypeSP
+ MakeType(lldb::user_id_t uid, ConstString name,
+ std::optional<uint64_t> byte_size, SymbolContextScope *context,
+ lldb::user_id_t encoding_uid,
+ Type::EncodingDataType encoding_uid_type, const Declaration &decl,
+ const CompilerType &compiler_qual_type,
+ Type::ResolveState compiler_type_resolve_state,
+ uint32_t opaque_payload = 0) = 0;
+
protected:
void AssertModuleLock();
m_debug_info_had_variable_errors = true;
}
+ /// This function is used to create types that belong to a SymbolFile. The
+ /// symbol file will own a strong reference to the type in an internal type
+ /// list.
+ lldb::TypeSP MakeType(lldb::user_id_t uid, ConstString name,
+ std::optional<uint64_t> byte_size,
+ SymbolContextScope *context,
+ lldb::user_id_t encoding_uid,
+ Type::EncodingDataType encoding_uid_type,
+ const Declaration &decl,
+ const CompilerType &compiler_qual_type,
+ Type::ResolveState compiler_type_resolve_state,
+ uint32_t opaque_payload = 0) override {
+ lldb::TypeSP type_sp (new Type(
+ uid, this, name, byte_size, context, encoding_uid,
+ encoding_uid_type, decl, compiler_qual_type,
+ compiler_type_resolve_state, opaque_payload));
+ m_type_list.Insert(type_sp);
+ return type_sp;
+ }
+
protected:
virtual uint32_t CalculateNumCompileUnits() = 0;
virtual lldb::CompUnitSP ParseCompileUnitAtIndex(uint32_t idx) = 0;
return m_sym_file_impl->SetDebugInfoHadFrameVariableErrors();
}
+ lldb::TypeSP MakeType(lldb::user_id_t uid, ConstString name,
+ std::optional<uint64_t> byte_size,
+ SymbolContextScope *context,
+ lldb::user_id_t encoding_uid,
+ Type::EncodingDataType encoding_uid_type,
+ const Declaration &decl,
+ const CompilerType &compiler_qual_type,
+ Type::ResolveState compiler_type_resolve_state,
+ uint32_t opaque_payload = 0) override {
+ return m_sym_file_impl->MakeType(
+ uid, name, byte_size, context, encoding_uid, encoding_uid_type, decl,
+ compiler_qual_type, compiler_type_resolve_state, opaque_payload);
+ }
+
private:
Log *GetLog() const { return ::lldb_private::GetLog(LLDBLog::OnDemand); }
#include <set>
namespace lldb_private {
+class SymbolFileCommon;
/// CompilerContext allows an array of these items to be passed to perform
/// detailed lookups in SymbolVendor and SymbolFile functions.
Full = 3
};
- Type(lldb::user_id_t uid, SymbolFile *symbol_file, ConstString name,
- std::optional<uint64_t> byte_size, SymbolContextScope *context,
- lldb::user_id_t encoding_uid, EncodingDataType encoding_uid_type,
- const Declaration &decl, const CompilerType &compiler_qual_type,
- ResolveState compiler_type_resolve_state, uint32_t opaque_payload = 0);
-
- // This makes an invalid type. Used for functions that return a Type when
- // they get an error.
- Type();
-
void Dump(Stream *s, bool show_context,
lldb::DescriptionLevel level = lldb::eDescriptionLevelFull);
Type *GetEncodingType();
bool ResolveCompilerType(ResolveState compiler_type_resolve_state);
+private:
+ /// Only allow Symbol File to create types, as they should own them by keeping
+ /// them in their TypeList. \see SymbolFileCommon::MakeType() reference in the
+ /// header documentation here so users will know what function to use if the
+ /// get a compile error.
+ friend class lldb_private::SymbolFileCommon;
+
+ Type(lldb::user_id_t uid, SymbolFile *symbol_file, ConstString name,
+ std::optional<uint64_t> byte_size, SymbolContextScope *context,
+ lldb::user_id_t encoding_uid, EncodingDataType encoding_uid_type,
+ const Declaration &decl, const CompilerType &compiler_qual_type,
+ ResolveState compiler_type_resolve_state, uint32_t opaque_payload = 0);
+
+ // This makes an invalid type. Used for functions that return a Type when
+ // they get an error.
+ Type();
};
// the two classes here are used by the public API as a backend to the SBType
GetClangASTImporter().RequireCompleteType(ClangUtil::GetQualType(type));
SymbolFileDWARF *dwarf = die.GetDWARF();
- TypeSP type_sp(new Type(die.GetID(), dwarf, pcm_type_sp->GetName(),
- pcm_type_sp->GetByteSize(nullptr), nullptr,
- LLDB_INVALID_UID, Type::eEncodingInvalid,
- &pcm_type_sp->GetDeclaration(), type,
- Type::ResolveState::Forward,
- TypePayloadClang(GetOwningClangModule(die))));
-
- dwarf->GetTypeList().Insert(type_sp);
+ auto type_sp = dwarf->MakeType(
+ die.GetID(), pcm_type_sp->GetName(), pcm_type_sp->GetByteSize(nullptr),
+ nullptr, LLDB_INVALID_UID, Type::eEncodingInvalid,
+ &pcm_type_sp->GetDeclaration(), type, Type::ResolveState::Forward,
+ TypePayloadClang(GetOwningClangModule(die)));
dwarf->GetDIEToType()[die.GetDIE()] = type_sp.get();
clang::TagDecl *tag_decl = TypeSystemClang::GetAsTagDecl(type);
if (tag_decl) {
}
}
- type_sp = std::make_shared<Type>(
- die.GetID(), dwarf, attrs.name, attrs.byte_size, nullptr,
+ type_sp = dwarf->MakeType(
+ die.GetID(), attrs.name, attrs.byte_size, nullptr,
dwarf->GetUID(attrs.type.Reference()), encoding_data_type, &attrs.decl,
clang_type, resolve_state, TypePayloadClang(GetOwningClangModule(die)));
LinkDeclContextToDIE(TypeSystemClang::GetDeclContextForType(clang_type), die);
- type_sp = std::make_shared<Type>(
- die.GetID(), dwarf, attrs.name, attrs.byte_size, nullptr,
- dwarf->GetUID(attrs.type.Reference()), Type::eEncodingIsUID, &attrs.decl,
- clang_type, Type::ResolveState::Forward,
- TypePayloadClang(GetOwningClangModule(die)));
+ type_sp = dwarf->MakeType(die.GetID(), attrs.name, attrs.byte_size, nullptr,
+ dwarf->GetUID(attrs.type.Reference()),
+ Type::eEncodingIsUID, &attrs.decl, clang_type,
+ Type::ResolveState::Forward,
+ TypePayloadClang(GetOwningClangModule(die)));
if (TypeSystemClang::StartTagDeclarationDefinition(clang_type)) {
if (die.HasChildren()) {
}
}
}
- return std::make_shared<Type>(
- die.GetID(), dwarf, attrs.name, std::nullopt, nullptr, LLDB_INVALID_UID,
+ return dwarf->MakeType(
+ die.GetID(), attrs.name, std::nullopt, nullptr, LLDB_INVALID_UID,
Type::eEncodingIsUID, &attrs.decl, clang_type, Type::ResolveState::Full);
}
m_ast.CreateArrayType(array_element_type, 0, attrs.is_vector);
}
ConstString empty_name;
- TypeSP type_sp = std::make_shared<Type>(
- die.GetID(), dwarf, empty_name, array_element_bit_stride / 8, nullptr,
- dwarf->GetUID(type_die), Type::eEncodingIsUID, &attrs.decl, clang_type,
- Type::ResolveState::Full);
+ TypeSP type_sp =
+ dwarf->MakeType(die.GetID(), empty_name, array_element_bit_stride / 8,
+ nullptr, dwarf->GetUID(type_die), Type::eEncodingIsUID,
+ &attrs.decl, clang_type, Type::ResolveState::Full);
type_sp->SetEncodingType(element_type);
const clang::Type *type = ClangUtil::GetQualType(clang_type).getTypePtr();
m_ast.SetMetadataAsUserID(type, die.GetID());
if (std::optional<uint64_t> clang_type_size =
clang_type.GetByteSize(nullptr)) {
- return std::make_shared<Type>(die.GetID(), dwarf, attrs.name,
- *clang_type_size, nullptr, LLDB_INVALID_UID,
- Type::eEncodingIsUID, nullptr, clang_type,
- Type::ResolveState::Forward);
+ return dwarf->MakeType(die.GetID(), attrs.name, *clang_type_size, nullptr,
+ LLDB_INVALID_UID, Type::eEncodingIsUID, nullptr,
+ clang_type, Type::ResolveState::Forward);
}
return nullptr;
}
// parameters in any class methods need it for the clang types for
// function prototypes.
LinkDeclContextToDIE(m_ast.GetDeclContextForType(clang_type), die);
- type_sp = std::make_shared<Type>(
- die.GetID(), dwarf, attrs.name, attrs.byte_size, nullptr,
- LLDB_INVALID_UID, Type::eEncodingIsUID, &attrs.decl, clang_type,
+ type_sp = dwarf->MakeType(
+ die.GetID(), attrs.name, attrs.byte_size, nullptr, LLDB_INVALID_UID,
+ Type::eEncodingIsUID, &attrs.decl, clang_type,
Type::ResolveState::Forward,
TypePayloadClang(OptionalClangModuleID(), attrs.is_complete_objc_class));
TypeSP type_sp = dwarf_ast->ParseTypeFromDWARF(sc, die, type_is_new_ptr);
if (type_sp) {
- GetTypeList().Insert(type_sp);
-
if (die.Tag() == DW_TAG_subprogram) {
std::string scope_qualified_name(GetDeclContextForUID(die.GetID())
.GetScopeQualifiedName()
Declaration decl;
lldb::TypeSP modified_type = GetOrCreateType(mr.ModifiedType);
- return std::make_shared<Type>(toOpaqueUid(type_id), this, ConstString(name),
- modified_type->GetByteSize(nullptr), nullptr,
- LLDB_INVALID_UID, Type::eEncodingIsUID, decl,
- ct, Type::ResolveState::Full);
+ return MakeType(toOpaqueUid(type_id), ConstString(name),
+ modified_type->GetByteSize(nullptr), nullptr,
+ LLDB_INVALID_UID, Type::eEncodingIsUID, decl, ct,
+ Type::ResolveState::Full);
}
lldb::TypeSP
}
Declaration decl;
- return std::make_shared<Type>(toOpaqueUid(type_id), this, ConstString(),
- pr.getSize(), nullptr, LLDB_INVALID_UID,
- Type::eEncodingIsUID, decl, ct,
- Type::ResolveState::Full);
+ return MakeType(toOpaqueUid(type_id), ConstString(), pr.getSize(), nullptr,
+ LLDB_INVALID_UID, Type::eEncodingIsUID, decl, ct,
+ Type::ResolveState::Full);
}
lldb::TypeSP SymbolFileNativePDB::CreateSimpleType(TypeIndex ti,
uint64_t uid = toOpaqueUid(PdbTypeSymId(ti, false));
if (ti == TypeIndex::NullptrT()) {
Declaration decl;
- return std::make_shared<Type>(
- uid, this, ConstString("std::nullptr_t"), 0, nullptr, LLDB_INVALID_UID,
- Type::eEncodingIsUID, decl, ct, Type::ResolveState::Full);
+ return MakeType(uid, ConstString("std::nullptr_t"), 0, nullptr,
+ LLDB_INVALID_UID, Type::eEncodingIsUID, decl, ct,
+ Type::ResolveState::Full);
}
if (ti.getSimpleMode() != SimpleTypeMode::Direct) {
return nullptr;
}
Declaration decl;
- return std::make_shared<Type>(
- uid, this, ConstString(), pointer_size, nullptr, LLDB_INVALID_UID,
- Type::eEncodingIsUID, decl, ct, Type::ResolveState::Full);
+ return MakeType(uid, ConstString(), pointer_size, nullptr, LLDB_INVALID_UID,
+ Type::eEncodingIsUID, decl, ct, Type::ResolveState::Full);
}
if (ti.getSimpleKind() == SimpleTypeKind::NotTranslated)
llvm::StringRef type_name = GetSimpleTypeName(ti.getSimpleKind());
Declaration decl;
- return std::make_shared<Type>(uid, this, ConstString(type_name), size,
- nullptr, LLDB_INVALID_UID, Type::eEncodingIsUID,
- decl, ct, Type::ResolveState::Full);
+ return MakeType(uid, ConstString(type_name), size, nullptr, LLDB_INVALID_UID,
+ Type::eEncodingIsUID, decl, ct, Type::ResolveState::Full);
}
static std::string GetUnqualifiedTypeName(const TagRecord &record) {
// FIXME: Search IPI stream for LF_UDT_MOD_SRC_LINE.
Declaration decl;
- return std::make_shared<Type>(toOpaqueUid(type_id), this, ConstString(uname),
- size, nullptr, LLDB_INVALID_UID,
- Type::eEncodingIsUID, decl, ct,
- Type::ResolveState::Forward);
+ return MakeType(toOpaqueUid(type_id), ConstString(uname), size, nullptr,
+ LLDB_INVALID_UID, Type::eEncodingIsUID, decl, ct,
+ Type::ResolveState::Forward);
}
lldb::TypeSP SymbolFileNativePDB::CreateTagType(PdbTypeSymId type_id,
Declaration decl;
TypeSP underlying_type = GetOrCreateType(er.UnderlyingType);
- return std::make_shared<lldb_private::Type>(
- toOpaqueUid(type_id), this, ConstString(uname),
- underlying_type->GetByteSize(nullptr), nullptr, LLDB_INVALID_UID,
- lldb_private::Type::eEncodingIsUID, decl, ct,
- lldb_private::Type::ResolveState::Forward);
+ return MakeType(toOpaqueUid(type_id), ConstString(uname),
+ underlying_type->GetByteSize(nullptr), nullptr,
+ LLDB_INVALID_UID, lldb_private::Type::eEncodingIsUID, decl,
+ ct, lldb_private::Type::ResolveState::Forward);
}
TypeSP SymbolFileNativePDB::CreateArrayType(PdbTypeSymId type_id,
TypeSP element_type = GetOrCreateType(ar.ElementType);
Declaration decl;
- TypeSP array_sp = std::make_shared<lldb_private::Type>(
- toOpaqueUid(type_id), this, ConstString(), ar.Size, nullptr,
- LLDB_INVALID_UID, lldb_private::Type::eEncodingIsUID, decl, ct,
- lldb_private::Type::ResolveState::Full);
+ TypeSP array_sp =
+ MakeType(toOpaqueUid(type_id), ConstString(), ar.Size, nullptr,
+ LLDB_INVALID_UID, lldb_private::Type::eEncodingIsUID, decl, ct,
+ lldb_private::Type::ResolveState::Full);
array_sp->SetEncodingType(element_type.get());
return array_sp;
}
-
TypeSP SymbolFileNativePDB::CreateFunctionType(PdbTypeSymId type_id,
const MemberFunctionRecord &mfr,
CompilerType ct) {
Declaration decl;
- return std::make_shared<lldb_private::Type>(
- toOpaqueUid(type_id), this, ConstString(), 0, nullptr, LLDB_INVALID_UID,
- lldb_private::Type::eEncodingIsUID, decl, ct,
- lldb_private::Type::ResolveState::Full);
+ return MakeType(toOpaqueUid(type_id), ConstString(), 0, nullptr,
+ LLDB_INVALID_UID, lldb_private::Type::eEncodingIsUID, decl,
+ ct, lldb_private::Type::ResolveState::Full);
}
TypeSP SymbolFileNativePDB::CreateProcedureType(PdbTypeSymId type_id,
const ProcedureRecord &pr,
CompilerType ct) {
Declaration decl;
- return std::make_shared<lldb_private::Type>(
- toOpaqueUid(type_id), this, ConstString(), 0, nullptr, LLDB_INVALID_UID,
- lldb_private::Type::eEncodingIsUID, decl, ct,
- lldb_private::Type::ResolveState::Full);
+ return MakeType(toOpaqueUid(type_id), ConstString(), 0, nullptr,
+ LLDB_INVALID_UID, lldb_private::Type::eEncodingIsUID, decl,
+ ct, lldb_private::Type::ResolveState::Full);
}
TypeSP SymbolFileNativePDB::CreateType(PdbTypeSymId type_id, CompilerType ct) {
ts->GetNativePDBParser()->GetOrCreateTypedefDecl(id);
Declaration decl;
- return std::make_shared<lldb_private::Type>(
- toOpaqueUid(id), this, ConstString(udt.Name),
- target_type->GetByteSize(nullptr), nullptr, target_type->GetID(),
- lldb_private::Type::eEncodingIsTypedefUID, decl,
- target_type->GetForwardCompilerType(),
+ return MakeType(
+ toOpaqueUid(id), ConstString(udt.Name), target_type->GetByteSize(nullptr),
+ nullptr, target_type->GetID(), lldb_private::Type::eEncodingIsTypedefUID,
+ decl, target_type->GetForwardCompilerType(),
lldb_private::Type::ResolveState::Forward);
}
clang_type = clang_type.AddVolatileModifier();
GetDeclarationForSymbol(type, decl);
- return std::make_shared<lldb_private::Type>(
- type.getSymIndexId(), m_ast.GetSymbolFile(), ConstString(name),
- udt->getLength(), nullptr, LLDB_INVALID_UID,
- lldb_private::Type::eEncodingIsUID, decl, clang_type,
+ return m_ast.GetSymbolFile()->MakeType(
+ type.getSymIndexId(), ConstString(name), udt->getLength(), nullptr,
+ LLDB_INVALID_UID, lldb_private::Type::eEncodingIsUID, decl, clang_type,
type_resolve_state);
} break;
case PDB_SymType::Enum: {
ast_enum = ast_enum.AddVolatileModifier();
GetDeclarationForSymbol(type, decl);
- return std::make_shared<lldb_private::Type>(
- type.getSymIndexId(), m_ast.GetSymbolFile(), ConstString(name), bytes,
- nullptr, LLDB_INVALID_UID, lldb_private::Type::eEncodingIsUID, decl,
- ast_enum, lldb_private::Type::ResolveState::Full);
+ return m_ast.GetSymbolFile()->MakeType(
+ type.getSymIndexId(), ConstString(name), bytes, nullptr,
+ LLDB_INVALID_UID, lldb_private::Type::eEncodingIsUID, decl, ast_enum,
+ lldb_private::Type::ResolveState::Full);
} break;
case PDB_SymType::Typedef: {
auto type_def = llvm::dyn_cast<PDBSymbolTypeTypedef>(&type);
std::optional<uint64_t> size;
if (type_def->getLength())
size = type_def->getLength();
- return std::make_shared<lldb_private::Type>(
- type_def->getSymIndexId(), m_ast.GetSymbolFile(), ConstString(name),
- size, nullptr, target_type->GetID(),
- lldb_private::Type::eEncodingIsTypedefUID, decl, ast_typedef,
- lldb_private::Type::ResolveState::Full);
+ return m_ast.GetSymbolFile()->MakeType(
+ type_def->getSymIndexId(), ConstString(name), size, nullptr,
+ target_type->GetID(), lldb_private::Type::eEncodingIsTypedefUID, decl,
+ ast_typedef, lldb_private::Type::ResolveState::Full);
} break;
case PDB_SymType::Function:
case PDB_SymType::FunctionSig: {
arg_list.size(), is_variadic, type_quals, cc);
GetDeclarationForSymbol(type, decl);
- return std::make_shared<lldb_private::Type>(
- type.getSymIndexId(), m_ast.GetSymbolFile(), ConstString(name),
- std::nullopt, nullptr, LLDB_INVALID_UID,
- lldb_private::Type::eEncodingIsUID, decl, func_sig_ast_type,
- lldb_private::Type::ResolveState::Full);
+ return m_ast.GetSymbolFile()->MakeType(
+ type.getSymIndexId(), ConstString(name), std::nullopt, nullptr,
+ LLDB_INVALID_UID, lldb_private::Type::eEncodingIsUID, decl,
+ func_sig_ast_type, lldb_private::Type::ResolveState::Full);
} break;
case PDB_SymType::ArrayType: {
auto array_type = llvm::dyn_cast<PDBSymbolTypeArray>(&type);
}
CompilerType array_ast_type = m_ast.CreateArrayType(
element_ast_type, num_elements, /*is_gnu_vector*/ false);
- TypeSP type_sp = std::make_shared<lldb_private::Type>(
- array_type->getSymIndexId(), m_ast.GetSymbolFile(), ConstString(),
- bytes, nullptr, LLDB_INVALID_UID, lldb_private::Type::eEncodingIsUID,
- decl, array_ast_type, lldb_private::Type::ResolveState::Full);
+ TypeSP type_sp = m_ast.GetSymbolFile()->MakeType(
+ array_type->getSymIndexId(), ConstString(), bytes, nullptr,
+ LLDB_INVALID_UID, lldb_private::Type::eEncodingIsUID, decl,
+ array_ast_type, lldb_private::Type::ResolveState::Full);
type_sp->SetEncodingType(element_type);
return type_sp;
} break;
auto type_name = GetPDBBuiltinTypeName(*builtin_type, builtin_ast_type);
- return std::make_shared<lldb_private::Type>(
- builtin_type->getSymIndexId(), m_ast.GetSymbolFile(), type_name, bytes,
- nullptr, LLDB_INVALID_UID, lldb_private::Type::eEncodingIsUID, decl,
+ return m_ast.GetSymbolFile()->MakeType(
+ builtin_type->getSymIndexId(), type_name, bytes, nullptr,
+ LLDB_INVALID_UID, lldb_private::Type::eEncodingIsUID, decl,
builtin_ast_type, lldb_private::Type::ResolveState::Full);
} break;
case PDB_SymType::PointerType: {
pointee_type->GetForwardCompilerType());
assert(pointer_ast_type);
- return std::make_shared<lldb_private::Type>(
- pointer_type->getSymIndexId(), m_ast.GetSymbolFile(), ConstString(),
+ return m_ast.GetSymbolFile()->MakeType(
+ pointer_type->getSymIndexId(), ConstString(),
pointer_type->getLength(), nullptr, LLDB_INVALID_UID,
lldb_private::Type::eEncodingIsUID, decl, pointer_ast_type,
lldb_private::Type::ResolveState::Forward);
if (pointer_type->isRestrictedType())
pointer_ast_type = pointer_ast_type.AddRestrictModifier();
- return std::make_shared<lldb_private::Type>(
- pointer_type->getSymIndexId(), m_ast.GetSymbolFile(), ConstString(),
- pointer_type->getLength(), nullptr, LLDB_INVALID_UID,
- lldb_private::Type::eEncodingIsUID, decl, pointer_ast_type,
- lldb_private::Type::ResolveState::Full);
+ return m_ast.GetSymbolFile()->MakeType(
+ pointer_type->getSymIndexId(), ConstString(), pointer_type->getLength(),
+ nullptr, LLDB_INVALID_UID, lldb_private::Type::eEncodingIsUID, decl,
+ pointer_ast_type, lldb_private::Type::ResolveState::Full);
} break;
default:
break;
lldb::TypeSP result = pdb->CreateLLDBTypeFromPDBType(*pdb_type);
if (result) {
m_types.insert(std::make_pair(type_uid, result));
- GetTypeList().Insert(result);
}
return result.get();
}
ScratchTypeSystemClang::InferIsolatedASTKindFromLangOpts(lang_opts));
}
-TEST_F(TestTypeSystemClang, GetExeModuleWhenMissingSymbolFile) {
- CompilerType compiler_type = m_ast->GetBasicTypeFromAST(lldb::eBasicTypeInt);
- lldb_private::Type t(0, nullptr, ConstString("MyType"), std::nullopt, nullptr,
- 0, {}, {}, compiler_type,
- lldb_private::Type::ResolveState::Full);
- // Test that getting the execution module when no type system is present
- // is handled gracefully.
- ModuleSP module = t.GetExeModule();
- EXPECT_EQ(module.get(), nullptr);
+TEST_F(TestTypeSystemClang, GetDeclContextByNameWhenMissingSymbolFile) {
+ // Test that a type system without a symbol file is handled gracefully.
+ std::vector<CompilerDecl> decls =
+ m_ast->DeclContextFindDeclByName(nullptr, ConstString("SomeName"), true);
+
+ EXPECT_TRUE(decls.empty());
}