18
18
#include " lldb/Interpreter/OptionGroupValueObjectDisplay.h"
19
19
#include " lldb/Target/StackFrame.h"
20
20
#include " lldb/Utility/ConstString.h"
21
+ #include " lldb/Utility/LLDBLog.h"
22
+ #include " lldb/Utility/Log.h"
21
23
#include " lldb/ValueObject/ValueObject.h"
22
24
#include " lldb/lldb-defines.h"
23
25
#include " lldb/lldb-enumerations.h"
24
26
#include " lldb/lldb-forward.h"
25
27
#include " llvm/ADT/StringRef.h"
28
+ #include " llvm/Support/Error.h"
26
29
27
30
#include < regex>
28
31
@@ -132,27 +135,22 @@ void CommandObjectDWIMPrint::DoExecute(StringRef command,
132
135
};
133
136
134
137
// Dump `valobj` according to whether `po` was requested or not.
135
- auto dump_val_object = [&](ValueObject &valobj) {
138
+ auto dump_val_object = [&](ValueObject &valobj) -> Error {
136
139
if (is_po) {
137
140
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
- }
141
+ if (Error err = valobj.Dump (temp_result_stream, dump_options))
142
+ return err;
142
143
llvm::StringRef output = temp_result_stream.GetString ();
143
144
maybe_add_hint (output);
144
145
result.GetOutputStream () << output;
145
146
} 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
- }
147
+ if (Error err = valobj.Dump (result.GetOutputStream (), dump_options))
148
+ return err;
152
149
}
153
150
m_interpreter.PrintWarningsIfNecessary (result.GetOutputStream (),
154
151
m_cmd_name);
155
152
result.SetStatus (eReturnStatusSuccessFinishResult);
153
+ return Error::success ();
156
154
};
157
155
158
156
// First, try `expr` as a _limited_ frame variable expression path: only the
@@ -186,8 +184,13 @@ void CommandObjectDWIMPrint::DoExecute(StringRef command,
186
184
expr);
187
185
}
188
186
189
- dump_val_object (*valobj_sp);
190
- return ;
187
+ Error err = dump_val_object (*valobj_sp);
188
+ if (!err)
189
+ return ;
190
+
191
+ // Dump failed, continue on to expression evaluation.
192
+ LLDB_LOG_ERROR (GetLog (LLDBLog::Expressions), std::move (err),
193
+ " could not print frame variable '{1}': {0}" , expr);
191
194
}
192
195
}
193
196
@@ -196,8 +199,14 @@ void CommandObjectDWIMPrint::DoExecute(StringRef command,
196
199
if (auto *state = target.GetPersistentExpressionStateForLanguage (language))
197
200
if (auto var_sp = state->GetVariable (expr))
198
201
if (auto valobj_sp = var_sp->GetValueObject ()) {
199
- dump_val_object (*valobj_sp);
200
- return ;
202
+ Error err = dump_val_object (*valobj_sp);
203
+ if (!err)
204
+ return ;
205
+
206
+ // Dump failed, continue on to expression evaluation.
207
+ LLDB_LOG_ERROR (GetLog (LLDBLog::Expressions), std::move (err),
208
+ " could not print persistent variable '{1}': {0}" ,
209
+ expr);
201
210
}
202
211
203
212
// Third, and lastly, try `expr` as a source expression to evaluate.
@@ -248,10 +257,12 @@ void CommandObjectDWIMPrint::DoExecute(StringRef command,
248
257
result.AppendNoteWithFormatv (" ran `expression {0}{1}`" , flags, expr);
249
258
}
250
259
251
- if (valobj_sp->GetError ().GetError () != UserExpression::kNoResult )
252
- dump_val_object (*valobj_sp);
253
- else
260
+ if (valobj_sp->GetError ().GetError () != UserExpression::kNoResult ) {
261
+ if (Error err = dump_val_object (*valobj_sp))
262
+ result.SetError (std::move (err));
263
+ } else {
254
264
result.SetStatus (eReturnStatusSuccessFinishNoResult);
265
+ }
255
266
256
267
if (suppress_result)
257
268
if (auto result_var_sp =
0 commit comments