[Lldb-commits] [lldb] [lldb] Fix dwim-print to not delete non-result persistent variables (PR #85152)

via lldb-commits lldb-commits at lists.llvm.org
Wed Mar 13 18:20:00 PDT 2024


================
@@ -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;
----------------
jimingham wrote:

This seems like a really fragile way to test what you want to test, which is whether the result of the expression was a new expression result variable.  It might be better to add a "PeekNextPersistentVariableName" that just prints what the next persistent variable would be called but doesn't increment the counter, then assert that the variable you produced is NOT called that?

https://github.com/llvm/llvm-project/pull/85152


More information about the lldb-commits mailing list