pythonlldb

LLDB Python scripting - how to add module or load symbol file at particular address?


In LLDB you can do the following during a debugging session to add missing symbols at particular addresses:

target modules load --file <symbol file> .text 0x<address>

How can you do that in with the LLDB Python scripting module? I searched through the API but I couldn't find a corresponding method.


Solution

  • I figured it out. You can make use of the debugger.HandleCommand to run arbitrary LLDB command. The general way I resolved this was to define and register a function that can be called during a LLDB debugging session.

    For example:

    def load_libraries(debugger, command, result, internal_dict):
        print(f"image add some_library.so", flush=True)
        debugger.HandleCommand(f"image add some_library.so")
        print(f"target modules load --file some_library.so .text 0x<some address>", flush=True)
        debugger.HandleCommand(f"target modules load --file some_library.so .text 0x<some address>")