Skip to content

Commit 3854963

Browse files
committed
Recommit [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`. Updates: To recommit this, both TestPersistentResult.py and TestPAlias.py needed to be updated, as well as the changes in D146230. Differential Revision: https://reviews.llvm.org/D145609
1 parent c819257 commit 3854963

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
@@ -71,6 +71,10 @@ bool CommandObjectDWIMPrint::DoExecute(StringRef command,
7171
return false;
7272
}
7373

74+
// If the user has not specified, default to disabling persistent results.
75+
if (m_expr_options.suppress_persistent_result == eLazyBoolCalculate)
76+
m_expr_options.suppress_persistent_result = eLazyBoolYes;
77+
7478
auto verbosity = GetDebugger().GetDWIMPrintVerbosity();
7579

7680
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
@@ -151,7 +151,7 @@ Status CommandObjectExpression::CommandOptions::SetOptionValue(
151151
bool persist_result =
152152
OptionArgParser::ToBoolean(option_arg, true, &success);
153153
if (success)
154-
suppress_persistent_result = !persist_result;
154+
suppress_persistent_result = !persist_result ? eLazyBoolYes : eLazyBoolNo;
155155
else
156156
error.SetErrorStringWithFormat(
157157
"could not convert \"%s\" to a boolean value.",
@@ -187,7 +187,7 @@ void CommandObjectExpression::CommandOptions::OptionParsingStarting(
187187
auto_apply_fixits = eLazyBoolCalculate;
188188
top_level = false;
189189
allow_jit = true;
190-
suppress_persistent_result = false;
190+
suppress_persistent_result = eLazyBoolCalculate;
191191
}
192192

193193
llvm::ArrayRef<OptionDefinition>
@@ -202,8 +202,9 @@ CommandObjectExpression::CommandOptions::GetEvaluateExpressionOptions(
202202
options.SetCoerceToId(display_opts.use_objc);
203203
// Explicitly disabling persistent results takes precedence over the
204204
// m_verbosity/use_objc logic.
205-
if (suppress_persistent_result)
206-
options.SetSuppressPersistentResult(true);
205+
if (suppress_persistent_result != eLazyBoolCalculate)
206+
options.SetSuppressPersistentResult(suppress_persistent_result ==
207+
eLazyBoolYes);
207208
else if (m_verbosity == eLanguageRuntimeDescriptionDisplayVerbosityCompact)
208209
options.SetSuppressPersistentResult(display_opts.use_objc);
209210
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
};
5858

5959
CommandObjectExpression(CommandInterpreter &interpreter);

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)