This is an archive of the discontinued LLVM Phabricator instance.

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

Authored by mib on Jan 29 2021, 9:55 AM.

Details

Summary

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

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>

Diff Detail

Event Timeline

mib created this revision.Jan 29 2021, 9:55 AM
mib requested review of this revision.Jan 29 2021, 9:55 AM
teemperor requested changes to this revision.Jan 29 2021, 11:12 AM

Wouldn't it make more sense to give SBTarget a IsLoaded function? The function reads more like "please check if this target is loaded" which doesn't make sense. I get that this is how the internal API is doing it, but as we can't change the SB API I would rather have this to be logical from the start.

Also this should have a Python doc string. The short explanation what "loaded" means on the internal function is probably good enough. Something like this (assuming this will be an SBTarget function):

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).
lldb/test/API/python_api/module_section/TestModuleAndSection.py
179 ↗(On Diff #320159)

Out of curiosity: Do we need to start the program to load all modules? I thought self.dbg.CreateTarget() would be enough (which would prevent this test from requiring a process start).

186 ↗(On Diff #320159)

I think one single assert that checks for an invalid passed argument would be nice. Also I guess calling this on the dummy target and making sure that it doesn't have any of the real target's modules loaded would be nice (right now return true; would be a valid implementation for this function that passes all tests).

This revision now requires changes to proceed.Jan 29 2021, 11:12 AM
mib updated this revision to Diff 320202.Jan 29 2021, 1:19 PM
mib edited the summary of this revision. (Show Details)

Addressing @teemperor comments.

mib updated this revision to Diff 320420.Feb 1 2021, 2:43 AM
mib edited the summary of this revision. (Show Details)
mib updated this revision to Diff 320424.Feb 1 2021, 2:48 AM

Add positive test case and update assert message to be more descriptive.

mib updated this revision to Diff 320425.Feb 1 2021, 2:56 AM
teemperor accepted this revision.Feb 1 2021, 3:06 AM

some minor things in the comments, otherwise LGTM

lldb/bindings/interface/SBTarget.i
946

That sounds like the function loads the module. I think we can just leave this out as this function has only one parameter and the description makes it clear what this parameter is.

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

I think the assert message could describe why this is being checked (target that hasn't been launched doesn't have anything loaded)

selft.assertFalse(..., "Target that isn't running shouldn't have any modules loaded"`

514

"Running the target should have loaded its modules"

This revision is now accepted and ready to land.Feb 1 2021, 3:06 AM
Harbormaster completed remote builds in B87342: Diff 320420.
mib closed this revision.Feb 1 2021, 3:19 AM
mib marked 3 inline comments as done.
This revision was landed with ongoing or failed builds.Feb 1 2021, 5:10 AM
This revision was landed with ongoing or failed builds.Feb 2 2021, 6:02 PM