Files
clang-p2996/lldb/test/API/commands/expression/persistent_result/TestPersistentResult.py
Dave Lee 63c77bf71d [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
2023-02-17 17:50:43 -08:00

38 lines
1.5 KiB
Python

"""
Test controlling `expression` result variables are persistent.
"""
import lldb
from lldbsuite.test.lldbtest import *
from lldbsuite.test.decorators import *
from lldbsuite.test import lldbutil
class TestCase(TestBase):
def setUp(self):
TestBase.setUp(self)
self.build()
lldbutil.run_to_source_breakpoint(self, "break here", lldb.SBFileSpec("main.c"))
def test_enable_persistent_result(self):
"""Test explicitly enabling result variables persistence."""
self.expect("expression --persistent-result on -- i", substrs=["(int) $0 = 30"])
# Verify the lifetime of $0 extends beyond the `expression` it was created in.
self.expect("expression $0", substrs=["(int) $0 = 30"])
def test_disable_persistent_result(self):
"""Test explicitly disabling persistent result variables."""
self.expect("expression --persistent-result off -- i", substrs=["(int) 30"])
# Verify a persistent result was not silently created.
self.expect("expression $0", error=True)
def test_expression_persists_result(self):
"""Test `expression`'s default behavior is to persist a result variable."""
self.expect("expression i", substrs=["(int) $0 = 30"])
self.expect("expression $0", substrs=["(int) $0 = 30"])
def test_p_persists_result(self):
"""Test `p` does persist a result variable."""
self.expect("p i", substrs=["(int) $0 = 30"])
self.expect("p $0", substrs=["(int) $0 = 30"])