llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-lldb Author: Dave Lee (kastiglione) <details> <summary>Changes</summary> --- Full diff: https://github.com/llvm/llvm-project/pull/85152.diff 2 Files Affected: - (modified) lldb/source/Commands/CommandObjectDWIMPrint.cpp (+10-2) - (modified) lldb/test/API/commands/dwim-print/TestDWIMPrint.py (+12) ``````````diff diff --git a/lldb/source/Commands/CommandObjectDWIMPrint.cpp b/lldb/source/Commands/CommandObjectDWIMPrint.cpp index b183cb423111fb..5c043dfd101be6 100644 --- a/lldb/source/Commands/CommandObjectDWIMPrint.cpp +++ b/lldb/source/Commands/CommandObjectDWIMPrint.cpp @@ -170,6 +170,14 @@ void CommandObjectDWIMPrint::DoExecute(StringRef command, ExpressionResults expr_result = target.EvaluateExpression( expr, exe_scope, valobj_sp, eval_options, &fixed_expression); + auto persistent_name = valobj_sp->GetName(); + // EvaluateExpression doesn't generate a new persistent result (`$0`) when + // the expression is already just a persistent variable (`$var`). Instead, + // the same persistent variable is reused. Take note of when a persistent + // result is created, to prevent unintentional deletion of a user's + // persistent variable. + bool did_persist_result = persistent_name != expr; + // Only mention Fix-Its if the expression evaluator applied them. // Compiler errors refer to the final expression after applying Fix-It(s). if (!fixed_expression.empty() && target.GetEnableNotifyAboutFixIts()) { @@ -199,9 +207,9 @@ void CommandObjectDWIMPrint::DoExecute(StringRef command, } } - if (suppress_result) + if (did_persist_result && suppress_result) if (auto result_var_sp = - target.GetPersistentVariable(valobj_sp->GetName())) { + target.GetPersistentVariable(persistent_name)) { auto language = valobj_sp->GetPreferredDisplayLanguage(); if (auto *persistent_state = target.GetPersistentExpressionStateForLanguage(language)) diff --git a/lldb/test/API/commands/dwim-print/TestDWIMPrint.py b/lldb/test/API/commands/dwim-print/TestDWIMPrint.py index 040632096c70e7..c650b1e3533e08 100644 --- a/lldb/test/API/commands/dwim-print/TestDWIMPrint.py +++ b/lldb/test/API/commands/dwim-print/TestDWIMPrint.py @@ -146,3 +146,15 @@ def test_void_result(self): self, "// break here", lldb.SBFileSpec("main.c") ) self.expect("dwim-print (void)15", matching=False, patterns=["(?i)error"]) + + def test_preserves_persistent_variables(self): + """Test dwim-print does not delete persistent variables.""" + self.build() + lldbutil.run_to_source_breakpoint( + self, "// break here", lldb.SBFileSpec("main.c") + ) + self.expect("dwim-print int $i = 15") + # Run the same expression twice and verify success. This ensures the + # first command does not delete the persistent variable. + for _ in range(2): + self.expect("dwim-print $i", startstr="(int) 15") `````````` </details> https://github.com/llvm/llvm-project/pull/85152 _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits