[lldb] Delay removal of persistent results
authorDave Lee <davelee.com@gmail.com>
Mon, 15 May 2023 21:36:17 +0000 (14:36 -0700)
committerDave Lee <davelee.com@gmail.com>
Thu, 18 May 2023 16:44:11 +0000 (09:44 -0700)
commitdb814552132d614e410118e22b22c89d35ae6062
treeca3b962cb7e7857bc5d2bdc467925b3731506bc8
parentd02d054473834091ce662073654c947b0551d61d
[lldb] Delay removal of persistent results

Follow up to "Suppress persistent result when running po" (D144044).

This change delays removal of the persistent result until after `Dump` has been called.
In doing so, the persistent result is available for the purpose of getting its object
description.

In the original change, the persistent result removal happens indirectly, by setting
`EvaluateExpressionOptions::SetSuppressPersistentResult`. In practice this has worked,
however this exposed a latent bug in swift-lldb. The subtlety, and the bug, depend on
when the persisteted result variable is removed.

When the result is removed via `SetSuppressPersistentResult`, it happens within the call
to `Target::EvaluateExpression`. That is, by the time the call returns, the persistent
result is already removed.

The issue occurs shortly thereafter, when `ValueObject::Dump` is called, it cannot make
use of the persistent result variable (instead it uses the `ValueObjectConstResult`). In
swift-lldb, this causes an additional expression evaluation to happen. It first tries an
expression that reference `$R0` etc, but that always fails because `$R0` is removed. The
fallback to this failure does work most of the time, but there's at least one bug
involving imported Clang types.

Differential Revision: https://reviews.llvm.org/D150619
lldb/source/Commands/CommandObjectDWIMPrint.cpp
lldb/source/Commands/CommandObjectExpression.cpp
lldb/source/Commands/CommandObjectExpression.h