aboutsummaryrefslogtreecommitdiff
path: root/lldb/source/Commands/CommandObjectExpression.cpp
diff options
context:
space:
mode:
authorDave Lee <davelee.com@gmail.com>2023-02-16 15:39:09 -0800
committerDave Lee <davelee.com@gmail.com>2023-02-17 17:50:43 -0800
commit63c77bf71d80b24df377fc45c80bfa1904ee849e (patch)
tree6673480f178c18dcc743b1f61183a8eead4724a8 /lldb/source/Commands/CommandObjectExpression.cpp
parent920b46e108b23454e6827ed0fa5e0a69fcb4a6e6 (diff)
downloadllvm-63c77bf71d80b24df377fc45c80bfa1904ee849e.zip
llvm-63c77bf71d80b24df377fc45c80bfa1904ee849e.tar.gz
llvm-63c77bf71d80b24df377fc45c80bfa1904ee849e.tar.bz2
[lldb] Make persisting result variables configurable
Context: The `expression` command uses artificial variables to store the expression result. This result variable is unconditionally kept around after the expression command has completed. These variables are known as persistent results. These are the variables `$0`, `$1`, etc, that are displayed when running `p` or `expression`. This change allows users to control whether result variables are persisted, by introducing a `--persistent-result` flag. This change keeps the current default behavior, persistent results are created by default. This change gives users the ability to opt-out by re-aliasing `p`. For example: ``` command unalias p command alias p expression --persistent-result false -- ``` For consistency, this flag is also adopted by `dwim-print`. Of note, if asked, `dwim-print` will create a persistent result even for frame variables. Differential Revision: https://reviews.llvm.org/D144230
Diffstat (limited to 'lldb/source/Commands/CommandObjectExpression.cpp')
-rw-r--r--lldb/source/Commands/CommandObjectExpression.cpp25
1 files changed, 22 insertions, 3 deletions
diff --git a/lldb/source/Commands/CommandObjectExpression.cpp b/lldb/source/Commands/CommandObjectExpression.cpp
index f576729..63b9236 100644
--- a/lldb/source/Commands/CommandObjectExpression.cpp
+++ b/lldb/source/Commands/CommandObjectExpression.cpp
@@ -146,6 +146,19 @@ Status CommandObjectExpression::CommandOptions::SetOptionValue(
break;
}
+ case '\x01': {
+ bool success;
+ bool persist_result =
+ OptionArgParser::ToBoolean(option_arg, true, &success);
+ if (success)
+ suppress_persistent_result = !persist_result;
+ else
+ error.SetErrorStringWithFormat(
+ "could not convert \"%s\" to a boolean value.",
+ option_arg.str().c_str());
+ break;
+ }
+
default:
llvm_unreachable("Unimplemented option");
}
@@ -174,6 +187,7 @@ void CommandObjectExpression::CommandOptions::OptionParsingStarting(
auto_apply_fixits = eLazyBoolCalculate;
top_level = false;
allow_jit = true;
+ suppress_persistent_result = false;
}
llvm::ArrayRef<OptionDefinition>
@@ -186,7 +200,11 @@ CommandObjectExpression::CommandOptions::GetEvaluateExpressionOptions(
const Target &target, const OptionGroupValueObjectDisplay &display_opts) {
EvaluateExpressionOptions options;
options.SetCoerceToId(display_opts.use_objc);
- if (m_verbosity == eLanguageRuntimeDescriptionDisplayVerbosityCompact)
+ // Explicitly disabling persistent results takes precedence over the
+ // m_verbosity/use_objc logic.
+ if (suppress_persistent_result)
+ options.SetSuppressPersistentResult(true);
+ else if (m_verbosity == eLanguageRuntimeDescriptionDisplayVerbosityCompact)
options.SetSuppressPersistentResult(display_opts.use_objc);
options.SetUnwindOnError(unwind_on_error);
options.SetIgnoreBreakpoints(ignore_breakpoints);
@@ -405,10 +423,10 @@ bool CommandObjectExpression::EvaluateExpression(llvm::StringRef expr,
return false;
}
- const EvaluateExpressionOptions options =
+ const EvaluateExpressionOptions eval_options =
m_command_options.GetEvaluateExpressionOptions(target, m_varobj_options);
ExpressionResults success = target.EvaluateExpression(
- expr, frame, result_valobj_sp, options, &m_fixed_expression);
+ expr, frame, result_valobj_sp, eval_options, &m_fixed_expression);
// We only tell you about the FixIt if we applied it. The compiler errors
// will suggest the FixIt if it parsed.
@@ -437,6 +455,7 @@ bool CommandObjectExpression::EvaluateExpression(llvm::StringRef expr,
DumpValueObjectOptions options(m_varobj_options.GetAsDumpOptions(
m_command_options.m_verbosity, format));
+ options.SetHideName(eval_options.GetSuppressPersistentResult());
options.SetVariableFormatDisplayLanguage(
result_valobj_sp->GetPreferredDisplayLanguage());