aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/lldb/source/Commands/CommandObjectExpression.cpp
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2023-09-02 21:17:18 +0000
committerDimitry Andric <dim@FreeBSD.org>2023-12-08 17:34:50 +0000
commit06c3fb2749bda94cb5201f81ffdb8fa6c3161b2e (patch)
tree62f873df87c7c675557a179e0c4c83fe9f3087bc /contrib/llvm-project/lldb/source/Commands/CommandObjectExpression.cpp
parentcf037972ea8863e2bab7461d77345367d2c1e054 (diff)
parent7fa27ce4a07f19b07799a767fc29416f3b625afb (diff)
Diffstat (limited to 'contrib/llvm-project/lldb/source/Commands/CommandObjectExpression.cpp')
-rw-r--r--contrib/llvm-project/lldb/source/Commands/CommandObjectExpression.cpp130
1 files changed, 87 insertions, 43 deletions
diff --git a/contrib/llvm-project/lldb/source/Commands/CommandObjectExpression.cpp b/contrib/llvm-project/lldb/source/Commands/CommandObjectExpression.cpp
index 9cce009f853e..e7e6e3820b99 100644
--- a/contrib/llvm-project/lldb/source/Commands/CommandObjectExpression.cpp
+++ b/contrib/llvm-project/lldb/source/Commands/CommandObjectExpression.cpp
@@ -10,6 +10,7 @@
#include "CommandObjectExpression.h"
#include "lldb/Core/Debugger.h"
+#include "lldb/Expression/ExpressionVariable.h"
#include "lldb/Expression/REPL.h"
#include "lldb/Expression/UserExpression.h"
#include "lldb/Host/OptionParser.h"
@@ -21,6 +22,8 @@
#include "lldb/Target/Process.h"
#include "lldb/Target/StackFrame.h"
#include "lldb/Target/Target.h"
+#include "lldb/lldb-enumerations.h"
+#include "lldb/lldb-private-enumerations.h"
using namespace lldb;
using namespace lldb_private;
@@ -145,6 +148,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 ? eLazyBoolYes : eLazyBoolNo;
+ else
+ error.SetErrorStringWithFormat(
+ "could not convert \"%s\" to a boolean value.",
+ option_arg.str().c_str());
+ break;
+ }
+
default:
llvm_unreachable("Unimplemented option");
}
@@ -173,6 +189,7 @@ void CommandObjectExpression::CommandOptions::OptionParsingStarting(
auto_apply_fixits = eLazyBoolCalculate;
top_level = false;
allow_jit = true;
+ suppress_persistent_result = eLazyBoolCalculate;
}
llvm::ArrayRef<OptionDefinition>
@@ -180,6 +197,57 @@ CommandObjectExpression::CommandOptions::GetDefinitions() {
return llvm::ArrayRef(g_expression_options);
}
+EvaluateExpressionOptions
+CommandObjectExpression::CommandOptions::GetEvaluateExpressionOptions(
+ const Target &target, const OptionGroupValueObjectDisplay &display_opts) {
+ EvaluateExpressionOptions options;
+ options.SetCoerceToId(display_opts.use_objc);
+ options.SetUnwindOnError(unwind_on_error);
+ options.SetIgnoreBreakpoints(ignore_breakpoints);
+ options.SetKeepInMemory(true);
+ options.SetUseDynamic(display_opts.use_dynamic);
+ options.SetTryAllThreads(try_all_threads);
+ options.SetDebug(debug);
+ options.SetLanguage(language);
+ options.SetExecutionPolicy(
+ allow_jit ? EvaluateExpressionOptions::default_execution_policy
+ : lldb_private::eExecutionPolicyNever);
+
+ bool auto_apply_fixits;
+ if (this->auto_apply_fixits == eLazyBoolCalculate)
+ auto_apply_fixits = target.GetEnableAutoApplyFixIts();
+ else
+ auto_apply_fixits = this->auto_apply_fixits == eLazyBoolYes;
+
+ options.SetAutoApplyFixIts(auto_apply_fixits);
+ options.SetRetriesWithFixIts(target.GetNumberOfRetriesWithFixits());
+
+ if (top_level)
+ options.SetExecutionPolicy(eExecutionPolicyTopLevel);
+
+ // If there is any chance we are going to stop and want to see what went
+ // wrong with our expression, we should generate debug info
+ if (!ignore_breakpoints || !unwind_on_error)
+ options.SetGenerateDebugInfo(true);
+
+ if (timeout > 0)
+ options.SetTimeout(std::chrono::microseconds(timeout));
+ else
+ options.SetTimeout(std::nullopt);
+ return options;
+}
+
+bool CommandObjectExpression::CommandOptions::ShouldSuppressResult(
+ const OptionGroupValueObjectDisplay &display_opts) const {
+ // Explicitly disabling persistent results takes precedence over the
+ // m_verbosity/use_objc logic.
+ if (suppress_persistent_result != eLazyBoolCalculate)
+ return suppress_persistent_result == eLazyBoolYes;
+
+ return display_opts.use_objc &&
+ m_verbosity == eLanguageRuntimeDescriptionDisplayVerbosityCompact;
+}
+
CommandObjectExpression::CommandObjectExpression(
CommandInterpreter &interpreter)
: CommandObjectRaw(interpreter, "expression",
@@ -342,47 +410,6 @@ CanBeUsedForElementCountPrinting(ValueObject &valobj) {
return Status();
}
-EvaluateExpressionOptions
-CommandObjectExpression::GetEvalOptions(const Target &target) {
- EvaluateExpressionOptions options;
- options.SetCoerceToId(m_varobj_options.use_objc);
- options.SetUnwindOnError(m_command_options.unwind_on_error);
- options.SetIgnoreBreakpoints(m_command_options.ignore_breakpoints);
- options.SetKeepInMemory(true);
- options.SetUseDynamic(m_varobj_options.use_dynamic);
- options.SetTryAllThreads(m_command_options.try_all_threads);
- options.SetDebug(m_command_options.debug);
- options.SetLanguage(m_command_options.language);
- options.SetExecutionPolicy(
- m_command_options.allow_jit
- ? EvaluateExpressionOptions::default_execution_policy
- : lldb_private::eExecutionPolicyNever);
-
- bool auto_apply_fixits;
- if (m_command_options.auto_apply_fixits == eLazyBoolCalculate)
- auto_apply_fixits = target.GetEnableAutoApplyFixIts();
- else
- auto_apply_fixits = m_command_options.auto_apply_fixits == eLazyBoolYes;
-
- options.SetAutoApplyFixIts(auto_apply_fixits);
- options.SetRetriesWithFixIts(target.GetNumberOfRetriesWithFixits());
-
- if (m_command_options.top_level)
- options.SetExecutionPolicy(eExecutionPolicyTopLevel);
-
- // If there is any chance we are going to stop and want to see what went
- // wrong with our expression, we should generate debug info
- if (!m_command_options.ignore_breakpoints ||
- !m_command_options.unwind_on_error)
- options.SetGenerateDebugInfo(true);
-
- if (m_command_options.timeout > 0)
- options.SetTimeout(std::chrono::microseconds(m_command_options.timeout));
- else
- options.SetTimeout(std::nullopt);
- return options;
-}
-
bool CommandObjectExpression::EvaluateExpression(llvm::StringRef expr,
Stream &output_stream,
Stream &error_stream,
@@ -403,9 +430,14 @@ bool CommandObjectExpression::EvaluateExpression(llvm::StringRef expr,
return false;
}
- const EvaluateExpressionOptions options = GetEvalOptions(target);
+ EvaluateExpressionOptions eval_options =
+ m_command_options.GetEvaluateExpressionOptions(target, m_varobj_options);
+ // This command manually removes the result variable, make sure expression
+ // evaluation doesn't do it first.
+ eval_options.SetSuppressPersistentResult(false);
+
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.
@@ -432,13 +464,25 @@ bool CommandObjectExpression::EvaluateExpression(llvm::StringRef expr,
}
}
+ bool suppress_result =
+ m_command_options.ShouldSuppressResult(m_varobj_options);
+
DumpValueObjectOptions options(m_varobj_options.GetAsDumpOptions(
m_command_options.m_verbosity, format));
+ options.SetHideRootName(suppress_result);
options.SetVariableFormatDisplayLanguage(
result_valobj_sp->GetPreferredDisplayLanguage());
result_valobj_sp->Dump(output_stream, options);
+ if (suppress_result)
+ if (auto result_var_sp =
+ target.GetPersistentVariable(result_valobj_sp->GetName())) {
+ auto language = result_valobj_sp->GetPreferredDisplayLanguage();
+ if (auto *persistent_state =
+ target.GetPersistentExpressionStateForLanguage(language))
+ persistent_state->RemovePersistentVariable(result_var_sp);
+ }
result.SetStatus(eReturnStatusSuccessFinishResult);
}
} else {