This is an archive of the discontinued LLVM Phabricator instance.

[lldb] Add tests for command removal
Needs ReviewPublic

Authored by wallace on Apr 27 2023, 1:53 PM.

Details

Reviewers
jingham
Summary

This adds some tests for removing lldb commands, user command and aliases. I've done in the SB API side for comleteness of this features. Besides that, I found a bug in the creation of the DummyCommand used in the test file: they were being allocated in the stack but they should have been allocated in the heap because CommandPluginInterfaceImplementation ends up owning the pointer passed to it, which is internally managed by a shared_ptr.

Diff Detail

Event Timeline

wallace created this revision.Apr 27 2023, 1:53 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 27 2023, 1:53 PM
wallace requested review of this revision.Apr 27 2023, 1:53 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 27 2023, 1:53 PM
jingham added a comment.EditedMay 9 2023, 3:53 PM

What happens if you remove a command that had an alias bound to it and then call the alias? We should probably add a test for this, it should produce some reasonable error... Probably need to test both the regex & regular aliases as those manage their dispatch differently.

The alias still works because it still holds a reference to it. I could add that as a test

The alias still works because it still holds a reference to it. I could add that as a test

The alias works but the original command is gone? Interesting. We should definitely test that that works correctly. We should also test what happens when a regex command dispatches to a command that has been deleted.

Also, should the "delete" operation fail or return an error if the actual command is still made available because of an alias. If your intention was to remove a built-in command (still not sure why that is an operation that makes sense, but that aside...) then you haven't if you can still get to it through an alias. Should we tell the user that?

TTTT, removing user commands is cosmetic if you don't remove script as well, since there's pretty much nothing that can be done on the command line that can't be done with scripts. So I don't have a sense for how strict you are trying to be. But if I can defeat the removal of a command by putting an alias in my .lldbinit, you are being very not strict...

lldb/include/lldb/API/SBCommandInterpreter.h
316

You should probably say explicitly what the "removable status" of a built-in command is. You (correctly) have to explicitly pass force=true for that to work but it would be good to state that explicitly. We should also emphasize here there isn't any way to get a built-in command back once you've deleted it.