Search code examples
lldb

LLDB Memory or read write on runtime


After playing around with lldb, I want to explore a way to write a register or memory value when a condition applies (breakpoint) automatically.

Does lldb have a feature like that?

Thanks


Solution

  • lldb breakpoints have conditions and commands. The condition (-c option to break set or break modify) is a C (ObjC/C++) expression evaluated in the frame context of the breakpoint hit.

    The commands (added with breakpoint command add) only get run if the condition evaluates to true. So if you can express the condition as an expression and the action as a sequence of fixed lldb commands, then you can implement the behavior you want that way.

    You can also write breakpoint commands in Python (breakpoint command add -s python using the SB API's:

    https://lldb.llvm.org/python_reference/index.html

    so if you have a more complex condition under which you want to make your changes, or more complex actions, you can do those tasks with the Python API's.