34#define LLDB_OPTIONS_expression
35#include "CommandOptions.inc"
38 uint32_t option_idx, llvm::StringRef option_arg,
42 const int short_option =
GetDefinitions()[option_idx].short_option;
44 switch (short_option) {
49 sstr.
Printf(
"unknown language type: '%s' for expression. "
50 "List of supported languages:\n",
51 option_arg.str().c_str());
64 "invalid all-threads value setting: \"%s\"",
65 option_arg.str().c_str());
77 "could not convert \"%s\" to a boolean value.",
78 option_arg.str().c_str());
89 "could not convert \"%s\" to a boolean value.",
90 option_arg.str().c_str());
95 if (option_arg.getAsInteger(0,
timeout)) {
98 "invalid timeout setting \"%s\"", option_arg.str().c_str());
109 "could not convert \"%s\" to a boolean value.",
110 option_arg.str().c_str());
115 if (option_arg.empty()) {
122 if (!
error.Success())
124 "unrecognized value for description-verbosity '%s'",
125 option_arg.str().c_str());
145 "could not convert \"%s\" to a boolean value.",
146 option_arg.str().c_str());
152 bool persist_result =
158 "could not convert \"%s\" to a boolean value.",
159 option_arg.str().c_str());
164 llvm_unreachable(
"Unimplemented option");
175 ignore_breakpoints = process_sp->GetIgnoreBreakpointsInExpressions();
176 unwind_on_error = process_sp->GetUnwindOnErrorInExpressions();
178 ignore_breakpoints =
true;
179 unwind_on_error =
true;
183 try_all_threads =
true;
194llvm::ArrayRef<OptionDefinition>
196 return llvm::ArrayRef(g_expression_options);
215 bool auto_apply_fixits;
219 auto_apply_fixits = this->auto_apply_fixits ==
eLazyBoolYes;
229 if (!ignore_breakpoints || !unwind_on_error)
233 options.
SetTimeout(std::chrono::microseconds(timeout));
253 "Evaluate an expression on the current "
254 "thread. Displays any returned value "
255 "with LLDB's default formatting.",
257 eCommandProcessMustBePaused | eCommandTryTargetAPILock),
265Single and multi-line expressions:
268 " The expression provided on the command line must be a complete expression \
269with no newlines. To evaluate a multi-line expression, \
270hit a return after an empty expression, and lldb will enter the multi-line expression editor. \
271Hit return on an empty line to end the multi-line expression."
278 " If the expression can be evaluated statically (without running code) then it will be. \
279Otherwise, by default the expression will run on the current thread with a short timeout: \
280currently .25 seconds. If it doesn't return in that time, the evaluation will be interrupted \
281and resumed with all threads running. You can use the -a option to disable retrying on all \
282threads. You can use the -t option to set a shorter timeout."
285User defined variables:
288 " You can define your own variables for convenience or to be used in subsequent expressions. \
289You define them the same way you would define variables in C. If the first character of \
290your user defined variable is a $, then the variable's value will be available in future \
291expressions, otherwise it will just be available in the current expression."
294Continuing evaluation after a breakpoint:
297 " If the \"-i false\" option is used, and execution is interrupted by a breakpoint hit, once \
298you are done with your investigation, you can either remove the expression execution frames \
299from the stack with \"thread return -x\" or if you are still interested in the expression result \
300you can issue the \"continue\" command and the expression evaluation will complete and the \
301expression result will be available using the \"thread.completed-expression\" key in the thread \
308 expr my_struct->a = my_array[3]
309 expr -f bin -- (index * 8) + 5
310 expr unsigned int $foo = 5
311 expr char c[] = \"foo\"; c[0])");
342 if (exe_ctx.GetFramePtr() ==
nullptr)
345 Target *exe_target = exe_ctx.GetTargetPtr();
356 const std::size_t original_code_size = code.size();
359 code = llvm::getToken(code).second.ltrim();
361 code = args.GetRawPart();
364 assert(original_code_size >= code.size());
365 std::size_t raw_start = original_code_size - code.size();
370 if (cursor_pos < raw_start)
374 assert(cursor_pos >= raw_start);
375 cursor_pos -= raw_start;
377 auto language = exe_ctx.GetFrameRef().GetLanguage();
382 options,
nullptr,
error));
386 expr->Complete(exe_ctx, request, cursor_pos);
393 if (!type.IsPointerType(&pointee))
408 Target *exe_target = exe_ctx.GetTargetPtr();
416 "Can't disable JIT compilation for top-level expressions.\n");
432 error_stream <<
" Evaluated this expression after applying Fix-It(s):\n";
436 if (result_valobj_sp) {
439 if (result_valobj_sp->GetError().Success()) {
442 result_valobj_sp->SetFormat(format);
448 "expression cannot be used with --element-count %s\n",
449 error.AsCString(
""));
454 bool suppress_result =
459 options.SetHideRootName(suppress_result);
460 options.SetVariableFormatDisplayLanguage(
461 result_valobj_sp->GetPreferredDisplayLanguage());
463 if (llvm::Error
error =
464 result_valobj_sp->Dump(output_stream, options)) {
470 if (
auto result_var_sp =
472 auto language = result_valobj_sp->GetPreferredDisplayLanguage();
473 if (
auto *persistent_state =
475 persistent_state->RemovePersistentVariable(result_var_sp);
480 if (result_valobj_sp->GetError().GetError() ==
489 result.
SetError(result_valobj_sp->GetError().ToError());
493 error_stream.
Printf(
"error: unknown error\n");
521 const size_t num_lines = lines.
GetSize();
522 if (num_lines > 0 && lines[num_lines - 1].empty()) {
537 const bool multiple_lines =
true;
543 multiple_lines, color_prompt,
547 StreamFileSP output_sp = io_handler_sp->GetOutputStreamFileSP();
549 output_sp->PutCString(
550 "Enter expressions, then terminate with an empty line to evaluate:\n");
564 command_options.
debug =
false;
571 if (command_options.
timeout > 0)
585 if (command.empty()) {
591 llvm::StringRef expr = args.GetRawPart();
593 if (args.HasArgs()) {
616 bool initialize =
false;
625 if (repl_error.
Fail()) {
626 result.
SetError(std::move(repl_error));
633 repl_sp->SetEvaluateOptions(
639 IOHandlerSP io_handler_sp(repl_sp->GetIOHandler());
640 io_handler_sp->SetIsDone(
false);
644 "Couldn't create a REPL for %s",
646 result.
SetError(std::move(repl_error));
652 else if (expr.empty()) {
660 std::optional<uint16_t> indent;
662 if (pos != llvm::StringRef::npos)
675 std::string fixed_command(
"expression ");
676 if (args.HasArgs()) {
678 fixed_command.append(std::string(args.GetArgStringWithDelimiter()));
static lldb_private::Status CanBeUsedForElementCountPrinting(ValueObject &valobj)
static EvaluateExpressionOptions GetExprOptions(ExecutionContext &ctx, CommandObjectExpression::CommandOptions command_options)
static llvm::raw_ostream & error(Stream &strm)
void AppendString(llvm::StringRef str, bool reject_if_dupe=true)
ExecutionContext GetExecutionContext() const
lldb::IOHandlerSP GetIOHandler(bool force_create=false, CommandInterpreterRunOptions *options=nullptr)
CommandHistory & GetCommandHistory()
void OptionParsingStarting(ExecutionContext *execution_context) override
llvm::ArrayRef< OptionDefinition > GetDefinitions() override
LazyBool auto_apply_fixits
lldb::LanguageType language
bool ShouldSuppressResult(const OptionGroupValueObjectDisplay &display_opts) const
~CommandOptions() override
LanguageRuntimeDescriptionDisplayVerbosity m_verbosity
LazyBool suppress_persistent_result
Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_value, ExecutionContext *execution_context) override
EvaluateExpressionOptions GetEvaluateExpressionOptions(const Target &target, const OptionGroupValueObjectDisplay &display_opts)
Return the appropriate expression options used for evaluating the expression in the given target.
Options * GetOptions() override
CommandOptions m_command_options
OptionGroupOptions m_option_group
CommandObjectExpression(CommandInterpreter &interpreter)
bool IOHandlerIsInputComplete(IOHandler &io_handler, StringList &lines) override
Called to determine whether typing enter after the last line in lines should end input.
OptionGroupValueObjectDisplay m_varobj_options
void HandleCompletion(CompletionRequest &request) override
This default version handles calling option argument completions and then calls HandleArgumentComplet...
bool EvaluateExpression(llvm::StringRef expr, Stream &output_stream, Stream &error_stream, CommandReturnObject &result)
Evaluates the given expression.
void GetMultilineExpression()
uint32_t m_expr_line_count
std::string m_fixed_expression
OptionGroupBoolean m_repl_option
void IOHandlerInputComplete(IOHandler &io_handler, std::string &line) override
Called when a line or lines have been retrieved.
~CommandObjectExpression() override
OptionGroupFormat m_format_options
void DoExecute(llvm::StringRef command, CommandReturnObject &result) override
virtual void SetHelpLong(llvm::StringRef str)
void AddSimpleArgumentList(lldb::CommandArgumentType arg_type, ArgumentRepetitionType repetition_type=eArgRepeatPlain)
bool ParseOptionsAndNotify(Args &args, CommandReturnObject &result, OptionGroupOptions &group_options, ExecutionContext &exe_ctx)
Target & GetDummyTarget()
CommandInterpreter & GetCommandInterpreter()
CommandInterpreter & m_interpreter
std::string m_original_command
void void AppendError(llvm::StringRef in_string)
Stream & GetErrorStream()
void SetStatus(lldb::ReturnStatus status)
std::string GetErrorString(bool with_diagnostics=true)
Return the errors as a string.
void SetError(Status error)
void AppendErrorWithFormat(const char *format,...) __attribute__((format(printf
void SetDiagnosticIndent(std::optional< uint16_t > indent)
Stream & GetOutputStream()
Generic representation of a type in a programming language.
"lldb/Utility/ArgCompletionRequest.h"
unsigned GetRawCursorPos() const
llvm::StringRef GetRawLineWithUnusedSuffix() const
Returns the full raw user input used to create this CompletionRequest.
A class to manage flag bits.
void RunIOHandlerAsync(const lldb::IOHandlerSP &reader_sp, bool cancel_top_handler=true)
Run the given IO handler and return immediately.
bool CheckTopIOHandlerTypes(IOHandler::Type top_type, IOHandler::Type second_top_type)
void SetUnwindOnError(bool unwind=false)
void SetExecutionPolicy(ExecutionPolicy policy=eExecutionPolicyAlways)
void SetKeepInMemory(bool keep=true)
void SetCoerceToId(bool coerce=true)
void SetLanguage(lldb::LanguageType language_type)
void SetTryAllThreads(bool try_others=true)
void SetRetriesWithFixIts(uint64_t number_of_retries)
void SetTimeout(const Timeout< std::micro > &timeout)
static constexpr ExecutionPolicy default_execution_policy
void SetAutoApplyFixIts(bool b)
void SetSuppressPersistentResult(bool b)
void SetIgnoreBreakpoints(bool ignore=false)
void SetUseDynamic(lldb::DynamicValueType dynamic=lldb::eDynamicCanRunTarget)
void SetGenerateDebugInfo(bool b)
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
const lldb::ProcessSP & GetProcessSP() const
Get accessor to get the process shared pointer.
Encapsulates a single expression for use in lldb.
A delegate class for use with IOHandler subclasses.
lldb::StreamFileSP GetErrorStreamFileSP()
lldb::StreamFileSP GetOutputStreamFileSP()
static void PrintSupportedLanguagesForExpressions(Stream &s, llvm::StringRef prefix, llvm::StringRef suffix)
Prints to the specified stream 's' each language type that the current target supports for expression...
static const char * GetNameForLanguageType(lldb::LanguageType language)
static lldb::LanguageType GetLanguageTypeFromString(const char *string)=delete
OptionValueBoolean & GetOptionValue()
void Append(OptionGroup *group)
Append options from a OptionGroup class.
DumpValueObjectOptions GetAsDumpOptions(LanguageRuntimeDescriptionDisplayVerbosity lang_descr_verbosity=eLanguageRuntimeDescriptionDisplayVerbosityFull, lldb::Format format=lldb::eFormatDefault, lldb::TypeSummaryImplSP summary_sp=lldb::TypeSummaryImplSP())
lldb::DynamicValueType use_dynamic
bool GetCurrentValue() const
A pair of an option list with a 'raw' string as a suffix.
A command line option parsing protocol class.
void NotifyOptionParsingStarting(ExecutionContext *execution_context)
This base class provides an interface to stack frames.
static Status FromErrorStringWithFormat(const char *format,...) __attribute__((format(printf
static Status FromErrorString(const char *str)
bool Fail() const
Test for error condition.
llvm::StringRef GetString() const
A stream class that can stream formatted output to a file.
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
bool GetEnableNotifyAboutFixIts() const
uint64_t GetNumberOfRetriesWithFixits() const
bool GetEnableAutoApplyFixIts() const
PersistentExpressionState * GetPersistentExpressionStateForLanguage(lldb::LanguageType language)
lldb::ExpressionVariableSP GetPersistentVariable(ConstString name)
lldb::REPLSP GetREPL(Status &err, lldb::LanguageType language, const char *repl_options, bool can_create)
UserExpression * GetUserExpressionForLanguage(llvm::StringRef expr, llvm::StringRef prefix, SourceLanguage language, Expression::ResultType desired_type, const EvaluateExpressionOptions &options, ValueObject *ctx_obj, Status &error)
lldb::ExpressionResults EvaluateExpression(llvm::StringRef expression, ExecutionContextScope *exe_scope, lldb::ValueObjectSP &result_valobj_sp, const EvaluateExpressionOptions &options=EvaluateExpressionOptions(), std::string *fixed_expression=nullptr, ValueObject *ctx_obj=nullptr)
static const Status::ValueType kNoResult
ValueObject::GetError() returns this if there is no result from the expression.
CompilerType GetCompilerType()
A class that represents a running process on the host machine.
@ eExecutionPolicyTopLevel
const char * toString(AppleArm64ExceptionClass EC)
LanguageRuntimeDescriptionDisplayVerbosity
@ eLanguageRuntimeDescriptionDisplayVerbosityCompact
@ eLanguageRuntimeDescriptionDisplayVerbosityFull
std::shared_ptr< lldb_private::IOHandler > IOHandlerSP
std::shared_ptr< lldb_private::ValueObject > ValueObjectSP
Format
Display format definitions.
@ eFormatVoid
Do not print this.
@ eLanguageTypeUnknown
Unknown or invalid language value.
std::shared_ptr< lldb_private::UserExpression > UserExpressionSP
ExpressionResults
The results of expression evaluation.
std::shared_ptr< lldb_private::Process > ProcessSP
@ eReturnStatusSuccessFinishResult
std::shared_ptr< lldb_private::StreamFile > StreamFileSP
std::shared_ptr< lldb_private::REPL > REPLSP
static int64_t ToOptionEnum(llvm::StringRef s, const OptionEnumValues &enum_values, int32_t fail_value, Status &error)
static bool ToBoolean(llvm::StringRef s, bool fail_value, bool *success_ptr)