Skip to content

Commit b4f5ea3

Browse files
committed
[lldb] Change dwim-print to default to disabled persistent results
Change `dwim-print` to now disable persistent results by default, unless requested by the user with the `--persistent-result` flag. Ex: ``` (lldb) dwim-print 1 + 1 (int) 2 (lldb) dwim-print --persistent-result on -- 1 + 1 (int) $0 = 2 ``` Users who wish to enable persistent results can make and use an alias that includes `--persistent-result on`. Differential Revision: https://reviews.llvm.org/D145609 (cherry picked from commit 3854963)
1 parent c1b4d2d commit b4f5ea3

File tree

6 files changed

+28
-28
lines changed

6 files changed

+28
-28
lines changed

lldb/source/Commands/CommandObjectDWIMPrint.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ bool CommandObjectDWIMPrint::DoExecute(StringRef command,
7575
return false;
7676
}
7777

78+
// If the user has not specified, default to disabling persistent results.
79+
if (m_expr_options.suppress_persistent_result == eLazyBoolCalculate)
80+
m_expr_options.suppress_persistent_result = eLazyBoolYes;
81+
7882
auto verbosity = GetDebugger().GetDWIMPrintVerbosity();
7983

8084
Target *target_ptr = m_exe_ctx.GetTargetPtr();

lldb/source/Commands/CommandObjectExpression.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ Status CommandObjectExpression::CommandOptions::SetOptionValue(
150150
bool persist_result =
151151
OptionArgParser::ToBoolean(option_arg, true, &success);
152152
if (success)
153-
suppress_persistent_result = !persist_result;
153+
suppress_persistent_result = !persist_result ? eLazyBoolYes : eLazyBoolNo;
154154
else
155155
error.SetErrorStringWithFormat(
156156
"could not convert \"%s\" to a boolean value.",
@@ -197,7 +197,7 @@ void CommandObjectExpression::CommandOptions::OptionParsingStarting(
197197
auto_apply_fixits = eLazyBoolCalculate;
198198
top_level = false;
199199
allow_jit = true;
200-
suppress_persistent_result = false;
200+
suppress_persistent_result = eLazyBoolCalculate;
201201
// BEGIN SWIFT
202202
bind_generic_types = eBindAuto;
203203
// END SWIFT
@@ -215,8 +215,9 @@ CommandObjectExpression::CommandOptions::GetEvaluateExpressionOptions(
215215
options.SetCoerceToId(display_opts.use_objc);
216216
// Explicitly disabling persistent results takes precedence over the
217217
// m_verbosity/use_objc logic.
218-
if (suppress_persistent_result)
219-
options.SetSuppressPersistentResult(true);
218+
if (suppress_persistent_result != eLazyBoolCalculate)
219+
options.SetSuppressPersistentResult(suppress_persistent_result ==
220+
eLazyBoolYes);
220221
else if (m_verbosity == eLanguageRuntimeDescriptionDisplayVerbosityCompact)
221222
options.SetSuppressPersistentResult(display_opts.use_objc);
222223
options.SetUnwindOnError(unwind_on_error);

lldb/source/Commands/CommandObjectExpression.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class CommandObjectExpression : public CommandObjectRaw,
5353
lldb::LanguageType language;
5454
LanguageRuntimeDescriptionDisplayVerbosity m_verbosity;
5555
LazyBool auto_apply_fixits;
56-
bool suppress_persistent_result;
56+
LazyBool suppress_persistent_result;
5757
// BEGIN SWIFT
5858
lldb::BindGenericTypes bind_generic_types;
5959
// END SWIFT

lldb/test/API/commands/dwim-print/TestDWIMPrint.py

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,16 @@ def _run_cmd(self, cmd: str) -> str:
1616
self.ci.HandleCommand(cmd, result)
1717
return result.GetOutput().rstrip()
1818

19-
VAR_IDENT_RAW = r"(?:\$\d+|\w+) = "
20-
VAR_IDENT = re.compile(VAR_IDENT_RAW)
19+
VAR_IDENT = re.compile(r"(?:\$\d+|\w+) = ")
2120

22-
def _mask_persistent_var(self, string: str) -> str:
21+
def _strip_result_var(self, string: str) -> str:
2322
"""
24-
Replace persistent result variables (ex '$0', '$1', etc) with a regex
25-
that matches any persistent result (r'\$\d+'). The returned string can
26-
be matched against other `expression` results.
23+
Strip (persistent) result variables (ex '$0 = ', or 'someVar = ', etc).
24+
25+
This allows for using the output of `expression`/`frame variable`, to
26+
compare it to `dwim-print` output, which disables result variables.
2727
"""
28-
before, after = self.VAR_IDENT.split(string, maxsplit=1)
29-
# Support either a frame variable (\w+) or a persistent result (\$\d+).
30-
return re.escape(before) + self.VAR_IDENT_RAW + re.escape(after)
28+
return self.VAR_IDENT.subn("", string, 1)[0]
3129

3230
def _expect_cmd(
3331
self,
@@ -46,19 +44,16 @@ def _expect_cmd(
4644
if actual_cmd == "frame variable":
4745
resolved_cmd = resolved_cmd.replace(" -- ", " ", 1)
4846

49-
expected_output = self._run_cmd(resolved_cmd)
47+
resolved_cmd_output = self._run_cmd(resolved_cmd)
48+
dwim_cmd_output = self._strip_result_var(resolved_cmd_output)
5049

5150
# Verify dwim-print chose the expected command.
5251
self.runCmd("settings set dwim-print-verbosity full")
53-
substrs = [f"note: ran `{resolved_cmd}`"]
54-
patterns = []
55-
56-
if self.VAR_IDENT.search(expected_output):
57-
patterns.append(self._mask_persistent_var(expected_output))
58-
else:
59-
substrs.append(expected_output)
6052

61-
self.expect(dwim_cmd, substrs=substrs, patterns=patterns)
53+
self.expect(dwim_cmd, substrs=[
54+
f"note: ran `{resolved_cmd}`",
55+
dwim_cmd_output,
56+
])
6257

6358
def test_variables(self):
6459
"""Test dwim-print with variables."""

lldb/test/API/commands/expression/persistent_result/TestPersistentResult.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def test_expression_persists_result(self):
3131
self.expect("expression i", substrs=["(int) $0 = 30"])
3232
self.expect("expression $0", substrs=["(int) $0 = 30"])
3333

34-
def test_p_persists_result(self):
35-
"""Test `p` does persist a result variable."""
36-
self.expect("p i", substrs=["(int) $0 = 30"])
37-
self.expect("p $0", substrs=["(int) $0 = 30"])
34+
def test_p_does_not_persist_results(self):
35+
"""Test `p` does not persist a result variable."""
36+
self.expect("p i", startstr="(int) 30")
37+
self.expect("p $0", error=True)

lldb/test/API/functionalities/alias/TestPAlias.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ class TestCase(TestBase):
77
def test(self):
88
self.build()
99
lldbutil.run_to_source_breakpoint(self, "return", lldb.SBFileSpec("main.c"))
10-
self.expect("p -g", substrs=["$0 = -"])
10+
self.expect("p -g", startstr="(int) -41")
1111
self.expect("p -i0 -g", error=True)

0 commit comments

Comments
 (0)