Extending Target Stop-Hooks#
Stop hooks fire whenever the process stops just before control is returned to the
user. Stop hooks can either be a set of lldb command-line commands, or can
be implemented by a suitably defined Python class. The Python-based stop-hooks
can also be passed as a set of -key -value pairs when they are added, and those
will get packaged up into a SBStructuredData Dictionary and passed to the
constructor of the Python object managing the stop hook. This allows for
parameterization of the stop hooks.
To add a Python-based stop hook, first define a class with the following methods:
Name |
Arguments |
Description |
|---|---|---|
|
|
This is the constructor for the new stop-hook. |
|
|
This is the called when the target stops. |
To use this class in lldb, run the command:
(lldb) command script import MyModule.py
(lldb) target stop-hook add -P MyModule.MyStopHook -k first -v 1 -k second -v 2
where MyModule.py is the file containing the class definition MyStopHook.
To run a stop hook only once, add it with --one-shot true. LLDB runs it at the
next stop where it applies, for every thread it applies to, and then deletes it.
At that stop, it votes on whether the process continues like any other stop
hook, so one added with --auto-continue true, or whose handle_stop returns
False, lets the process keep running. A one-shot stop hook is how a script can
do something at the next stop and then get out of the way.