diff --git a/lldb/bindings/interface/SBType.i b/lldb/bindings/interface/SBType.i --- a/lldb/bindings/interface/SBType.i +++ b/lldb/bindings/interface/SBType.i @@ -277,6 +277,9 @@ lldb::SBTypeEnumMemberList GetEnumMembers(); + lldb::SBModule + GetModule(); + const char* GetName(); @@ -330,6 +333,7 @@ return template_args return None + module = property(GetModule, None, doc='''A read only property that returns the module in which type is defined.''') name = property(GetName, None, doc='''A read only property that returns the name for this type as a string.''') size = property(GetByteSize, None, doc='''A read only property that returns size in bytes for this type as an integer.''') is_pointer = property(IsPointerType, None, doc='''A read only property that returns a boolean value that indicates if this type is a pointer type.''') diff --git a/lldb/include/lldb/API/SBModule.h b/lldb/include/lldb/API/SBModule.h --- a/lldb/include/lldb/API/SBModule.h +++ b/lldb/include/lldb/API/SBModule.h @@ -300,6 +300,7 @@ friend class SBSection; friend class SBSymbolContext; friend class SBTarget; + friend class SBType; explicit SBModule(const lldb::ModuleSP &module_sp); diff --git a/lldb/include/lldb/API/SBType.h b/lldb/include/lldb/API/SBType.h --- a/lldb/include/lldb/API/SBType.h +++ b/lldb/include/lldb/API/SBType.h @@ -185,6 +185,8 @@ lldb::SBTypeMemberFunction GetMemberFunctionAtIndex(uint32_t idx); + lldb::SBModule GetModule(); + const char *GetName(); const char *GetDisplayTypeName(); diff --git a/lldb/include/lldb/Symbol/Type.h b/lldb/include/lldb/Symbol/Type.h --- a/lldb/include/lldb/Symbol/Type.h +++ b/lldb/include/lldb/Symbol/Type.h @@ -114,6 +114,14 @@ // Type instances. They can store a weak pointer to the Module; lldb::ModuleSP GetModule(); + /* + GetModule may return module for compile unit's object file. + GetExeModule returns module for executable object file that contains + compile unit where type was actualy defined. + GetModule and GetExeModule may return the same value. + */ + lldb::ModuleSP GetExeModule(); + void GetDescription(Stream *s, lldb::DescriptionLevel level, bool show_name, ExecutionContextScope *exe_scope); @@ -260,6 +268,8 @@ void Clear(); + lldb::ModuleSP GetModule(); + ConstString GetName() const; ConstString GetDisplayTypeName() const; @@ -287,8 +297,12 @@ private: bool CheckModule(lldb::ModuleSP &module_sp) const; + bool CheckExeModule(lldb::ModuleSP &module_sp) const; + bool CheckModuleCommon(const lldb::ModuleWP &input_module_wp, + lldb::ModuleSP &module_sp) const; lldb::ModuleWP m_module_wp; + lldb::ModuleWP m_exe_module_wp; CompilerType m_static_type; CompilerType m_dynamic_type; }; diff --git a/lldb/source/API/SBType.cpp b/lldb/source/API/SBType.cpp --- a/lldb/source/API/SBType.cpp +++ b/lldb/source/API/SBType.cpp @@ -9,6 +9,7 @@ #include "lldb/API/SBType.h" #include "SBReproducerPrivate.h" #include "lldb/API/SBDefines.h" +#include "lldb/API/SBModule.h" #include "lldb/API/SBStream.h" #include "lldb/API/SBTypeEnumMember.h" #include "lldb/Core/Mangled.h" @@ -495,6 +496,17 @@ return m_opaque_sp->GetCompilerType(true).GetTypeInfo(); } +lldb::SBModule SBType::GetModule() { + LLDB_RECORD_METHOD_NO_ARGS(lldb::SBModule, SBType, GetModule); + + lldb::SBModule sb_module; + if (!IsValid()) + return LLDB_RECORD_RESULT(sb_module); + + sb_module.SetSP(m_opaque_sp->GetModule()); + return LLDB_RECORD_RESULT(sb_module); +} + const char *SBType::GetName() { LLDB_RECORD_METHOD_NO_ARGS(const char *, SBType, GetName); @@ -950,6 +962,7 @@ (uint32_t)); LLDB_REGISTER_METHOD(bool, SBType, IsTypeComplete, ()); LLDB_REGISTER_METHOD(uint32_t, SBType, GetTypeFlags, ()); + LLDB_REGISTER_METHOD(lldb::SBModule, SBType, GetModule, ()); LLDB_REGISTER_METHOD(const char *, SBType, GetName, ()); LLDB_REGISTER_METHOD(const char *, SBType, GetDisplayTypeName, ()); LLDB_REGISTER_METHOD(lldb::TypeClass, SBType, GetTypeClass, ()); diff --git a/lldb/source/Symbol/Type.cpp b/lldb/source/Symbol/Type.cpp --- a/lldb/source/Symbol/Type.cpp +++ b/lldb/source/Symbol/Type.cpp @@ -727,6 +727,14 @@ return ModuleSP(); } +ModuleSP Type::GetExeModule() { + if (m_compiler_type) { + SymbolFile *symbol_file = m_compiler_type.GetTypeSystem()->GetSymbolFile(); + return symbol_file->GetObjectFile()->GetModule(); + } + return ModuleSP(); +} + TypeAndOrName::TypeAndOrName(TypeSP &in_type_sp) { if (in_type_sp) { m_compiler_type = in_type_sp->GetForwardCompilerType(); @@ -821,6 +829,7 @@ void TypeImpl::SetType(const lldb::TypeSP &type_sp) { if (type_sp) { m_static_type = type_sp->GetForwardCompilerType(); + m_exe_module_wp = type_sp->GetExeModule(); m_module_wp = type_sp->GetModule(); } else { m_static_type.Clear(); @@ -847,6 +856,15 @@ } bool TypeImpl::CheckModule(lldb::ModuleSP &module_sp) const { + return CheckModuleCommon(m_module_wp, module_sp); +} + +bool TypeImpl::CheckExeModule(lldb::ModuleSP &module_sp) const { + return CheckModuleCommon(m_exe_module_wp, module_sp); +} + +bool TypeImpl::CheckModuleCommon(const lldb::ModuleWP &input_module_wp, + 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 @@ -855,7 +873,7 @@ // 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(); + module_sp = input_module_wp.lock(); if (!module_sp) { lldb::ModuleWP empty_module_wp; // If either call to "std::weak_ptr::owner_before(...) value returns true, @@ -863,9 +881,9 @@ // 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 + if (empty_module_wp.owner_before(input_module_wp) || + input_module_wp.owner_before(empty_module_wp)) { + // input_module_wp had a valid reference to a module, but all strong // references have been released and the module has been deleted return false; } @@ -899,6 +917,13 @@ m_dynamic_type.Clear(); } +ModuleSP TypeImpl::GetModule() { + lldb::ModuleSP module_sp; + if (CheckExeModule(module_sp)) + return module_sp; + return nullptr; +} + ConstString TypeImpl::GetName() const { ModuleSP module_sp; if (CheckModule(module_sp)) {