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"};
97 if (!language && frame)
102 auto maybe_add_hint = [&](llvm::StringRef output) {
103 static bool note_shown =
false;
116 static const std::regex swift_class_regex(
117 "^<\\S+: 0x[[:xdigit:]]{5,}>\\s*$");
122 std::regex_match(output.data(), swift_class_regex)) {
125 "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)");
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);
164 const bool try_variable_path =
165 expr.find_first_of(
"*&->[]") == StringRef::npos;
166 if (frame && try_variable_path) {
174 if (valobj_sp && status.
Success() && valobj_sp->GetError().Success()) {
175 if (!suppress_result) {
176 if (
auto persisted_valobj = valobj_sp->Persist())
177 valobj_sp = persisted_valobj;
188 dump_val_object(*valobj_sp);
194 if (expr.starts_with(
"$"))
197 if (
auto var_sp = state->GetVariable(expr))
198 if (
auto valobj_sp = var_sp->GetValueObject()) {
199 dump_val_object(*valobj_sp);
205 auto *exe_scope =
m_exe_ctx.GetBestExecutionContextScope();
207 std::string fixed_expression;
210 expr, exe_scope, valobj_sp, eval_options, &fixed_expression);
216 std::optional<uint16_t> indent;
217 if (fixed_expression.empty()) {
219 if (pos != llvm::StringRef::npos)
230 error_stream <<
" Evaluated this expression after applying Fix-It(s):\n";
231 error_stream <<
" " << fixed_expression <<
"\n";
237 result.
SetError(valobj_sp->GetError().Clone());
240 "unknown error evaluating expression `{0}`", expr);
252 dump_val_object(*valobj_sp);
257 if (
auto result_var_sp =
259 auto language = valobj_sp->GetPreferredDisplayLanguage();
260 if (
auto *persistent_state =
262 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
CommandObjectRaw(CommandInterpreter &interpreter, llvm::StringRef name, llvm::StringRef help="", llvm::StringRef syntax="", uint32_t flags=0)
void AddSimpleArgumentList(lldb::CommandArgumentType arg_type, ArgumentRepetitionType repetition_type=eArgRepeatPlain)
bool ParseOptionsAndNotify(Args &args, CommandReturnObject &result, OptionGroupOptions &group_options, ExecutionContext &exe_ctx)
ExecutionContext m_exe_ctx
CommandInterpreter & m_interpreter
std::string m_original_command
void AppendError(llvm::StringRef in_string)
const ValueObjectList & GetValueObjectList() const
void AppendNote(llvm::StringRef in_string)
Stream & GetErrorStream()
void SetStatus(lldb::ReturnStatus status)
void SetError(Status error)
void SetDiagnosticIndent(std::optional< uint16_t > indent)
void AppendNoteWithFormatv(const char *format, Args &&...args)
void AppendErrorWithFormatv(const char *format, Args &&...args)
Stream & GetOutputStream()
lldb::DWIMPrintVerbosity GetDWIMPrintVerbosity() const
DumpValueObjectOptions & SetHideRootName(bool hide_root_name)
DumpValueObjectOptions & SetExpandPointerTypeFlags(unsigned flags)
lldb::DynamicValueType GetUseDynamic() const
void SetSuppressPersistentResult(bool b)
A pair of an option list with a 'raw' string as a suffix.
bool HasArgs() const
Returns true if there are any arguments before the raw suffix.
Args & GetArgs()
Returns the list of arguments.
llvm::StringRef GetArgString() const
Returns the part of the input string that was used for parsing the argument list.
const std::string & GetRawPart() const
Returns the raw suffix part of the parsed string.
llvm::StringRef GetArgStringWithDelimiter() const
Returns the part of the input string that was used for parsing the argument list.
A command line option parsing protocol class.
This base class provides an interface to stack frames.
virtual lldb::ValueObjectSP GetValueForVariableExpressionPath(llvm::StringRef var_expr, lldb::DynamicValueType use_dynamic, uint32_t options, lldb::VariableSP &var_sp, Status &error, lldb::DILMode mode=lldb::eDILModeFull)
Create a ValueObject for a variable name / pathname, possibly including simple dereference/child sele...
@ eExpressionPathOptionsDisallowGlobals
@ eExpressionPathOptionsAllowDirectIVarAccess
virtual SourceLanguage GuessLanguage()
Similar to GetLanguage(), but is allowed to take a potentially incorrect guess if exact information i...
bool Success() const
Test for success condition.
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)
bool IsDummyTarget() const
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)
A class that represents a running process on the host machine.
std::string toString(FormatterBytecode::OpCodes op)
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.
@ eLanguageTypeSwift
Swift.
ExpressionResults
The results of expression evaluation.
@ eReturnStatusSuccessFinishResult
@ eReturnStatusSuccessFinishNoResult
std::shared_ptr< lldb_private::Variable > VariableSP
@ eDILModeSimple
Allowed: identifiers, operators: '.'.
A type-erased pair of llvm::dwarf::SourceLanguageName and version.
lldb::LanguageType AsLanguageType() const