Search code examples
pythondebugginglldb

LLDB Python API, how do I find load address of a module?


I am trying to write a Python plugin for lldb that will make a breakpoint based on a given module name and an offset from the start of that module. Currenlty I'm doing so manually, with commands like:

(lldb) image list my_module
[  0] XXXXXXX-XXXX-XXXX-XXXX-XXXXXXXX 0x00000000deadbeef /path/to/my_module
(lldb) breakpoint set -a 0x00000000deadbeef + 0x1234

And I want to automate this. For that, I need to get the load address of my_module. Something similar to using lldb's image list command and reading the resulting address.

I found the method SBModule.ResolveFileAddress(), which does the reverse conversion - It takes the absolute address and converts it into a relative-to-module one.

Is there a function that takes an SBModule object, or a module name, and returns the load of that module?


Solution

  • Modules don't really have load addresses per se. On many systems, the different sections of a module can be independently relocated, so each section can have a different load address. That can even happen in the shared cache on mach-o, though in general mach-o loads binaries as a unit.

    "image list" shows the load address of the TEXT section of the binary. If you know the symbol you are looking for is in the TEXT section, then you can get the SBSections from the SBModule (it has a "sections" property that is iterable) find the TEXT section and get its load address.