[Lldb-commits] [lldb] Add a new affordance that the Python module in a dSYM (PR #133290)

via lldb-commits lldb-commits at lists.llvm.org
Thu Mar 27 12:01:46 PDT 2025


jimingham wrote:

> Do we want to just do the "command script import" _after_ the target is created to avoid this?
> 
> Or it would be great to have a way for a python script to add a callback function to be run after a target is created. So this diff could just do something like:
> 
> ```
> def target_created_callback(target):
>     pass # Do something with the target
> 
> def __lldb_init_module(debugger, internal_dict):
>   debugger.AddTargetCreatedCallback(target_created_callback);
> ```
> 
> Many scripts would love to be able to add functionality during the lifetime of a debug session like:
> 
> * right before a target is destroyed
> * first stop in a process
> * each stop of a process
> * process exited

Adding callbacks for "life-cycle events" of a target to lldb is a long-standing but considerably larger piece of work.  We would want there to be a command line way to do this, and register & deregister actions, etc.  Basically a general extension to what we do with stop-hooks.

I don't have time to add that feature as the solution to this fairly narrow problem right now.

Just deferring the command script import doesn't seem like a very robust solution, because you still aren't telling the code in the dSYM module what Target it's getting loaded into.  The only way that the `__lldb_init_module` code can find it is if it happens to still be the currently selected target when it gets to run.  We don't currently have a way to ensure that - another target could hit a breakpoint and get to be the selected target between those two steps.

https://github.com/llvm/llvm-project/pull/133290


More information about the lldb-commits mailing list