25#include "llvm/ADT/StringRef.h"
35 "Print a variable or expression.",
36 "dwim-print [<variable-name> | <expression>]",
37 eCommandProcessMustBePaused | eCommandTryTargetAPILock) {
45 StringRef exclude_expr_options[] = {
"debug",
"top-level"};
103 auto maybe_add_hint = [&](llvm::StringRef output) {
113 const std::regex swift_class_regex(
"^<\\S+: 0x[[:xdigit:]]{5,}>\\s*$");
115 if (
GetDebugger().GetShowDontUsePoHint() && target_ptr &&
118 std::regex_match(output.data(), swift_class_regex)) {
120 static bool note_shown =
false;
125 <<
"note: object description requested, but type doesn't implement "
126 "a custom object description. Consider using \"p\" instead of "
127 "\"po\" (this note will only be shown once per debug session).\n";
136 if (llvm::Error
error = valobj.Dump(temp_result_stream, dump_options)) {
140 llvm::StringRef output = temp_result_stream.
GetString();
141 maybe_add_hint(output);
157 if (valobj_sp && valobj_sp->GetError().Success()) {
158 if (!suppress_result) {
159 if (
auto persisted_valobj = valobj_sp->Persist())
160 valobj_sp = persisted_valobj;
166 flags = args.GetArgString();
171 dump_val_object(*valobj_sp);
177 if (expr.starts_with(
"$"))
179 if (
auto var_sp = state->GetVariable(expr))
180 if (
auto valobj_sp = var_sp->GetValueObject()) {
181 dump_val_object(*valobj_sp);
189 std::string fixed_expression;
192 expr, exe_scope, valobj_sp, eval_options, &fixed_expression);
198 error_stream <<
" Evaluated this expression after applying Fix-It(s):\n";
199 error_stream <<
" " << fixed_expression <<
"\n";
205 result.
SetError(valobj_sp->GetError());
208 "unknown error evaluating expression `{0}`", expr);
215 flags = args.GetArgStringWithDelimiter();
221 dump_val_object(*valobj_sp);
226 if (
auto result_var_sp =
228 auto language = valobj_sp->GetPreferredDisplayLanguage();
229 if (
auto *persistent_state =
231 persistent_state->RemovePersistentVariable(result_var_sp);
static llvm::raw_ostream & error(Stream &strm)
Options * GetOptions() override
CommandObjectExpression::CommandOptions m_expr_options
OptionGroupFormat m_format_options
OptionGroupOptions m_option_group
CommandObjectDWIMPrint(CommandInterpreter &interpreter)
OptionGroupValueObjectDisplay m_varobj_options
void DoExecute(llvm::StringRef command, CommandReturnObject &result) override
lldb::LanguageType language
bool ShouldSuppressResult(const OptionGroupValueObjectDisplay &display_opts) const
LanguageRuntimeDescriptionDisplayVerbosity m_verbosity
LazyBool suppress_persistent_result
EvaluateExpressionOptions GetEvaluateExpressionOptions(const Target &target, const OptionGroupValueObjectDisplay &display_opts)
Return the appropriate expression options used for evaluating the expression in the given target.
void AddSimpleArgumentList(lldb::CommandArgumentType arg_type, ArgumentRepetitionType repetition_type=eArgRepeatPlain)
bool ParseOptionsAndNotify(Args &args, CommandReturnObject &result, OptionGroupOptions &group_options, ExecutionContext &exe_ctx)
Target & GetDummyTarget()
ExecutionContext m_exe_ctx
void AppendErrorWithFormatv(const char *format, Args &&... args)
void void AppendError(llvm::StringRef in_string)
Stream & GetErrorStream()
void SetStatus(lldb::ReturnStatus status)
void void AppendMessageWithFormatv(const char *format, Args &&... args)
void SetError(const Status &error, const char *fallback_error_cstr=nullptr)
Stream & GetOutputStream()
A uniqued constant string class.
lldb::DWIMPrintVerbosity GetDWIMPrintVerbosity() const
DumpValueObjectOptions & SetHideRootName(bool hide_root_name)
void SetSuppressPersistentResult(bool b)
ExecutionContextScope * GetBestExecutionContextScope() const
StackFrame * GetFramePtr() const
Returns a pointer to the frame object.
Target * GetTargetPtr() const
Returns a pointer to the target object.
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())
A pair of an option list with a 'raw' string as a suffix.
const std::string & GetRawPart() const
Returns the raw suffix part of the parsed string.
A command line option parsing protocol class.
void NotifyOptionParsingStarting(ExecutionContext *execution_context)
This base class provides an interface to stack frames.
SourceLanguage GuessLanguage()
Similar to GetLanguage(), but is allowed to take a potentially incorrect guess if exact information i...
lldb::ValueObjectSP FindVariable(ConstString name)
Attempt to reconstruct the ValueObject for a variable with a given name from within the current Stack...
llvm::StringRef GetString() const
A stream class that can stream formatted output to a file.
bool GetEnableNotifyAboutFixIts() const
PersistentExpressionState * GetPersistentExpressionStateForLanguage(lldb::LanguageType language)
lldb::ExpressionVariableSP GetPersistentVariable(ConstString name)
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.
A class that represents a running process on the host machine.
const char * toString(AppleArm64ExceptionClass EC)
std::shared_ptr< lldb_private::ValueObject > ValueObjectSP
@ eDWIMPrintVerbosityFull
Always print a message indicating how dwim-print is evaluating its expression.
@ eDWIMPrintVerbosityNone
Run dwim-print with no verbosity.
LanguageType
Programming language type.
@ eLanguageTypeUnknown
Unknown or invalid language value.
@ eLanguageTypeSwift
Swift.
@ eLanguageTypeObjC
Objective-C.
ExpressionResults
The results of expression evaluation.
@ eReturnStatusSuccessFinishResult
lldb::LanguageType AsLanguageType() const