9#include "llvm/ADT/StringRef.h"
35#define LLDB_OPTIONS_expression
36#include "CommandOptions.inc"
39 uint32_t option_idx, llvm::StringRef option_arg,
43 const int short_option =
GetDefinitions()[option_idx].short_option;
45 switch (short_option) {
50 sstr.
Printf(
"unknown language type: '%s' for expression. "
51 "List of supported languages:\n",
52 option_arg.str().c_str());
64 error.SetErrorStringWithFormat(
65 "invalid all-threads value setting: \"%s\"",
66 option_arg.str().c_str());
77 error.SetErrorStringWithFormat(
78 "could not convert \"%s\" to a boolean value.",
79 option_arg.str().c_str());
89 error.SetErrorStringWithFormat(
90 "could not convert \"%s\" to a boolean value.",
91 option_arg.str().c_str());
96 if (option_arg.getAsInteger(0,
timeout)) {
98 error.SetErrorStringWithFormat(
"invalid timeout setting \"%s\"",
99 option_arg.str().c_str());
109 error.SetErrorStringWithFormat(
110 "could not convert \"%s\" to a boolean value.",
111 option_arg.str().c_str());
116 if (option_arg.empty()) {
123 if (!
error.Success())
124 error.SetErrorStringWithFormat(
125 "unrecognized value for description-verbosity '%s'",
126 option_arg.str().c_str());
145 error.SetErrorStringWithFormat(
146 "could not convert \"%s\" to a boolean value.",
147 option_arg.str().c_str());
153 bool persist_result =
158 error.SetErrorStringWithFormat(
159 "could not convert \"%s\" to a boolean value.",
160 option_arg.str().c_str());
165 llvm_unreachable(
"Unimplemented option");
176 ignore_breakpoints = process_sp->GetIgnoreBreakpointsInExpressions();
177 unwind_on_error = process_sp->GetUnwindOnErrorInExpressions();
179 ignore_breakpoints =
true;
180 unwind_on_error =
true;
184 try_all_threads =
true;
195llvm::ArrayRef<OptionDefinition>
197 return llvm::ArrayRef(g_expression_options);
216 bool auto_apply_fixits;
220 auto_apply_fixits = this->auto_apply_fixits ==
eLazyBoolYes;
230 if (!ignore_breakpoints || !unwind_on_error)
234 options.
SetTimeout(std::chrono::microseconds(timeout));
254 "Evaluate an expression on the current "
255 "thread. Displays any returned value "
256 "with LLDB's default formatting.",
258 eCommandProcessMustBePaused | eCommandTryTargetAPILock),
266Single and multi-line expressions:
269 " The expression provided on the command line must be a complete expression \
270with no newlines. To evaluate a multi-line expression, \
271hit a return after an empty expression, and lldb will enter the multi-line expression editor. \
272Hit return on an empty line to end the multi-line expression."
279 " If the expression can be evaluated statically (without running code) then it will be. \
280Otherwise, by default the expression will run on the current thread with a short timeout: \
281currently .25 seconds. If it doesn't return in that time, the evaluation will be interrupted \
282and resumed with all threads running. You can use the -a option to disable retrying on all \
283threads. You can use the -t option to set a shorter timeout."
286User defined variables:
289 " You can define your own variables for convenience or to be used in subsequent expressions. \
290You define them the same way you would define variables in C. If the first character of \
291your user defined variable is a $, then the variable's value will be available in future \
292expressions, otherwise it will just be available in the current expression."
295Continuing evaluation after a breakpoint:
298 " If the \"-i false\" option is used, and execution is interrupted by a breakpoint hit, once \
299you are done with your investigation, you can either remove the expression execution frames \
300from the stack with \"thread return -x\" or if you are still interested in the expression result \
301you can issue the \"continue\" command and the expression evaluation will complete and the \
302expression result will be available using the \"thread.completed-expression\" key in the thread \
309 expr my_struct->a = my_array[3]
310 expr -f bin -- (index * 8) + 5
311 expr unsigned int $foo = 5
312 expr char c[] = \"foo\"; c[0])");
343 if (exe_ctx.GetFramePtr() ==
nullptr)
346 Target *exe_target = exe_ctx.GetTargetPtr();
357 const std::size_t original_code_size = code.size();
360 code = llvm::getToken(code).second.ltrim();
362 code = args.GetRawPart();
365 assert(original_code_size >= code.size());
366 std::size_t raw_start = original_code_size - code.size();
371 if (cursor_pos < raw_start)
375 assert(cursor_pos >= raw_start);
376 cursor_pos -= raw_start;
378 auto language = exe_ctx.GetFrameRef().GetLanguage();
383 options,
nullptr,
error));
387 expr->Complete(exe_ctx, request, cursor_pos);
394 if (!type.IsPointerType(&pointee))
395 return Status(
"as it does not refer to a pointer");
397 return Status(
"as it refers to a pointer to void");
409 Target *exe_target = exe_ctx.GetTargetPtr();
417 "Can't disable JIT compilation for top-level expressions.\n");
433 error_stream <<
" Evaluated this expression after applying Fix-It(s):\n";
437 if (result_valobj_sp) {
440 if (result_valobj_sp->GetError().Success()) {
443 result_valobj_sp->SetFormat(format);
449 "expression cannot be used with --element-count %s\n",
450 error.AsCString(
""));
455 bool suppress_result =
460 options.SetHideRootName(suppress_result);
461 options.SetVariableFormatDisplayLanguage(
462 result_valobj_sp->GetPreferredDisplayLanguage());
464 if (llvm::Error
error =
465 result_valobj_sp->Dump(output_stream, options)) {
471 if (
auto result_var_sp =
473 auto language = result_valobj_sp->GetPreferredDisplayLanguage();
474 if (
auto *persistent_state =
476 persistent_state->RemovePersistentVariable(result_var_sp);
481 if (result_valobj_sp->GetError().GetError() ==
489 const char *error_cstr = result_valobj_sp->GetError().AsCString();
490 if (error_cstr && error_cstr[0]) {
491 const size_t error_cstr_len = strlen(error_cstr);
492 const bool ends_with_newline = error_cstr[error_cstr_len - 1] ==
'\n';
493 if (strstr(error_cstr,
"error:") != error_cstr)
495 error_stream.
Write(error_cstr, error_cstr_len);
496 if (!ends_with_newline)
499 error_stream.
PutCString(
"error: unknown error\n");
506 error_stream.
Printf(
"error: unknown error\n");
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,
557 StreamFileSP output_sp = io_handler_sp->GetOutputStreamFileSP();
559 output_sp->PutCString(
560 "Enter expressions, then terminate with an empty line to evaluate:\n");
574 command_options.
debug =
false;
581 if (command_options.
timeout > 0)
595 if (command.empty()) {
601 llvm::StringRef expr = args.GetRawPart();
603 if (args.HasArgs()) {
626 bool initialize =
false;
643 repl_sp->SetEvaluateOptions(
649 IOHandlerSP io_handler_sp(repl_sp->GetIOHandler());
650 io_handler_sp->SetIsDone(
false);
654 "Couldn't create a REPL for %s",
662 else if (expr.empty()) {
677 std::string fixed_command(
"expression ");
678 if (args.HasArgs()) {
680 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
void void AppendError(llvm::StringRef in_string)
Stream & GetErrorStream()
void SetStatus(lldb::ReturnStatus status)
void AppendErrorWithFormat(const char *format,...) __attribute__((format(printf
void SetError(const Status &error, const char *fallback_error_cstr=nullptr)
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.
int SetErrorStringWithFormat(const char *format,...) __attribute__((format(printf
Set the current error string to a formatted error string.
bool Success() const
Test for success condition.
llvm::StringRef GetString() const
A stream class that can stream formatted output to a file.
size_t Write(const void *src, size_t src_len)
Output character bytes to the stream.
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.
size_t EOL()
Output and End of Line character 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)