This is an archive of the discontinued LLVM Phabricator instance.

[lldb] Make persisting result variables configurable
ClosedPublic

Authored by kastiglione on Feb 16 2023, 3:56 PM.

Details

Summary

Context: The expression command uses artificial variables to store the expression
result. This result variable is unconditionally kept around after the expression command
has completed. These variables are known as persistent results. These are the variables
$0, $1, etc, that are displayed when running p or expression.

This change allows users to control whether result variables are persisted, by
introducing a --persistent-result flag.

This change keeps the current default behavior, persistent results are created by
default. This change gives users the ability to opt-out by re-aliasing p. For example:

command unalias p
command alias p expression --persistent-result false --

For consistency, this flag is also adopted by dwim-print. Of note, if asked,
dwim-print will create a persistent result even for frame variables.

Diff Detail

Event Timeline

kastiglione created this revision.Feb 16 2023, 3:56 PM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 16 2023, 3:56 PM
kastiglione requested review of this revision.Feb 16 2023, 3:56 PM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 16 2023, 3:56 PM
kastiglione retitled this revision from [lldb] Make use of persistent result variables configurable to [lldb] Make persisting result variables configurable.Feb 16 2023, 4:00 PM
aprantl added inline comments.Feb 16 2023, 7:43 PM
lldb/source/Commands/CommandObjectExpression.cpp
149

Do we expect people to actually use this flag or to just use an alias that has this turned on? If the latter, maybe we should only provide a long option, since the single-letter name space is precious?

Did you forget to git-add the test?

kastiglione added inline comments.Feb 17 2023, 8:34 AM
lldb/source/Commands/CommandObjectExpression.cpp
149

Initially I was going to have only the long option, but I reconsidered because I don't know how frequently persistent results are used by users. In the future, if/when we make the persistent results opt-in (instead of opt-out), will people want to use persistent results sporadically? If so maybe they'd want a short flag to quickly opt-in.

since the single-letter name space is precious

this is a compelling argument. I'll go with long option only to start. It's easier to add a short option later, than to remove it.

fix Makefile

Remove short option -C, leaving only --persistent-result

kastiglione edited the summary of this revision. (Show Details)Feb 17 2023, 8:43 AM
aprantl added inline comments.Feb 17 2023, 10:49 AM
lldb/source/Commands/Options.td
389

Is that the approved way of doing long options-only? What's printed in help dwim-print now?

kastiglione added inline comments.Feb 17 2023, 11:05 AM
lldb/source/Commands/Options.td
389

We don't have many long option-only flags, and those few others do it this way. If I recall, Jonas was the first to use this approach.

The relevant portion of help dwim-print (or help expression) is:

--persistent-result <boolean>

Persist expression result in a variable for subsequent use. Expression results will be
labeled with $-prefixed variables, e.g. $0, $1, etc. Defaults to true.

Improve handling of po

aprantl accepted this revision.Feb 17 2023, 12:21 PM
aprantl added inline comments.
lldb/source/Commands/Options.td
389

Okay, thanks for checking!

This revision is now accepted and ready to land.Feb 17 2023, 12:21 PM

Fix composition of --persistent-result and -O/-v

This revision was landed with ongoing or failed builds.Feb 17 2023, 5:50 PM
This revision was automatically updated to reflect the committed changes.