diff --git a/lldb/bindings/interface/SBModule.i b/lldb/bindings/interface/SBModule.i --- a/lldb/bindings/interface/SBModule.i +++ b/lldb/bindings/interface/SBModule.i @@ -197,6 +197,9 @@ bool GetDescription (lldb::SBStream &description); + bool + IsLoaded (const lldb::SBTarget &target) const; + uint32_t GetNumCompileUnits(); 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 @@ -118,6 +118,8 @@ bool GetDescription(lldb::SBStream &description); + bool IsLoaded(const lldb::SBTarget &target) const; + uint32_t GetNumCompileUnits(); lldb::SBCompileUnit GetCompileUnitAtIndex(uint32_t); diff --git a/lldb/source/API/SBModule.cpp b/lldb/source/API/SBModule.cpp --- a/lldb/source/API/SBModule.cpp +++ b/lldb/source/API/SBModule.cpp @@ -251,6 +251,21 @@ return true; } +bool SBModule::IsLoaded(const SBTarget &target) const { + LLDB_RECORD_METHOD_CONST(bool, SBModule, IsLoaded, (const lldb::SBTarget &), + target); + + ModuleSP module_sp(GetSP()); + if (!module_sp) + return LLDB_RECORD_RESULT(false); + + TargetSP target_sp(target.GetSP()); + if (!target_sp) + return LLDB_RECORD_RESULT(false); + + return LLDB_RECORD_RESULT(module_sp->IsLoadedInTarget(target_sp.get())); +} + uint32_t SBModule::GetNumCompileUnits() { LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBModule, GetNumCompileUnits); @@ -730,6 +745,8 @@ ResolveSymbolContextForAddress, (const lldb::SBAddress &, uint32_t)); LLDB_REGISTER_METHOD(bool, SBModule, GetDescription, (lldb::SBStream &)); + LLDB_REGISTER_METHOD_CONST(bool, SBModule, IsLoaded, + (const lldb::SBTarget &)); LLDB_REGISTER_METHOD(uint32_t, SBModule, GetNumCompileUnits, ()); LLDB_REGISTER_METHOD(lldb::SBCompileUnit, SBModule, GetCompileUnitAtIndex, (uint32_t)); diff --git a/lldb/test/API/python_api/module_section/TestModuleAndSection.py b/lldb/test/API/python_api/module_section/TestModuleAndSection.py --- a/lldb/test/API/python_api/module_section/TestModuleAndSection.py +++ b/lldb/test/API/python_api/module_section/TestModuleAndSection.py @@ -6,6 +6,7 @@ import lldb +import lldbsuite.test.lldbutil as lldbutil from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * from lldbsuite.test import lldbutil @@ -165,3 +166,21 @@ self.assertTrue( sc.GetCompileUnit().GetFileSpec().GetFilename() == source_name) + + @add_test_categories(['pyapi']) + def test_is_loaded(self): + """Exercise SBModule.IsLoaded(SBTarget&) API.""" + self.build() + self.main_source_file = lldb.SBFileSpec("main.cpp") + + target, _, _, _ = lldbutil.run_to_line_breakpoint(self, + self.main_source_file, + line_number(self.main_source_file.GetFilename(), + 'Hello')) + + num_modules = target.GetNumModules() + for i in range(num_modules): + module = target.GetModuleAtIndex(i) + module_is_loaded = module.IsLoaded(target) + self.assertTrue(module_is_loaded, "Module is not loaded in " + "target.")