This is an archive of the discontinued LLVM Phabricator instance.

Stop regex commands from double entry into the history
ClosedPublic

Authored by jingham on Jun 1 2022, 9:02 AM.

Details

Summary

At present, if you run a regex command (e.g. the b command) you will get two history entries, one for the actual command the user typed, and one for the resolved command:

(lldb) b foo.c:12
Breakpoint 1: no locations (pending).
Breakpoint set in dummy target, will get copied into future targets.
(lldb) history
   0: b foo.c:12
   1: breakpoint set --file 'foo.c' --line 12
   2: history

That seems wrong in principle, there shouldn't be double entry like this. But it also has some subtle side effects that are even less desirable. For instance, if you write a Python based command that calls "HandleCommand" of a regex command, then the resolved command gets inserted into the history list AFTER the python command the user actually ran. That in turn means that up-arrow doesn't rerun the command the user typed, but instead runs the resolved regex command.

Since regex command resolution isn't stateful - the same input string will always resolve to the same command - there's no actual reason to do this double entry, just storing the command the user typed will suffice. And there's already a way to see resolved commands, so you don't need it for this purpose either.

Diff Detail

Event Timeline

jingham created this revision.Jun 1 2022, 9:02 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 1 2022, 9:02 AM
jingham requested review of this revision.Jun 1 2022, 9:02 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 1 2022, 9:02 AM
jingham edited the summary of this revision. (Show Details)Jun 1 2022, 9:02 AM

Note, the original code tries to finesse this by passing eLazyBoolCalculate, which then resolves to a check against the current command depth. But that check was wrong for SBDebugger.HandleCommand, which is considered at depth 0, and anyway, I don't think it ever makes sense to have the regex command add the resolved command to the history.

This revision is now accepted and ready to land.Jun 1 2022, 9:31 AM

thank you for fixing!

Q: why does this test have this thin test_X/do_x_test separation?

jingham added a comment.EditedJun 1 2022, 3:29 PM

thank you for fixing!

Q: why does this test have this thin test_X/do_x_test separation?

We did that separation originally (and the sample test reflects that) so that you could see the list of tests in a file (with hopefully suggestive names) easily at the top, and then all the gritty details would be in the do_ methods below. It's also good to remind yourself that for unittest all the "test_" methods are special, you can't use that name for a helper function...

This format is not unique to this test, many of the tests (particularly older ones or ones that copied the sample test) do it that way. With tiny actual test bodies like these, it's unclear how much you gain by this, but the test was already mostly following that separation (except the test implementation name was just copied over from the sample test) I followed the practice of the file.

clayborg added inline comments.Jun 1 2022, 9:52 PM
lldb/source/Commands/CommandObjectRegexCommand.cpp
73–75

Is this comment out of date now? It mentions passing in "true"?

jingham added inline comments.Jun 3 2022, 11:26 AM
lldb/source/Commands/CommandObjectRegexCommand.cpp
73–75

No, that comment has to do with the Interpreter's ExecutionContext, not the history state.

jingham added inline comments.Jun 3 2022, 11:29 AM
lldb/source/Commands/CommandObjectRegexCommand.cpp
73–75

Or rather, I think it was obsoleted a while ago. What it's really explaining is why you don't need to call the version of HandleCommand that takes an override_context. I think that was controlled by a bool at some point in the past. I'll update the comment.

jingham updated this revision to Diff 434082.Jun 3 2022, 11:32 AM

Fix a comment that hadn't been correct for a while...