This is an archive of the discontinued LLVM Phabricator instance.

[lldb] Make repeat commands work for regex commands
ClosedPublic

Authored by kastiglione on Feb 9 2023, 5:30 PM.

Details

Summary

Fix logic for repeat commands, so that regex commands (specificially bt) are
given the opportunity to provide a repeat command.

rdar://104562616

Diff Detail

Event Timeline

kastiglione created this revision.Feb 9 2023, 5:30 PM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 9 2023, 5:30 PM
kastiglione requested review of this revision.Feb 9 2023, 5:30 PM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 9 2023, 5:30 PM
jingham requested changes to this revision.Feb 23 2023, 12:29 PM

This change didn't immediately make sense to me, which means it's a bit tricky and tricky changes should get comments or they will confuse us later on. Plus, I wasn't sure how it worked, so I'm looking forward to reading the comment as part of the review...

lldb/source/Interpreter/CommandInterpreter.cpp
2005

You at least need to fix this comment, since you aren't checking empty_command anymore.

It would also be good to explain the logic here, since I'm not entirely sure why this patch fixes the problem. It should just mean that we are setting the "previous repeat command" twice, once above and once here, in the case where we didn't set "empty_command", so it's not clear why that helps.

I also think it's wrong to set a repeat command when add_to_history is false. That generally happens if some code, like a breakpoint command, uses HandleCommand, i.e. that's a command the user didn't directly execute. So it doesn't make sense that that non-user command should set the user repeat command.

This revision now requires changes to proceed.Feb 23 2023, 12:29 PM

Introduce new allow_repeat_command parameter

kastiglione added inline comments.Mar 7 2023, 1:19 PM
lldb/source/Interpreter/CommandInterpreter.cpp
2005

I've updated the logic here, keeping add_to_history || empty_command and adding a third check, which is the caller can specific an argument for allow_repeat_command. This let's CommandObjectRegexCommand opt-in to the repeat behavior without changing the semantics of add_to_history.

So the problem is that regex commands don't want to add the resolved command to the history, and so they need to force the creation of the repeat command even though they aren't adding to the history. But allow_repeat_command is a misleading name for that. It makes is sound like if I don't pass that flag I won't get a repeat command. force_repeat_command would be a better name - you aren't allowing this you're requiring it... And some explanation of why it's necessary would help make this patch understandable.

But allow_repeat_command is a misleading name for that. It makes is sound like if I don't pass that flag I won't get a repeat command. force_repeat_command would be a better name

I agree. I did have some loose thoughts matching this, when writing it, yet somehow ended up with allow_.

Rename variable to force_repeat_command and add comment block

jingham accepted this revision.Mar 8 2023, 3:57 PM

LGTM

This revision is now accepted and ready to land.Mar 8 2023, 3:57 PM

thanks for the feedback

This revision was automatically updated to reflect the committed changes.