@@ -141,10 +141,14 @@ void CommandObjectDWIMPrint::DoExecute(StringRef command,
141
141
maybe_add_hint (output);
142
142
result.GetOutputStream () << output;
143
143
} else {
144
- if (llvm::Error error =
145
- valobj.Dump (result.GetOutputStream (), dump_options))
144
+ llvm::Error error =
145
+ valobj.Dump (result.GetOutputStream (), dump_options);
146
+ if (error) {
146
147
result.AppendError (toString (std::move (error)));
148
+ return ;
149
+ }
147
150
}
151
+ result.SetStatus (eReturnStatusSuccessFinishResult);
148
152
};
149
153
150
154
// First, try `expr` as the name of a frame variable.
@@ -165,7 +169,6 @@ void CommandObjectDWIMPrint::DoExecute(StringRef command,
165
169
}
166
170
167
171
dump_val_object (*valobj_sp);
168
- result.SetStatus (eReturnStatusSuccessFinishResult);
169
172
return ;
170
173
}
171
174
}
@@ -176,7 +179,6 @@ void CommandObjectDWIMPrint::DoExecute(StringRef command,
176
179
if (auto var_sp = state->GetVariable (expr))
177
180
if (auto valobj_sp = var_sp->GetValueObject ()) {
178
181
dump_val_object (*valobj_sp);
179
- result.SetStatus (eReturnStatusSuccessFinishResult);
180
182
return ;
181
183
}
182
184
@@ -197,34 +199,36 @@ void CommandObjectDWIMPrint::DoExecute(StringRef command,
197
199
error_stream << " " << fixed_expression << " \n " ;
198
200
}
199
201
200
- if (expr_result == eExpressionCompleted) {
201
- if (verbosity != eDWIMPrintVerbosityNone) {
202
- StringRef flags;
203
- if (args.HasArgs ())
204
- flags = args.GetArgStringWithDelimiter ();
205
- result.AppendMessageWithFormatv (" note: ran `expression {0}{1}`" , flags,
206
- expr);
207
- }
208
-
209
- if (valobj_sp->GetError ().GetError () != UserExpression::kNoResult )
210
- dump_val_object (*valobj_sp);
211
-
212
- if (suppress_result)
213
- if (auto result_var_sp =
214
- target.GetPersistentVariable (valobj_sp->GetName ())) {
215
- auto language = valobj_sp->GetPreferredDisplayLanguage ();
216
- if (auto *persistent_state =
217
- target.GetPersistentExpressionStateForLanguage (language))
218
- persistent_state->RemovePersistentVariable (result_var_sp);
219
- }
220
-
221
- result.SetStatus (eReturnStatusSuccessFinishResult);
222
- } else {
202
+ // If the expression failed, return an error.
203
+ if (expr_result != eExpressionCompleted) {
223
204
if (valobj_sp)
224
205
result.SetError (valobj_sp->GetError ());
225
206
else
226
207
result.AppendErrorWithFormatv (
227
208
" unknown error evaluating expression `{0}`" , expr);
209
+ return ;
210
+ }
211
+
212
+ if (verbosity != eDWIMPrintVerbosityNone) {
213
+ StringRef flags;
214
+ if (args.HasArgs ())
215
+ flags = args.GetArgStringWithDelimiter ();
216
+ result.AppendMessageWithFormatv (" note: ran `expression {0}{1}`" , flags,
217
+ expr);
228
218
}
219
+
220
+ if (valobj_sp->GetError ().GetError () != UserExpression::kNoResult )
221
+ dump_val_object (*valobj_sp);
222
+ else
223
+ result.SetStatus (eReturnStatusSuccessFinishResult);
224
+
225
+ if (suppress_result)
226
+ if (auto result_var_sp =
227
+ target.GetPersistentVariable (valobj_sp->GetName ())) {
228
+ auto language = valobj_sp->GetPreferredDisplayLanguage ();
229
+ if (auto *persistent_state =
230
+ target.GetPersistentExpressionStateForLanguage (language))
231
+ persistent_state->RemovePersistentVariable (result_var_sp);
232
+ }
229
233
}
230
234
}
0 commit comments