lldb::SBTypeEnumMemberList
GetEnumMembers();
+ lldb::SBModule
+ GetModule();
+
const char*
GetName();
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.''')
friend class SBSection;
friend class SBSymbolContext;
friend class SBTarget;
+ friend class SBType;
explicit SBModule(const lldb::ModuleSP &module_sp);
lldb::SBTypeMemberFunction GetMemberFunctionAtIndex(uint32_t idx);
+ lldb::SBModule GetModule();
+
const char *GetName();
const char *GetDisplayTypeName();
void DumpTypeName(Stream *s);
- // Since Type instances only keep a "SymbolFile *" internally, other classes
- // like TypeImpl need make sure the module is still around before playing
- // with
- // Type instances. They can store a weak pointer to the Module;
+ /// Since Type instances only keep a "SymbolFile *" internally, other classes
+ /// like TypeImpl need make sure the module is still around before playing
+ /// with
+ /// 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);
void Clear();
+ lldb::ModuleSP GetModule() const;
+
ConstString GetName() const;
ConstString GetDisplayTypeName() const;
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;
};
#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"
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);
(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, ());
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();
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();
}
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
// 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,
// 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;
}
m_dynamic_type.Clear();
}
+ModuleSP TypeImpl::GetModule() const {
+ lldb::ModuleSP module_sp;
+ if (CheckExeModule(module_sp))
+ return module_sp;
+ return nullptr;
+}
+
ConstString TypeImpl::GetName() const {
ModuleSP module_sp;
if (CheckModule(module_sp)) {
--- /dev/null
+C_SOURCES := main.c compile_unit1.c compile_unit2.c
+include Makefile.rules
--- /dev/null
+"""
+Test that SBType returns SBModule of executable file but not
+of compile unit's object file.
+"""
+
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+import lldbsuite.test.lldbutil as lldbutil
+
+
+class TestTypeGetModule(TestBase):
+
+ mydir = TestBase.compute_mydir(__file__)
+
+ def test(self):
+ self.build()
+ target = lldbutil.run_to_breakpoint_make_target(self)
+ exe_module = target.GetModuleAtIndex(0)
+
+ type1_name = 'compile_unit1_type'
+ type2_name = 'compile_unit2_type'
+
+ num_comp_units = exe_module.GetNumCompileUnits()
+ self.assertEqual(num_comp_units, 3)
+
+ comp_unit = exe_module.GetCompileUnitAtIndex(1)
+ type_name = comp_unit.GetTypes().GetTypeAtIndex(0).GetName()
+ self.assertEqual(type_name, type1_name)
+
+ comp_unit = exe_module.GetCompileUnitAtIndex(2)
+ type_name = comp_unit.GetTypes().GetTypeAtIndex(0).GetName()
+ self.assertEqual(type_name, type2_name)
+
+ type1 = target.FindFirstType(type1_name)
+ self.assertTrue(type1.IsValid())
+
+ type2 = target.FindFirstType(type2_name)
+ self.assertTrue(type2.IsValid())
+
+ self.assertTrue(exe_module == type1.GetModule() and
+ exe_module == type2.GetModule())
--- /dev/null
+struct compile_unit1_type {
+ int x;
+ int y;
+};
+
+struct compile_unit1_type compile_unit1_var = {1, 1};
--- /dev/null
+struct compile_unit2_type {
+ int x;
+ int y;
+};
+
+struct compile_unit2_type compile_unit2_var = {2, 2};
--- /dev/null
+int main() { return 0; }