================
@@ -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;
----------------
kastiglione wrote:
I agree that it's not ideal, but I felt it was sufficient.
> what you want to test, which is whether the result of the expression was a
> new expression result variable
exactly. However I think peeking at the result variables is also not ideal.
Both my initial stab at this, and your suggestion are deducing whether a new
expression result variable was created. If I'm to change the API, I think it'd
be ideal to make the API communicate have means to communicate this explicitly.
There's another approach I considered taking. Before calling
`EvaluateExpression`, try the expression as a persistent variable and check in
the target to see if it exists, and if it does exist, use it (and avoid
`EvaluateExpression` altogether). This is similar to how expressions are first
treated as frame variables (and as @felipepiovezan has requested, we should try
`target variable` too).
https://github.com/llvm/llvm-project/pull/85152
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits