@@ -138,6 +138,28 @@ void CommandObjectDWIMPrint::DoExecute(StringRef command,
138
138
}
139
139
};
140
140
141
+ // Dump `valobj` according to whether `po` was requested or not.
142
+ auto dump_val_object = [&](ValueObject &valobj) {
143
+ if (is_po) {
144
+ StreamString temp_result_stream;
145
+ if (llvm::Error error = valobj.Dump (temp_result_stream, dump_options)) {
146
+ result.AppendError (toString (std::move (error)));
147
+ return ;
148
+ }
149
+ llvm::StringRef output = temp_result_stream.GetString ();
150
+ maybe_add_hint (output);
151
+ result.GetOutputStream () << output;
152
+ } else {
153
+ llvm::Error error =
154
+ valobj.Dump (result.GetOutputStream (), dump_options);
155
+ if (error) {
156
+ result.AppendError (toString (std::move (error)));
157
+ return ;
158
+ }
159
+ }
160
+ result.SetStatus (eReturnStatusSuccessFinishResult);
161
+ };
162
+
141
163
// First, try `expr` as the name of a frame variable.
142
164
if (frame) {
143
165
auto valobj_sp = frame->FindVariable (ConstString (expr));
@@ -155,16 +177,7 @@ void CommandObjectDWIMPrint::DoExecute(StringRef command,
155
177
flags, expr);
156
178
}
157
179
158
- if (is_po) {
159
- StreamString temp_result_stream;
160
- valobj_sp->Dump (temp_result_stream, dump_options);
161
- llvm::StringRef output = temp_result_stream.GetString ();
162
- maybe_add_hint (output);
163
- result.GetOutputStream () << output;
164
- } else {
165
- valobj_sp->Dump (result.GetOutputStream (), dump_options);
166
- }
167
- result.SetStatus (eReturnStatusSuccessFinishResult);
180
+ dump_val_object (*valobj_sp);
168
181
return ;
169
182
}
170
183
}
@@ -211,8 +224,7 @@ void CommandObjectDWIMPrint::DoExecute(StringRef command,
211
224
if (auto *state = target.GetPersistentExpressionStateForLanguage (language))
212
225
if (auto var_sp = state->GetVariable (expr))
213
226
if (auto valobj_sp = var_sp->GetValueObject ()) {
214
- valobj_sp->Dump (result.GetOutputStream (), dump_options);
215
- result.SetStatus (eReturnStatusSuccessFinishResult);
227
+ dump_val_object (*valobj_sp);
216
228
return ;
217
229
}
218
230
@@ -233,43 +245,36 @@ void CommandObjectDWIMPrint::DoExecute(StringRef command,
233
245
error_stream << " " << fixed_expression << " \n " ;
234
246
}
235
247
236
- if (expr_result == eExpressionCompleted) {
237
- if (verbosity != eDWIMPrintVerbosityNone) {
238
- StringRef flags;
239
- if (args.HasArgs ())
240
- flags = args.GetArgStringWithDelimiter ();
241
- result.AppendMessageWithFormatv (" note: ran `expression {0}{1}`" , flags,
242
- expr);
243
- }
244
-
245
- if (valobj_sp->GetError ().GetError () != UserExpression::kNoResult ) {
246
- if (is_po) {
247
- StreamString temp_result_stream;
248
- valobj_sp->Dump (temp_result_stream, dump_options);
249
- llvm::StringRef output = temp_result_stream.GetString ();
250
- maybe_add_hint (output);
251
- result.GetOutputStream () << output;
252
- } else {
253
- valobj_sp->Dump (result.GetOutputStream (), dump_options);
254
- }
255
- }
256
-
257
- if (suppress_result)
258
- if (auto result_var_sp =
259
- target.GetPersistentVariable (valobj_sp->GetName ())) {
260
- auto language = valobj_sp->GetPreferredDisplayLanguage ();
261
- if (auto *persistent_state =
262
- target.GetPersistentExpressionStateForLanguage (language))
263
- persistent_state->RemovePersistentVariable (result_var_sp);
264
- }
265
-
266
- result.SetStatus (eReturnStatusSuccessFinishResult);
267
- } else {
248
+ // If the expression failed, return an error.
249
+ if (expr_result != eExpressionCompleted) {
268
250
if (valobj_sp)
269
251
result.SetError (valobj_sp->GetError ());
270
252
else
271
253
result.AppendErrorWithFormatv (
272
254
" unknown error evaluating expression `{0}`" , expr);
255
+ return ;
256
+ }
257
+
258
+ if (verbosity != eDWIMPrintVerbosityNone) {
259
+ StringRef flags;
260
+ if (args.HasArgs ())
261
+ flags = args.GetArgStringWithDelimiter ();
262
+ result.AppendMessageWithFormatv (" note: ran `expression {0}{1}`" , flags,
263
+ expr);
273
264
}
265
+
266
+ if (valobj_sp->GetError ().GetError () != UserExpression::kNoResult )
267
+ dump_val_object (*valobj_sp);
268
+ else
269
+ result.SetStatus (eReturnStatusSuccessFinishResult);
270
+
271
+ if (suppress_result)
272
+ if (auto result_var_sp =
273
+ target.GetPersistentVariable (valobj_sp->GetName ())) {
274
+ auto language = valobj_sp->GetPreferredDisplayLanguage ();
275
+ if (auto *persistent_state =
276
+ target.GetPersistentExpressionStateForLanguage (language))
277
+ persistent_state->RemovePersistentVariable (result_var_sp);
278
+ }
274
279
}
275
280
}
0 commit comments