|
10 | 10 |
|
11 | 11 | #include "CommandObjectExpression.h"
|
12 | 12 | #include "lldb/Core/Debugger.h"
|
| 13 | +#include "lldb/Expression/ExpressionVariable.h" |
13 | 14 | #include "lldb/Expression/REPL.h"
|
14 | 15 | #include "lldb/Expression/UserExpression.h"
|
15 | 16 | #include "lldb/Host/OptionParser.h"
|
|
21 | 22 | #include "lldb/Target/Process.h"
|
22 | 23 | #include "lldb/Target/StackFrame.h"
|
23 | 24 | #include "lldb/Target/Target.h"
|
| 25 | +#include "lldb/lldb-enumerations.h" |
24 | 26 | #include "lldb/lldb-private-enumerations.h"
|
25 | 27 |
|
26 | 28 | // BEGIN SWIFT
|
@@ -218,13 +220,6 @@ CommandObjectExpression::CommandOptions::GetEvaluateExpressionOptions(
|
218 | 220 | const Target &target, const OptionGroupValueObjectDisplay &display_opts) {
|
219 | 221 | EvaluateExpressionOptions options;
|
220 | 222 | options.SetCoerceToId(display_opts.use_objc);
|
221 |
| - // Explicitly disabling persistent results takes precedence over the |
222 |
| - // m_verbosity/use_objc logic. |
223 |
| - if (suppress_persistent_result != eLazyBoolCalculate) |
224 |
| - options.SetSuppressPersistentResult(suppress_persistent_result == |
225 |
| - eLazyBoolYes); |
226 |
| - else if (m_verbosity == eLanguageRuntimeDescriptionDisplayVerbosityCompact) |
227 |
| - options.SetSuppressPersistentResult(display_opts.use_objc); |
228 | 223 | options.SetUnwindOnError(unwind_on_error);
|
229 | 224 | options.SetIgnoreBreakpoints(ignore_breakpoints);
|
230 | 225 | options.SetKeepInMemory(true);
|
@@ -272,6 +267,17 @@ CommandObjectExpression::CommandOptions::GetEvaluateExpressionOptions(
|
272 | 267 | return options;
|
273 | 268 | }
|
274 | 269 |
|
| 270 | +bool CommandObjectExpression::CommandOptions::ShouldSuppressResult( |
| 271 | + const OptionGroupValueObjectDisplay &display_opts) const { |
| 272 | + // Explicitly disabling persistent results takes precedence over the |
| 273 | + // m_verbosity/use_objc logic. |
| 274 | + if (suppress_persistent_result != eLazyBoolCalculate) |
| 275 | + return suppress_persistent_result == eLazyBoolYes; |
| 276 | + |
| 277 | + return display_opts.use_objc && |
| 278 | + m_verbosity == eLanguageRuntimeDescriptionDisplayVerbosityCompact; |
| 279 | +} |
| 280 | + |
275 | 281 | CommandObjectExpression::CommandObjectExpression(
|
276 | 282 | CommandInterpreter &interpreter)
|
277 | 283 | : CommandObjectRaw(interpreter, "expression",
|
@@ -456,8 +462,12 @@ bool CommandObjectExpression::EvaluateExpression(llvm::StringRef expr,
|
456 | 462 | return false;
|
457 | 463 | }
|
458 | 464 |
|
459 |
| - const EvaluateExpressionOptions eval_options = |
| 465 | + EvaluateExpressionOptions eval_options = |
460 | 466 | m_command_options.GetEvaluateExpressionOptions(target, m_varobj_options);
|
| 467 | + // This command manually removes the result variable, make sure expression |
| 468 | + // evaluation doesn't do it first. |
| 469 | + eval_options.SetSuppressPersistentResult(false); |
| 470 | + |
461 | 471 | ExpressionResults success = target.EvaluateExpression(
|
462 | 472 | expr, frame, result_valobj_sp, eval_options, &m_fixed_expression);
|
463 | 473 |
|
@@ -486,14 +496,25 @@ bool CommandObjectExpression::EvaluateExpression(llvm::StringRef expr,
|
486 | 496 | }
|
487 | 497 | }
|
488 | 498 |
|
| 499 | + bool suppress_result = |
| 500 | + m_command_options.ShouldSuppressResult(m_varobj_options); |
| 501 | + |
489 | 502 | DumpValueObjectOptions options(m_varobj_options.GetAsDumpOptions(
|
490 | 503 | m_command_options.m_verbosity, format));
|
491 |
| - options.SetHideRootName(eval_options.GetSuppressPersistentResult()); |
| 504 | + options.SetHideRootName(suppress_result); |
492 | 505 | options.SetVariableFormatDisplayLanguage(
|
493 | 506 | result_valobj_sp->GetPreferredDisplayLanguage());
|
494 | 507 |
|
495 | 508 | result_valobj_sp->Dump(output_stream, options);
|
496 | 509 |
|
| 510 | + if (suppress_result) |
| 511 | + if (auto result_var_sp = |
| 512 | + target.GetPersistentVariable(result_valobj_sp->GetName())) { |
| 513 | + auto language = result_valobj_sp->GetPreferredDisplayLanguage(); |
| 514 | + if (auto *persistent_state = |
| 515 | + target.GetPersistentExpressionStateForLanguage(language)) |
| 516 | + persistent_state->RemovePersistentVariable(result_var_sp); |
| 517 | + } |
497 | 518 | result.SetStatus(eReturnStatusSuccessFinishResult);
|
498 | 519 | }
|
499 | 520 | } else {
|
|
0 commit comments