Skip to content

Add the new "parsed cmd" from llvm mainline to 2030725 #8204

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Feb 16, 2024

Conversation

jimingham
Copy link

I recently added the ability to define commands from Python that use the lldb command parser. That allows lldb to do completion on the arguments and options, and it makes help consistent with lldb help.

This PR is what we need to cherry-pick that feature onto the stable/20230725 branch.

medismailben and others added 8 commits February 14, 2024 13:41
This patch moves the template files for the various scripting
affordances to a separate directory.

This is a preparatory work for upcoming improvements and consolidations
to other scripting affordances.

Differential Revision: https://reviews.llvm.org/D159310

Signed-off-by: Med Ismail Bennani <[email protected]>
(cherry picked from commit 6bff2d5)
…ectParsed (llvm#70734)

This allows you to specify options and arguments and their definitions
and then have lldb handle the completions, help, etc. in the same way
that lldb does for its parsed commands internally.

This feature has some design considerations as well as the code, so I've
also set up an RFC, but I did this one first and will put the RFC
address in here once I've pushed it...

Note, the lldb "ParsedCommand interface" doesn't actually do all the
work that it should. For instance, saying the type of an option that has
a completer doesn't automatically hook up the completer, and ditto for
argument values. We also do almost no work to verify that the arguments
match their definition, or do auto-completion for them. This patch
allows you to make a command that's bug-for-bug compatible with built-in
ones, but I didn't want to stall it on getting the auto-command checking
to work all the way correctly.

As an overall design note, my primary goal here was to make an interface
that worked well in the script language. For that I needed, for
instance, to have a property-based way to get all the option values that
were specified. It was much more convenient to do that by making a
fairly bare-bones C interface to define the options and arguments of a
command, and set their values, and then wrap that in a Python class
(installed along with the other bits of the lldb python module) which
you can then derive from to make your new command. This approach will
also make it easier to experiment.

See the file test_commands.py in the test case for examples of how this
works.

(cherry picked from commit a69ecb2)
why it's crashing on the x86_64 Debian Linux worker.

(cherry picked from commit f0b271e)
The Linux std has more asserts enabled by default, so it
complained, even though this worked on Darwin...

(cherry picked from commit 3647ff1)
When the parsed command python code is run on 3.9, I get:

File ".../lib/python3.9/site-packages/lldb/plugins/parsed_cmd.py", line 124, in translate_value
    return cls.translators[value_type](value)
TypeError: 'staticmethod' object is not callable

But this works correctly in Python 3.10 on macOS and Linux.  I'm guessing something
changed between those versions, and I'll have to do something to work around the difference.
But I'm going to skip the test on 3.9 while I figure that out.

(cherry picked from commit 1ec8197)
Python3.9 does not allow you to put a reference to a class staticmethod
in a table and call it from there.  Python3.10 and following do allow
this, but we still support 3.9.  staticmethod was slightly cleaner,
but this will do.

(cherry picked from commit 22d2f3a)
This comes from a larger patch (f22d82c) but I don't want to
try to incorporate that, so I'm just copying this bit in.
@jimingham
Copy link
Author

@swift-ci please test

@jimingham jimingham merged commit 02a02cb into swiftlang:stable/20230725 Feb 16, 2024
@jimingham jimingham deleted the parsed-cmd-for-2030725 branch February 16, 2024 00:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants