jimingham wrote:

One thing that's nicer about this approach than independent callbacks for each 
of the hooks is that it allows you to group the three callbacks in the same 
class, so that you can more easily keep shared state.

But that's a general problem with these affordances.  For instance, it's super 
inconvenient that the summary providers and synthetic child providers produce 
separate objects to handle the callbacks.  You end up computing the sizes of 
container classes twice, once for the summary and once because you need it to 
present the type...  If the summary & child provider could share state, you'd 
only need to do that once per stop.  

And as we are adding more of these callbacks for "lifecycle events" it would be 
really convenient, as you have done here, to be able to get one object to 
manage multiple different types of callback hits.

For the case of hooks, I wonder if we could augment the -C options we currently 
use to add affordances backed by a Python class with a `__call__` method so you 
could say:

`target stop-hook add -C my_python_class --shared-instance 1 --call_method 
stop_hook_handler
`
And that would tell lldb to make a single object instance (one for each target 
in this case).   Allowing you to specify the method name means you don't have 
to do the discrimination in `__call__`...  

That way as we add more of these callbacks (which I agree we really need to do) 
then people could mix and match them as the wish, we wouldn't have to figure 
out what the right combination are for everybody's uses.

Note for summary & synthetic child providers you wouldn't need to specify the 
methods as those are pre-determined.  So the `--call-method` would not be 
necessary.

It might also be handy to be able to define several commands that share state, 
so you could do the same thing for command classes (though in that case the 
shared instance would be held by the debugger not the target...)

https://github.com/llvm/llvm-project/pull/142514
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to