[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
Thu Mar 14 13:55:51 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:

It would be good to have EvaluateExpression tell you whether it created a result variable or not.  For instance, calling a void function produces no result.  It would be nice to know that happened directly rather than attempting to guess from the returned ValueObject.  We definitely know this...
That would definitely be a better way to do this.

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


More information about the lldb-commits mailing list