[Lldb-commits] [lldb] [lldb/Plugins] Introduce Scripted Platform Plugin (PR #99814)

via lldb-commits lldb-commits at lists.llvm.org
Thu Aug 8 13:47:28 PDT 2024


jimingham wrote:

> To extend on Pavel's modification of my idea:
> 
> ```
> class ScriptedPlatform:
>   def extends_platform_name(self):
>     '''Get the name of the internal platform this class extends.'''
>     return "iPhoneOS.platform"
> ```
> 
> Then every function would have 3 variants:
> 
> ```
> def pre_XXX(...):
> def XXX(...)
> def post_XXX(...)
> ```
> 
> So for "attach_to_process" this would mean the possible functions are:
> 
> ```
> class ScriptedPlatform:
>   def pre_attach_to_process(self, ...):
>     # Called before the extended platform default attach_to_process() functionality
>     # but only if `def extends_platform_name(self)` exists in this class. The default
>     # attach_to_process() from the extended platform will be called after this function
>     # completes.
> 
>   def attach_to_process(self, ...):
>     # This will override the attach_to_process() functionality. Clients that implement
>     # this function should not override pre_attach_to_process() or 
>     # post_attach_to_process() as everything can be done in this function.
> 
>   def post_attach_to_process(...)
>     # Called after the extended platform's default attach_to_process() functionality
>     # but only if `def extends_platform_name(self)` exists in this class. 
> ```

If we were to do it this way, I would not have "attach_to_process" be the override of the underlying platform's method, because you could also have a scripted platform that extends nothing, and it would use attach_to_process but override nothing.  I think it would be clearer to have the "override" version explicitly state that it is that, so: `override_attach_to_process` rather than `attach_to_process`.

But again, if most of the things that we want the scripted platform to do are methods that really ought to be available in the SBPlatform API, then I think it would be much more straightforward to be able to have the scripted version just make an instance of the platform it wants to wrap, and do the dispatch itself.

I do think it would also be handy to be able to have a wrapping scripted platform override the name lookup of the platform it wraps as well.  You might have something special you wanted to do for you installation with say the `remote-macosx` platform in your environment, and it would be simpler if you could just tell people to install your scripted platform, and then just use `remote-macosx` as they were before.  That means we need to have a shadowing list (in the Debugger) of the scripted platforms, and also a way to ask for the "built-in" platform of that name.



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


More information about the lldb-commits mailing list