[lldb] Make persisting result variables configurable
authorDave Lee <davelee.com@gmail.com>
Thu, 16 Feb 2023 23:39:09 +0000 (15:39 -0800)
committerDave Lee <davelee.com@gmail.com>
Sat, 18 Feb 2023 01:50:43 +0000 (17:50 -0800)
commit63c77bf71d80b24df377fc45c80bfa1904ee849e
tree6673480f178c18dcc743b1f61183a8eead4724a8
parent920b46e108b23454e6827ed0fa5e0a69fcb4a6e6
[lldb] Make persisting result variables configurable

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.

Differential Revision: https://reviews.llvm.org/D144230
lldb/source/Commands/CommandObjectDWIMPrint.cpp
lldb/source/Commands/CommandObjectExpression.cpp
lldb/source/Commands/CommandObjectExpression.h
lldb/source/Commands/Options.td
lldb/source/DataFormatters/ValueObjectPrinter.cpp
lldb/test/API/commands/dwim-print/TestDWIMPrint.py
lldb/test/API/commands/expression/persistent_result/Makefile [new file with mode: 0644]
lldb/test/API/commands/expression/persistent_result/TestPersistentResult.py [new file with mode: 0644]
lldb/test/API/commands/expression/persistent_result/main.c [new file with mode: 0644]