[Lldb-commits] [PATCH] D95686: [lldb/API] Expose Module::IsLoadedInTarget() to SB API (NFC)
Med Ismail Bennani via Phabricator via lldb-commits
lldb-commits at lists.llvm.org
Fri Jan 29 09:55:13 PST 2021
mib created this revision.
mib added reviewers: teemperor, jingham.
mib added a project: LLDB.
Herald added a subscriber: JDevlieghere.
mib requested review of this revision.
Herald added a subscriber: lldb-commits.
This patch adds an `SBModule::IsLoaded(const SBTarget&) const` endpoint
to lldb's Scripting Bridge API. As the name suggests, it will allow the
user to know if the module is loaded in a specific target.
rdar://37957625
Signed-off-by: Med Ismail Bennani <medismail.bennani at gmail.com>
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D95686
Files:
lldb/bindings/interface/SBModule.i
lldb/include/lldb/API/SBModule.h
lldb/source/API/SBModule.cpp
lldb/test/API/python_api/module_section/TestModuleAndSection.py
Index: lldb/test/API/python_api/module_section/TestModuleAndSection.py
===================================================================
--- lldb/test/API/python_api/module_section/TestModuleAndSection.py
+++ 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.")
Index: lldb/source/API/SBModule.cpp
===================================================================
--- lldb/source/API/SBModule.cpp
+++ 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));
Index: lldb/include/lldb/API/SBModule.h
===================================================================
--- lldb/include/lldb/API/SBModule.h
+++ 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);
Index: lldb/bindings/interface/SBModule.i
===================================================================
--- lldb/bindings/interface/SBModule.i
+++ lldb/bindings/interface/SBModule.i
@@ -197,6 +197,9 @@
bool
GetDescription (lldb::SBStream &description);
+ bool
+ IsLoaded (const lldb::SBTarget &target) const;
+
uint32_t
GetNumCompileUnits();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D95686.320159.patch
Type: text/x-patch
Size: 3569 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20210129/3d5a418d/attachment-0001.bin>
More information about the lldb-commits
mailing list