36#define LLDB_OPTIONS_expression
37#include "CommandOptions.inc"
40 uint32_t option_idx, llvm::StringRef option_arg,
44 const int short_option =
GetDefinitions()[option_idx].short_option;
46 switch (short_option) {
51 sstr.
Printf(
"unknown language type: '%s' for expression. "
52 "List of supported languages:\n",
53 option_arg.str().c_str());
66 "invalid all-threads value setting: \"%s\"",
67 option_arg.str().c_str());
79 "could not convert \"%s\" to a boolean value.",
80 option_arg.str().c_str());
91 "could not convert \"%s\" to a boolean value.",
92 option_arg.str().c_str());
97 if (option_arg.getAsInteger(0,
timeout)) {
100 "invalid timeout setting \"%s\"", option_arg.str().c_str());
111 "could not convert \"%s\" to a boolean value.",
112 option_arg.str().c_str());
117 if (option_arg.empty()) {
124 if (!
error.Success())
126 "unrecognized value for description-verbosity '%s'",
127 option_arg.str().c_str());
147 "could not convert \"%s\" to a boolean value.",
148 option_arg.str().c_str());
154 bool persist_result =
160 "could not convert \"%s\" to a boolean value.",
161 option_arg.str().c_str());
166 llvm_unreachable(
"Unimplemented option");
196llvm::ArrayRef<OptionDefinition>
198 return llvm::ArrayRef(g_expression_options);
255 "Evaluate an expression on the current "
256 "thread. Displays any returned value "
257 "with LLDB's default formatting.",
259 eCommandProcessMustBePaused | eCommandTryTargetAPILock),
267Single and multi-line expressions:
270 " The expression provided on the command line must be a complete expression \
271with no newlines. To evaluate a multi-line expression, \
272hit a return after an empty expression, and lldb will enter the multi-line expression editor. \
273Hit return on an empty line to end the multi-line expression."
280 " If the expression can be evaluated statically (without running code) then it will be. \
281Otherwise, by default the expression will run on the current thread with a short timeout: \
282currently .25 seconds. If it doesn't return in that time, the evaluation will be interrupted \
283and resumed with all threads running. You can use the -a option to disable retrying on all \
284threads. You can use the -t option to set a shorter timeout."
287User defined variables:
290 " You can define your own variables for convenience or to be used in subsequent expressions. \
291You define them the same way you would define variables in C. If the first character of \
292your user defined variable is a $, then the variable's value will be available in future \
293expressions, otherwise it will just be available in the current expression."
296Continuing evaluation after a breakpoint:
299 " If the \"-i false\" option is used, and execution is interrupted by a breakpoint hit, once \
300you are done with your investigation, you can either remove the expression execution frames \
301from the stack with \"thread return -x\" or if you are still interested in the expression result \
302you can issue the \"continue\" command and the expression evaluation will complete and the \
303expression result will be available using the \"thread.completed-expression\" key in the thread \
310 expr my_struct->a = my_array[3]
311 expr -f bin -- (index * 8) + 5
312 expr unsigned int $foo = 5
313 expr char c[] = \"foo\"; c[0])");
344 if (exe_ctx.GetFramePtr() ==
nullptr)
347 Target *exe_target = exe_ctx.GetTargetPtr();
358 const std::size_t original_code_size = code.size();
361 code = llvm::getToken(code).second.ltrim();
363 code = args.GetRawPart();
366 assert(original_code_size >= code.size());
367 std::size_t raw_start = original_code_size - code.size();
372 if (cursor_pos < raw_start)
376 assert(cursor_pos >= raw_start);
377 cursor_pos -= raw_start;
379 auto language = exe_ctx.GetFrameRef().GetLanguage();
384 options,
nullptr,
error));
388 expr->Complete(exe_ctx, request, cursor_pos);
395 if (!type.IsPointerType(&pointee))
410 Target *exe_target = exe_ctx.GetTargetPtr();
418 "Can't disable JIT compilation for top-level expressions.\n");
422 EvaluateExpressionOptions eval_options =
434 error_stream <<
" Evaluated this expression after applying Fix-It(s):\n";
438 if (result_valobj_sp) {
443 if (result_valobj_sp->GetError().Success()) {
446 result_valobj_sp->SetFormat(format);
452 "expression cannot be used with --element-count %s\n",
453 error.AsCString(
""));
458 bool suppress_result =
463 options.SetHideRootName(suppress_result);
464 options.SetVariableFormatDisplayLanguage(
465 result_valobj_sp->GetPreferredDisplayLanguage());
467 if (llvm::Error
error =
468 result_valobj_sp->Dump(output_stream, options)) {
477 if (
auto result_var_sp =
479 auto language = result_valobj_sp->GetPreferredDisplayLanguage();
480 if (
auto *persistent_state =
482 persistent_state->RemovePersistentVariable(result_var_sp);
487 if (result_valobj_sp->GetError().GetError() ==
496 result.
SetError(result_valobj_sp->GetError().ToError());
500 error_stream.
Printf(
"error: unknown error\n");
519 output_stream->Flush();
520 *error_stream << return_obj.GetErrorString();
526 const size_t num_lines = lines.
GetSize();
527 if (num_lines > 0 && lines[num_lines - 1].empty()) {
542 const bool multiple_lines =
true;
548 multiple_lines, color_prompt,
555 "Enter expressions, then terminate with an empty line to evaluate:\n");
568 command_options.
debug =
false;
575 if (command_options.
timeout > 0)
589 if (command.empty()) {
595 llvm::StringRef expr = args.GetRawPart();
597 if (args.HasArgs()) {
620 bool initialize =
false;
629 if (repl_error.
Fail()) {
630 result.
SetError(std::move(repl_error));
637 repl_sp->SetEvaluateOptions(
643 IOHandlerSP io_handler_sp(repl_sp->GetIOHandler());
644 io_handler_sp->SetIsDone(
false);
648 "Couldn't create a REPL for %s",
650 result.
SetError(std::move(repl_error));
656 else if (expr.empty()) {
664 std::optional<uint16_t> indent;
666 if (pos != llvm::StringRef::npos)
679 std::string fixed_command(
"expression ");
680 if (args.HasArgs()) {
682 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)
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
CommandObjectRaw(CommandInterpreter &interpreter, llvm::StringRef name, llvm::StringRef help="", llvm::StringRef syntax="", uint32_t flags=0)
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)
const ValueObjectList & GetValueObjectList() const
Stream & GetErrorStream()
void SetStatus(lldb::ReturnStatus status)
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.
lldb::StreamUP GetAsyncErrorStream()
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)
lldb::StreamUP GetAsyncOutputStream()
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.
IOHandlerDelegate(Completion completion=Completion::None)
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()
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
Debugger & GetDebugger() 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.
void Append(const lldb::ValueObjectSP &val_obj_sp)
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::Stream > StreamSP
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::LockableStreamFile > LockableStreamFileSP
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)