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) {
54 sstr.
Printf(
"unknown language type: '%s' for expression. "
55 "List of supported languages:\n",
56 option_arg.str().c_str());
69 "invalid all-threads value setting: \"%s\"",
70 option_arg.str().c_str());
82 "could not convert \"%s\" to a boolean value.",
83 option_arg.str().c_str());
94 "could not convert \"%s\" to a boolean value.",
95 option_arg.str().c_str());
100 if (option_arg.getAsInteger(0,
timeout)) {
103 "invalid timeout setting \"%s\"", option_arg.str().c_str());
114 "could not convert \"%s\" to a boolean value.",
115 option_arg.str().c_str());
120 if (option_arg.empty()) {
127 if (!
error.Success())
129 "unrecognized value for description-verbosity '%s'",
130 option_arg.str().c_str());
150 "could not convert \"%s\" to a boolean value.",
151 option_arg.str().c_str());
157 bool persist_result =
163 "could not convert \"%s\" to a boolean value.",
164 option_arg.str().c_str());
169 llvm_unreachable(
"Unimplemented option");
200llvm::ArrayRef<OptionDefinition>
202 return llvm::ArrayRef(g_expression_options);
260 "Evaluate an expression on the current "
261 "thread. Displays any returned value "
262 "with LLDB's default formatting.",
264 eCommandProcessMustBePaused | eCommandTryTargetAPILock),
272Single and multi-line expressions:
275 " The expression provided on the command line must be a complete expression \
276with no newlines. To evaluate a multi-line expression, \
277hit a return after an empty expression, and lldb will enter the multi-line expression editor. \
278Hit return on an empty line to end the multi-line expression."
285 " If the expression can be evaluated statically (without running code) then it will be. \
286Otherwise, by default the expression will run on the current thread with a short timeout: \
287currently .25 seconds. If it doesn't return in that time, the evaluation will be interrupted \
288and resumed with all threads running. You can use the -a option to disable retrying on all \
289threads. You can use the -t option to set a shorter timeout."
292User defined variables:
295 " You can define your own variables for convenience or to be used in subsequent expressions. \
296You define them the same way you would define variables in C. If the first character of \
297your user defined variable is a $, then the variable's value will be available in future \
298expressions, otherwise it will just be available in the current expression."
301Continuing evaluation after a breakpoint:
304 " If the \"-i false\" option is used, and execution is interrupted by a breakpoint hit, once \
305you are done with your investigation, you can either remove the expression execution frames \
306from the stack with \"thread return -x\" or if you are still interested in the expression result \
307you can issue the \"continue\" command and the expression evaluation will complete and the \
308expression result will be available using the \"thread.completed-expression\" key in the thread \
315 expr my_struct->a = my_array[3]
316 expr -f bin -- (index * 8) + 5
317 expr unsigned int $foo = 5
318 expr char c[] = \"foo\"; c[0])");
349 if (exe_ctx.GetFramePtr() ==
nullptr)
352 Target *exe_target = exe_ctx.GetTargetPtr();
363 const std::size_t original_code_size = code.size();
366 code = llvm::getToken(code).second.ltrim();
368 code = args.GetRawPart();
371 assert(original_code_size >= code.size());
372 std::size_t raw_start = original_code_size - code.size();
377 if (cursor_pos < raw_start)
381 assert(cursor_pos >= raw_start);
382 cursor_pos -= raw_start;
384 auto language = exe_ctx.GetFrameRef().GetLanguage();
389 options,
nullptr,
error));
393 expr->Complete(exe_ctx, request, cursor_pos);
400 if (!type.IsPointerType(&pointee))
415 Target *exe_target = exe_ctx.GetTargetPtr();
423 "Can't disable JIT compilation for top-level expressions.\n");
427 EvaluateExpressionOptions eval_options =
439 error_stream <<
" Evaluated this expression after applying Fix-It(s):\n";
443 if (result_valobj_sp) {
448 if (result_valobj_sp->GetError().Success()) {
451 result_valobj_sp->SetFormat(format);
457 "expression cannot be used with --element-count %s\n",
458 error.AsCString(
""));
463 bool suppress_result =
468 options.SetHideRootName(suppress_result);
469 options.SetVariableFormatDisplayLanguage(
470 result_valobj_sp->GetPreferredDisplayLanguage());
472 if (llvm::Error
error =
473 result_valobj_sp->Dump(output_stream, options)) {
482 if (
auto result_var_sp =
484 auto language = result_valobj_sp->GetPreferredDisplayLanguage();
485 if (
auto *persistent_state =
487 persistent_state->RemovePersistentVariable(result_var_sp);
492 if (result_valobj_sp->GetError().GetError() ==
501 result.
SetError(result_valobj_sp->GetError().ToError());
505 error_stream.
Printf(
"error: unknown error\n");
524 output_stream->Flush();
525 *error_stream << return_obj.GetErrorString();
531 const size_t num_lines = lines.
GetSize();
532 if (num_lines > 0 && lines[num_lines - 1].empty()) {
547 const bool multiple_lines =
true;
553 multiple_lines, color_prompt,
560 "Enter expressions, then terminate with an empty line to evaluate:\n");
573 command_options.
debug =
false;
580 if (command_options.
timeout > 0)
594 if (command.empty()) {
600 llvm::StringRef expr = args.GetRawPart();
602 if (args.HasArgs()) {
625 bool initialize =
false;
634 if (repl_error.
Fail()) {
635 result.
SetError(std::move(repl_error));
642 repl_sp->SetEvaluateOptions(
648 IOHandlerSP io_handler_sp(repl_sp->GetIOHandler());
649 io_handler_sp->SetIsDone(
false);
653 "Couldn't create a REPL for %s",
655 result.
SetError(std::move(repl_error));
661 else if (expr.empty()) {
669 std::optional<uint16_t> indent;
671 if (pos != llvm::StringRef::npos)
684 std::string fixed_command(
"expression ");
685 if (args.HasArgs()) {
687 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
bool cpp_ignore_context_qualifiers
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 SetCppIgnoreContextQualifiers(bool value)
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)
Returns the internal LLDB name for the specified 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
LanguageRuntimeDescriptionDisplayVerbosity
@ eLanguageRuntimeDescriptionDisplayVerbosityCompact
@ eLanguageRuntimeDescriptionDisplayVerbosityFull
std::string toString(FormatterBytecode::OpCodes op)
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)