diff options
Diffstat (limited to 'source/Symbol/Type.cpp')
-rw-r--r-- | source/Symbol/Type.cpp | 313 |
1 files changed, 231 insertions, 82 deletions
diff --git a/source/Symbol/Type.cpp b/source/Symbol/Type.cpp index 073940e8a7f7..4eb538fb1352 100644 --- a/source/Symbol/Type.cpp +++ b/source/Symbol/Type.cpp @@ -30,6 +30,8 @@ #include "llvm/ADT/StringRef.h" +#include "clang/AST/Decl.h" + using namespace lldb; using namespace lldb_private; @@ -91,7 +93,7 @@ Type::Type m_name (name), m_symbol_file (symbol_file), m_context (context), - m_encoding_type (NULL), + m_encoding_type (nullptr), m_encoding_uid (encoding_uid), m_encoding_uid_type (encoding_uid_type), m_byte_size (byte_size), @@ -106,9 +108,9 @@ Type::Type () : std::enable_shared_from_this<Type> (), UserID (0), m_name ("<INVALID TYPE>"), - m_symbol_file (NULL), - m_context (NULL), - m_encoding_type (NULL), + m_symbol_file (nullptr), + m_context (nullptr), + m_encoding_type (nullptr), m_encoding_uid (LLDB_INVALID_UID), m_encoding_uid_type (eEncodingInvalid), m_byte_size (0), @@ -201,16 +203,16 @@ Type::GetDescription (Stream *s, lldb::DescriptionLevel level, bool show_name) void Type::Dump (Stream *s, bool show_context) { - s->Printf("%p: ", this); + s->Printf("%p: ", static_cast<void*>(this)); s->Indent(); - *s << "Type" << (const UserID&)*this << ' '; + *s << "Type" << static_cast<const UserID&>(*this) << ' '; if (m_name) *s << ", name = \"" << m_name << "\""; if (m_byte_size != 0) s->Printf(", size = %" PRIu64, m_byte_size); - if (show_context && m_context != NULL) + if (show_context && m_context != nullptr) { s->PutCString(", context = ( "); m_context->DumpSymbolContext(s); @@ -306,7 +308,7 @@ Type::DumpValue Type * Type::GetEncodingType () { - if (m_encoding_type == NULL && m_encoding_uid != LLDB_INVALID_UID) + if (m_encoding_type == nullptr && m_encoding_uid != LLDB_INVALID_UID) m_encoding_type = m_symbol_file->ResolveTypeUID(m_encoding_uid); return m_encoding_type; } @@ -406,7 +408,7 @@ Type::DumpValueInMemory if (address != LLDB_INVALID_ADDRESS) { DataExtractor data; - Target *target = NULL; + Target *target = nullptr; if (exe_ctx) target = exe_ctx->GetTargetPtr(); if (target) @@ -439,14 +441,14 @@ Type::ReadFromMemory (ExecutionContext *exe_ctx, lldb::addr_t addr, AddressType } uint8_t* dst = (uint8_t*)data.PeekData(0, byte_size); - if (dst != NULL) + if (dst != nullptr) { if (address_type == eAddressTypeHost) { // The address is an address in this process, so just copy it if (addr == 0) return false; - memcpy (dst, (uint8_t*)NULL + addr, byte_size); + memcpy (dst, (uint8_t*)nullptr + addr, byte_size); return true; } else @@ -488,7 +490,7 @@ Type::GetDeclaration () const bool Type::ResolveClangType (ResolveState clang_type_resolve_state) { - Type *encoding_type = NULL; + Type *encoding_type = nullptr; if (!m_clang_type.IsValid()) { encoding_type = GetEncodingType(); @@ -603,7 +605,7 @@ Type::ResolveClangType (ResolveState clang_type_resolve_state) // resolved appropriately. if (m_encoding_uid != LLDB_INVALID_UID) { - if (encoding_type == NULL) + if (encoding_type == nullptr) encoding_type = GetEncodingType(); if (encoding_type) { @@ -777,7 +779,7 @@ Type::GetTypeScopeAndBasename (const char* &name_cstr, if (namespace_separator) { const char* template_arg_char = ::strchr (basename_cstr, '<'); - while (namespace_separator != NULL) + while (namespace_separator != nullptr) { if (template_arg_char && namespace_separator > template_arg_char) // but namespace'd template arguments are still good to go break; @@ -796,6 +798,13 @@ Type::GetTypeScopeAndBasename (const char* &name_cstr, } +ModuleSP +Type::GetModule() +{ + if (m_symbol_file) + return m_symbol_file->GetObjectFile()->GetModule(); + return ModuleSP(); +} TypeAndOrName::TypeAndOrName () : m_type_pair(), m_type_name() @@ -927,76 +936,95 @@ TypeAndOrName::HasClangASTType () const TypeImpl::TypeImpl() : -m_static_type(), -m_dynamic_type() + m_module_wp(), + m_static_type(), + m_dynamic_type() { } TypeImpl::TypeImpl(const TypeImpl& rhs) : -m_static_type(rhs.m_static_type), -m_dynamic_type(rhs.m_dynamic_type) + m_module_wp (rhs.m_module_wp), + m_static_type(rhs.m_static_type), + m_dynamic_type(rhs.m_dynamic_type) { } -TypeImpl::TypeImpl (lldb::TypeSP type_sp) : -m_static_type(type_sp), -m_dynamic_type() +TypeImpl::TypeImpl (const lldb::TypeSP &type_sp) : + m_module_wp (), + m_static_type(), + m_dynamic_type() { + SetType (type_sp); } -TypeImpl::TypeImpl (ClangASTType clang_type) : -m_static_type(clang_type), -m_dynamic_type() +TypeImpl::TypeImpl (const ClangASTType &clang_type) : + m_module_wp (), + m_static_type(), + m_dynamic_type() { + SetType (clang_type); } -TypeImpl::TypeImpl (lldb::TypeSP type_sp, ClangASTType dynamic) : -m_static_type (type_sp), -m_dynamic_type(dynamic) +TypeImpl::TypeImpl (const lldb::TypeSP &type_sp, const ClangASTType &dynamic) : + m_module_wp (), + m_static_type (type_sp), + m_dynamic_type(dynamic) { + SetType (type_sp, dynamic); } -TypeImpl::TypeImpl (ClangASTType clang_type, ClangASTType dynamic) : -m_static_type (clang_type), -m_dynamic_type(dynamic) +TypeImpl::TypeImpl (const ClangASTType &static_type, const ClangASTType &dynamic_type) : + m_module_wp (), + m_static_type (), + m_dynamic_type() { + SetType (static_type, dynamic_type); } -TypeImpl::TypeImpl (TypePair pair, ClangASTType dynamic) : -m_static_type (pair), -m_dynamic_type(dynamic) +TypeImpl::TypeImpl (const TypePair &pair, const ClangASTType &dynamic) : + m_module_wp (), + m_static_type (), + m_dynamic_type() { + SetType (pair, dynamic); } void -TypeImpl::SetType (lldb::TypeSP type_sp) +TypeImpl::SetType (const lldb::TypeSP &type_sp) { m_static_type.SetType(type_sp); + if (type_sp) + m_module_wp = type_sp->GetModule(); + else + m_module_wp = lldb::ModuleWP(); } void -TypeImpl::SetType (ClangASTType clang_type) +TypeImpl::SetType (const ClangASTType &clang_type) { + m_module_wp = lldb::ModuleWP(); m_static_type.SetType (clang_type); } void -TypeImpl::SetType (lldb::TypeSP type_sp, ClangASTType dynamic) +TypeImpl::SetType (const lldb::TypeSP &type_sp, const ClangASTType &dynamic) { - m_static_type.SetType (type_sp); + SetType (type_sp); m_dynamic_type = dynamic; } void -TypeImpl::SetType (ClangASTType clang_type, ClangASTType dynamic) +TypeImpl::SetType (const ClangASTType &clang_type, const ClangASTType &dynamic) { + m_module_wp = lldb::ModuleWP(); m_static_type.SetType (clang_type); m_dynamic_type = dynamic; } void -TypeImpl::SetType (TypePair pair, ClangASTType dynamic) +TypeImpl::SetType (const TypePair &pair, const ClangASTType &dynamic) { + m_module_wp = pair.GetModule(); m_static_type = pair; m_dynamic_type = dynamic; } @@ -1006,6 +1034,7 @@ TypeImpl::operator = (const TypeImpl& rhs) { if (rhs != *this) { + m_module_wp = rhs.m_module_wp; m_static_type = rhs.m_static_type; m_dynamic_type = rhs.m_dynamic_type; } @@ -1013,24 +1042,55 @@ TypeImpl::operator = (const TypeImpl& rhs) } bool +TypeImpl::CheckModule (lldb::ModuleSP &module_sp) const +{ + // Check if we have a module for this type. If we do and the shared pointer is + // can be successfully initialized with m_module_wp, return true. Else return false + // if we didn't have a module, or if we had a module and it has been deleted. Any + // functions doing anything with a TypeSP in this TypeImpl class should call this + // function and only do anything with the ivars if this function returns true. If + // we have a module, the "module_sp" will be filled in with a strong reference to the + // module so that the module will at least stay around long enough for the type + // query to succeed. + module_sp = m_module_wp.lock(); + if (!module_sp) + { + lldb::ModuleWP empty_module_wp; + // If either call to "std::weak_ptr::owner_before(...) value returns true, this + // indicates that m_module_wp once contained (possibly still does) a reference + // to a valid shared pointer. This helps us know if we had a valid reference to + // a section which is now invalid because the module it was in was deleted + if (empty_module_wp.owner_before(m_module_wp) || m_module_wp.owner_before(empty_module_wp)) + { + // m_module_wp had a valid reference to a module, but all strong references + // have been released and the module has been deleted + return false; + } + } + // We either successfully locked the module, or didn't have one to begin with + return true; +} + +bool TypeImpl::operator == (const TypeImpl& rhs) const { - return m_static_type == rhs.m_static_type && - m_dynamic_type == rhs.m_dynamic_type; + return m_static_type == rhs.m_static_type && m_dynamic_type == rhs.m_dynamic_type; } bool TypeImpl::operator != (const TypeImpl& rhs) const { - return m_static_type != rhs.m_static_type || - m_dynamic_type != rhs.m_dynamic_type; + return m_static_type != rhs.m_static_type || m_dynamic_type != rhs.m_dynamic_type; } bool TypeImpl::IsValid() const { // just a name is not valid - return m_static_type.IsValid() || m_dynamic_type.IsValid(); + ModuleSP module_sp; + if (CheckModule (module_sp)) + return m_static_type.IsValid() || m_dynamic_type.IsValid(); + return false; } TypeImpl::operator bool () const @@ -1041,6 +1101,7 @@ TypeImpl::operator bool () const void TypeImpl::Clear() { + m_module_wp = lldb::ModuleWP(); m_static_type.Clear(); m_dynamic_type.Clear(); } @@ -1048,113 +1109,201 @@ TypeImpl::Clear() ConstString TypeImpl::GetName () const { - if (m_dynamic_type) - return m_dynamic_type.GetTypeName(); - return m_static_type.GetName (); + ModuleSP module_sp; + if (CheckModule (module_sp)) + { + if (m_dynamic_type) + return m_dynamic_type.GetTypeName(); + return m_static_type.GetName (); + } + return ConstString(); +} + +ConstString +TypeImpl::GetDisplayTypeName () const +{ + ModuleSP module_sp; + if (CheckModule (module_sp)) + { + if (m_dynamic_type) + return m_dynamic_type.GetDisplayTypeName(); + return m_static_type.GetDisplayTypeName(); + } + return ConstString(); } TypeImpl TypeImpl::GetPointerType () const { - if (m_dynamic_type.IsValid()) + ModuleSP module_sp; + if (CheckModule (module_sp)) { - return TypeImpl(m_static_type, m_dynamic_type.GetPointerType()); + if (m_dynamic_type.IsValid()) + { + return TypeImpl(m_static_type, m_dynamic_type.GetPointerType()); + } + return TypeImpl(m_static_type.GetPointerType()); } - return TypeImpl(m_static_type.GetPointerType()); + return TypeImpl(); } TypeImpl TypeImpl::GetPointeeType () const { - if (m_dynamic_type.IsValid()) + ModuleSP module_sp; + if (CheckModule (module_sp)) { - return TypeImpl(m_static_type, m_dynamic_type.GetPointeeType()); + if (m_dynamic_type.IsValid()) + { + return TypeImpl(m_static_type, m_dynamic_type.GetPointeeType()); + } + return TypeImpl(m_static_type.GetPointeeType()); } - return TypeImpl(m_static_type.GetPointeeType()); + return TypeImpl(); } TypeImpl TypeImpl::GetReferenceType () const { - if (m_dynamic_type.IsValid()) + ModuleSP module_sp; + if (CheckModule (module_sp)) { - return TypeImpl(m_static_type, m_dynamic_type.GetLValueReferenceType()); + if (m_dynamic_type.IsValid()) + { + return TypeImpl(m_static_type, m_dynamic_type.GetLValueReferenceType()); + } + return TypeImpl(m_static_type.GetReferenceType()); } - return TypeImpl(m_static_type.GetReferenceType()); + return TypeImpl(); } TypeImpl TypeImpl::GetTypedefedType () const { - if (m_dynamic_type.IsValid()) + ModuleSP module_sp; + if (CheckModule (module_sp)) { - return TypeImpl(m_static_type, m_dynamic_type.GetTypedefedType()); + if (m_dynamic_type.IsValid()) + { + return TypeImpl(m_static_type, m_dynamic_type.GetTypedefedType()); + } + return TypeImpl(m_static_type.GetTypedefedType()); } - return TypeImpl(m_static_type.GetTypedefedType()); + return TypeImpl(); } TypeImpl TypeImpl::GetDereferencedType () const { - if (m_dynamic_type.IsValid()) + ModuleSP module_sp; + if (CheckModule (module_sp)) { - return TypeImpl(m_static_type, m_dynamic_type.GetNonReferenceType()); + if (m_dynamic_type.IsValid()) + { + return TypeImpl(m_static_type, m_dynamic_type.GetNonReferenceType()); + } + return TypeImpl(m_static_type.GetDereferencedType()); } - return TypeImpl(m_static_type.GetDereferencedType()); + return TypeImpl(); } TypeImpl TypeImpl::GetUnqualifiedType() const { - if (m_dynamic_type.IsValid()) + ModuleSP module_sp; + if (CheckModule (module_sp)) { - return TypeImpl(m_static_type, m_dynamic_type.GetFullyUnqualifiedType()); + if (m_dynamic_type.IsValid()) + { + return TypeImpl(m_static_type, m_dynamic_type.GetFullyUnqualifiedType()); + } + return TypeImpl(m_static_type.GetUnqualifiedType()); } - return TypeImpl(m_static_type.GetUnqualifiedType()); + return TypeImpl(); } TypeImpl TypeImpl::GetCanonicalType() const { - if (m_dynamic_type.IsValid()) + ModuleSP module_sp; + if (CheckModule (module_sp)) { - return TypeImpl(m_static_type, m_dynamic_type.GetCanonicalType()); + if (m_dynamic_type.IsValid()) + { + return TypeImpl(m_static_type, m_dynamic_type.GetCanonicalType()); + } + return TypeImpl(m_static_type.GetCanonicalType()); } - return TypeImpl(m_static_type.GetCanonicalType()); + return TypeImpl(); } ClangASTType TypeImpl::GetClangASTType (bool prefer_dynamic) { - if (prefer_dynamic) + ModuleSP module_sp; + if (CheckModule (module_sp)) { - if (m_dynamic_type.IsValid()) - return m_dynamic_type; + if (prefer_dynamic) + { + if (m_dynamic_type.IsValid()) + return m_dynamic_type; + } + return m_static_type.GetClangASTType(); } - return m_static_type.GetClangASTType(); + return ClangASTType(); } clang::ASTContext * TypeImpl::GetClangASTContext (bool prefer_dynamic) { - if (prefer_dynamic) + ModuleSP module_sp; + if (CheckModule (module_sp)) { - if (m_dynamic_type.IsValid()) - return m_dynamic_type.GetASTContext(); + if (prefer_dynamic) + { + if (m_dynamic_type.IsValid()) + return m_dynamic_type.GetASTContext(); + } + return m_static_type.GetClangASTContext(); } - return m_static_type.GetClangASTContext(); + return NULL; } bool TypeImpl::GetDescription (lldb_private::Stream &strm, - lldb::DescriptionLevel description_level) + lldb::DescriptionLevel description_level) { - if (m_dynamic_type.IsValid()) + ModuleSP module_sp; + if (CheckModule (module_sp)) { - strm.Printf("Dynamic:\n"); - m_dynamic_type.DumpTypeDescription(&strm); - strm.Printf("\nStatic:\n"); + if (m_dynamic_type.IsValid()) + { + strm.Printf("Dynamic:\n"); + m_dynamic_type.DumpTypeDescription(&strm); + strm.Printf("\nStatic:\n"); + } + m_static_type.GetClangASTType().DumpTypeDescription(&strm); + } + else + { + strm.PutCString("Invalid TypeImpl module for type has been deleted\n"); } - m_static_type.GetClangASTType().DumpTypeDescription(&strm); return true; } + +TypeEnumMemberImpl::TypeEnumMemberImpl (const clang::EnumConstantDecl* enum_member_decl, + const lldb_private::ClangASTType& integer_type) : + m_integer_type_sp(), + m_name(), + m_value(), + m_valid(false) + +{ + if (enum_member_decl) + { + m_integer_type_sp.reset(new TypeImpl(integer_type)); + m_name = ConstString(enum_member_decl->getNameAsString().c_str()); + m_value = enum_member_decl->getInitVal(); + m_valid = true; + } +} |