mirror of
https://github.com/intel/llvm.git
synced 2026-01-14 20:10:50 +08:00
GetModule, GetExeModule methods added
This commit is contained in:
@@ -277,6 +277,9 @@ public:
|
||||
lldb::SBTypeEnumMemberList
|
||||
GetEnumMembers();
|
||||
|
||||
lldb::SBModule
|
||||
GetModule();
|
||||
|
||||
const char*
|
||||
GetName();
|
||||
|
||||
@@ -330,6 +333,7 @@ public:
|
||||
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.''')
|
||||
|
||||
@@ -300,6 +300,7 @@ private:
|
||||
friend class SBSection;
|
||||
friend class SBSymbolContext;
|
||||
friend class SBTarget;
|
||||
friend class SBType;
|
||||
|
||||
explicit SBModule(const lldb::ModuleSP &module_sp);
|
||||
|
||||
|
||||
@@ -185,6 +185,8 @@ public:
|
||||
|
||||
lldb::SBTypeMemberFunction GetMemberFunctionAtIndex(uint32_t idx);
|
||||
|
||||
lldb::SBModule GetModule();
|
||||
|
||||
const char *GetName();
|
||||
|
||||
const char *GetDisplayTypeName();
|
||||
|
||||
@@ -109,12 +109,18 @@ public:
|
||||
|
||||
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);
|
||||
|
||||
@@ -261,6 +267,8 @@ public:
|
||||
|
||||
void Clear();
|
||||
|
||||
lldb::ModuleSP GetModule() const;
|
||||
|
||||
ConstString GetName() const;
|
||||
|
||||
ConstString GetDisplayTypeName() const;
|
||||
@@ -288,8 +296,12 @@ public:
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
@@ -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 @@ uint32_t SBType::GetTypeFlags() {
|
||||
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 @@ void RegisterMethods<SBType>(Registry &R) {
|
||||
(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, ());
|
||||
|
||||
@@ -727,6 +727,14 @@ ModuleSP Type::GetModule() {
|
||||
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 @@ TypeImpl::TypeImpl(const CompilerType &static_type,
|
||||
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 @@ void TypeImpl::SetType(const CompilerType &compiler_type,
|
||||
}
|
||||
|
||||
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 @@ bool TypeImpl::CheckModule(lldb::ModuleSP &module_sp) const {
|
||||
// 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 @@ bool TypeImpl::CheckModule(lldb::ModuleSP &module_sp) const {
|
||||
// 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 @@ void TypeImpl::Clear() {
|
||||
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)) {
|
||||
|
||||
2
lldb/test/API/functionalities/type_get_module/Makefile
Normal file
2
lldb/test/API/functionalities/type_get_module/Makefile
Normal file
@@ -0,0 +1,2 @@
|
||||
C_SOURCES := main.c compile_unit1.c compile_unit2.c
|
||||
include Makefile.rules
|
||||
@@ -0,0 +1,42 @@
|
||||
"""
|
||||
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())
|
||||
@@ -0,0 +1,6 @@
|
||||
struct compile_unit1_type {
|
||||
int x;
|
||||
int y;
|
||||
};
|
||||
|
||||
struct compile_unit1_type compile_unit1_var = {1, 1};
|
||||
@@ -0,0 +1,6 @@
|
||||
struct compile_unit2_type {
|
||||
int x;
|
||||
int y;
|
||||
};
|
||||
|
||||
struct compile_unit2_type compile_unit2_var = {2, 2};
|
||||
1
lldb/test/API/functionalities/type_get_module/main.c
Normal file
1
lldb/test/API/functionalities/type_get_module/main.c
Normal file
@@ -0,0 +1 @@
|
||||
int main() { return 0; }
|
||||
Reference in New Issue
Block a user