2323#include " lldb/lldb-enumerations.h"
2424#include " lldb/lldb-forward.h"
2525#include " llvm/ADT/StringRef.h"
26+ #include " llvm/Support/Error.h"
2627
2728#include < regex>
2829
@@ -132,27 +133,22 @@ void CommandObjectDWIMPrint::DoExecute(StringRef command,
132133 };
133134
134135 // Dump `valobj` according to whether `po` was requested or not.
135- auto dump_val_object = [&](ValueObject &valobj) {
136+ auto dump_val_object = [&](ValueObject &valobj) -> Error {
136137 if (is_po) {
137138 StreamString temp_result_stream;
138- if (llvm::Error error = valobj.Dump (temp_result_stream, dump_options)) {
139- result.AppendError (toString (std::move (error)));
140- return ;
141- }
139+ if (Error err = valobj.Dump (temp_result_stream, dump_options))
140+ return err;
142141 llvm::StringRef output = temp_result_stream.GetString ();
143142 maybe_add_hint (output);
144143 result.GetOutputStream () << output;
145144 } else {
146- llvm::Error error =
147- valobj.Dump (result.GetOutputStream (), dump_options);
148- if (error) {
149- result.AppendError (toString (std::move (error)));
150- return ;
151- }
145+ if (Error err = valobj.Dump (result.GetOutputStream (), dump_options))
146+ return err;
152147 }
153148 m_interpreter.PrintWarningsIfNecessary (result.GetOutputStream (),
154149 m_cmd_name);
155150 result.SetStatus (eReturnStatusSuccessFinishResult);
151+ return Error::success ();
156152 };
157153
158154 // First, try `expr` as a _limited_ frame variable expression path: only the
@@ -186,8 +182,11 @@ void CommandObjectDWIMPrint::DoExecute(StringRef command,
186182 expr);
187183 }
188184
189- dump_val_object (*valobj_sp);
190- return ;
185+ bool failed = errorToBool (dump_val_object (*valobj_sp));
186+ if (!failed)
187+ return ;
188+
189+ // Dump failed, continue on to expression evaluation.
191190 }
192191 }
193192
@@ -196,8 +195,9 @@ void CommandObjectDWIMPrint::DoExecute(StringRef command,
196195 if (auto *state = target.GetPersistentExpressionStateForLanguage (language))
197196 if (auto var_sp = state->GetVariable (expr))
198197 if (auto valobj_sp = var_sp->GetValueObject ()) {
199- dump_val_object (*valobj_sp);
200- return ;
198+ bool failed = errorToBool (dump_val_object (*valobj_sp));
199+ if (!failed)
200+ return ;
201201 }
202202
203203 // Third, and lastly, try `expr` as a source expression to evaluate.
@@ -248,10 +248,12 @@ void CommandObjectDWIMPrint::DoExecute(StringRef command,
248248 result.AppendNoteWithFormatv (" ran `expression {0}{1}`" , flags, expr);
249249 }
250250
251- if (valobj_sp->GetError ().GetError () != UserExpression::kNoResult )
252- dump_val_object (*valobj_sp);
253- else
251+ if (valobj_sp->GetError ().GetError () != UserExpression::kNoResult ) {
252+ if (Error err = dump_val_object (*valobj_sp))
253+ result.SetError (std::move (err));
254+ } else {
254255 result.SetStatus (eReturnStatusSuccessFinishNoResult);
256+ }
255257
256258 if (suppress_result)
257259 if (auto result_var_sp =
0 commit comments