Skip to content

Commit 10bc28f

Browse files
committed
[lldb/API] Expose Module::IsLoadedInTarget() to SB API (NFC)
This patch adds an `SBTarget::IsLoaded(const SBModule&) 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 Differential Review: https://reviews.llvm.org/D95686 Signed-off-by: Med Ismail Bennani <[email protected]>
1 parent 08fbe73 commit 10bc28f

File tree

4 files changed

+53
-0
lines changed

4 files changed

+53
-0
lines changed

lldb/bindings/interface/SBTarget.i

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -952,6 +952,16 @@ public:
952952
lldb::addr_t
953953
GetStackRedZoneSize();
954954

955+
%feature("docstring", "
956+
Returns true if the module has been loaded in this `SBTarget`.
957+
A module can be loaded either by the dynamic loader or by being manually
958+
added to the target (see `SBTarget.AddModule` and the `target module add` command).
959+
960+
:rtype: bool
961+
") IsLoaded;
962+
bool
963+
IsLoaded (const lldb::SBModule &module) const;
964+
955965
lldb::SBLaunchInfo
956966
GetLaunchInfo () const;
957967

lldb/include/lldb/API/SBTarget.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -834,6 +834,8 @@ class LLDB_API SBTarget {
834834

835835
lldb::addr_t GetStackRedZoneSize();
836836

837+
bool IsLoaded(const lldb::SBModule &module) const;
838+
837839
lldb::SBLaunchInfo GetLaunchInfo() const;
838840

839841
void SetLaunchInfo(const lldb::SBLaunchInfo &launch_info);

lldb/source/API/SBTarget.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2410,6 +2410,21 @@ lldb::addr_t SBTarget::GetStackRedZoneSize() {
24102410
return 0;
24112411
}
24122412

2413+
bool SBTarget::IsLoaded(const SBModule &module) const {
2414+
LLDB_RECORD_METHOD_CONST(bool, SBTarget, IsLoaded, (const lldb::SBModule &),
2415+
module);
2416+
2417+
TargetSP target_sp(GetSP());
2418+
if (!target_sp)
2419+
return LLDB_RECORD_RESULT(false);
2420+
2421+
ModuleSP module_sp(module.GetSP());
2422+
if (!module_sp)
2423+
return LLDB_RECORD_RESULT(false);
2424+
2425+
return LLDB_RECORD_RESULT(module_sp->IsLoadedInTarget(target_sp.get()));
2426+
}
2427+
24132428
lldb::SBLaunchInfo SBTarget::GetLaunchInfo() const {
24142429
LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::SBLaunchInfo, SBTarget, GetLaunchInfo);
24152430

@@ -2682,6 +2697,8 @@ void RegisterMethods<SBTarget>(Registry &R) {
26822697
LLDB_REGISTER_METHOD(lldb::SBValue, SBTarget, EvaluateExpression,
26832698
(const char *, const lldb::SBExpressionOptions &));
26842699
LLDB_REGISTER_METHOD(lldb::addr_t, SBTarget, GetStackRedZoneSize, ());
2700+
LLDB_REGISTER_METHOD_CONST(bool, SBTarget, IsLoaded,
2701+
(const lldb::SBModule &));
26852702
LLDB_REGISTER_METHOD_CONST(lldb::SBLaunchInfo, SBTarget, GetLaunchInfo, ());
26862703
LLDB_REGISTER_METHOD(void, SBTarget, SetLaunchInfo,
26872704
(const lldb::SBLaunchInfo &));

lldb/test/API/python_api/target/TestTargetAPI.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,3 +476,27 @@ def resolve_symbol_context_with_address(self):
476476
desc2 = get_description(symbol2)
477477
self.assertTrue(desc1 and desc2 and desc1 == desc2,
478478
"The two addresses should resolve to the same symbol")
479+
480+
@add_test_categories(['pyapi'])
481+
def test_is_loaded(self):
482+
"""Exercise SBTarget.IsLoaded(SBModule&) API."""
483+
d = {'EXE': 'b.out'}
484+
self.build(dictionary=d)
485+
self.setTearDownCleanup(dictionary=d)
486+
target = self.create_simple_target('b.out')
487+
488+
self.assertFalse(target.IsLoaded(lldb.SBModule()))
489+
490+
num_modules = target.GetNumModules()
491+
for i in range(num_modules):
492+
module = target.GetModuleAtIndex(i)
493+
self.assertFalse(target.IsLoaded(module), "Target that isn't "
494+
"running shouldn't have any module loaded.")
495+
496+
process = target.LaunchSimple(None, None,
497+
self.get_process_working_directory())
498+
499+
for i in range(num_modules):
500+
module = target.GetModuleAtIndex(i)
501+
self.assertTrue(target.IsLoaded(module), "Running the target should "
502+
"have loaded its modules.")

0 commit comments

Comments
 (0)