Skip to content

[lldb/API] Expose Module::IsLoadedInTarget() to SB API (NFC) #2403

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions lldb/bindings/interface/SBTarget.i
Original file line number Diff line number Diff line change
Expand Up @@ -952,6 +952,16 @@ public:
lldb::addr_t
GetStackRedZoneSize();

%feature("docstring", "
Returns true if the module has been loaded in this `SBTarget`.
A module can be loaded either by the dynamic loader or by being manually
added to the target (see `SBTarget.AddModule` and the `target module add` command).

:rtype: bool
") IsLoaded;
bool
IsLoaded (const lldb::SBModule &module) const;

lldb::SBLaunchInfo
GetLaunchInfo () const;

Expand Down
2 changes: 2 additions & 0 deletions lldb/include/lldb/API/SBTarget.h
Original file line number Diff line number Diff line change
Expand Up @@ -834,6 +834,8 @@ class LLDB_API SBTarget {

lldb::addr_t GetStackRedZoneSize();

bool IsLoaded(const lldb::SBModule &module) const;

lldb::SBLaunchInfo GetLaunchInfo() const;

void SetLaunchInfo(const lldb::SBLaunchInfo &launch_info);
Expand Down
17 changes: 17 additions & 0 deletions lldb/source/API/SBTarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2410,6 +2410,21 @@ lldb::addr_t SBTarget::GetStackRedZoneSize() {
return 0;
}

bool SBTarget::IsLoaded(const SBModule &module) const {
LLDB_RECORD_METHOD_CONST(bool, SBTarget, IsLoaded, (const lldb::SBModule &),
module);

TargetSP target_sp(GetSP());
if (!target_sp)
return LLDB_RECORD_RESULT(false);

ModuleSP module_sp(module.GetSP());
if (!module_sp)
return LLDB_RECORD_RESULT(false);

return LLDB_RECORD_RESULT(module_sp->IsLoadedInTarget(target_sp.get()));
}

lldb::SBLaunchInfo SBTarget::GetLaunchInfo() const {
LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::SBLaunchInfo, SBTarget, GetLaunchInfo);

Expand Down Expand Up @@ -2682,6 +2697,8 @@ void RegisterMethods<SBTarget>(Registry &R) {
LLDB_REGISTER_METHOD(lldb::SBValue, SBTarget, EvaluateExpression,
(const char *, const lldb::SBExpressionOptions &));
LLDB_REGISTER_METHOD(lldb::addr_t, SBTarget, GetStackRedZoneSize, ());
LLDB_REGISTER_METHOD_CONST(bool, SBTarget, IsLoaded,
(const lldb::SBModule &));
LLDB_REGISTER_METHOD_CONST(lldb::SBLaunchInfo, SBTarget, GetLaunchInfo, ());
LLDB_REGISTER_METHOD(void, SBTarget, SetLaunchInfo,
(const lldb::SBLaunchInfo &));
Expand Down
25 changes: 25 additions & 0 deletions lldb/test/API/python_api/target/TestTargetAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,3 +476,28 @@ def resolve_symbol_context_with_address(self):
desc2 = get_description(symbol2)
self.assertTrue(desc1 and desc2 and desc1 == desc2,
"The two addresses should resolve to the same symbol")

@add_test_categories(['pyapi'])
@skipIfWindows
def test_is_loaded(self):
"""Exercise SBTarget.IsLoaded(SBModule&) API."""
d = {'EXE': 'b.out'}
self.build(dictionary=d)
self.setTearDownCleanup(dictionary=d)
target = self.create_simple_target('b.out')

self.assertFalse(target.IsLoaded(lldb.SBModule()))

num_modules = target.GetNumModules()
for i in range(num_modules):
module = target.GetModuleAtIndex(i)
self.assertFalse(target.IsLoaded(module), "Target that isn't "
"running shouldn't have any module loaded.")

process = target.LaunchSimple(None, None,
self.get_process_working_directory())

for i in range(num_modules):
module = target.GetModuleAtIndex(i)
self.assertTrue(target.IsLoaded(module), "Running the target should "
"have loaded its modules.")