[Lldb-commits] [lldb] Add the ability to define a Python based command that uses CommandObjectParsed (PR #70734)

Greg Clayton via lldb-commits lldb-commits at lists.llvm.org
Wed Nov 1 17:59:50 PDT 2023


https://github.com/clayborg commented:

I like this idea. Since python is so dynamic, I wonder if we can just add extra metadata to the standard "argparse" objects so that users can just write their stuff in the most pythonic way possible using `import argparse` and then adding some extra metadata that lldb can access. For example something like:

```
$ python3
Python 3.8.9 (default, Jul 27 2021, 02:53:04) 
[Clang 7.1.0 (tags/RELEASE_710/final)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import argparse
>>> ap = argparse.ArgumentParser()
>>> v = ap.add_argument('-v')
>>> print(v)
_StoreAction(option_strings=['-v'], dest='v', nargs=None, const=None, default=None, type=None, choices=None, help=None, metavar=None)
>>> print(type(v))
<class 'argparse._StoreAction'>
>>> v.lldb_type = lldb.eArgTypeBoolean
>>> v.lldb_type
lldb.eArgTypeBoolean
```
Then users can use the standard `argparse` module and just add a bit of extra metadata to it that LLDB can then access when needed. This would remove the need for a custom LLDBOVParser class.


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


More information about the lldb-commits mailing list