|
19 | 19 | #include "lldb/Target/MemoryRegionInfo.h" |
20 | 20 | #include "lldb/Target/StackFrame.h" |
21 | 21 | #include "lldb/Utility/ConstString.h" |
| 22 | +#include "lldb/Utility/LLDBLog.h" |
| 23 | +#include "lldb/Utility/Log.h" |
22 | 24 | #include "lldb/ValueObject/ValueObject.h" |
23 | 25 | #include "lldb/lldb-defines.h" |
24 | 26 | #include "lldb/lldb-enumerations.h" |
25 | 27 | #include "lldb/lldb-forward.h" |
26 | 28 | #include "lldb/lldb-types.h" |
27 | 29 | #include "llvm/ADT/StringRef.h" |
| 30 | +#include "llvm/Support/Error.h" |
28 | 31 |
|
29 | 32 | #include <regex> |
30 | 33 |
|
@@ -134,27 +137,22 @@ void CommandObjectDWIMPrint::DoExecute(StringRef command, |
134 | 137 | }; |
135 | 138 |
|
136 | 139 | // Dump `valobj` according to whether `po` was requested or not. |
137 | | - auto dump_val_object = [&](ValueObject &valobj) { |
| 140 | + auto dump_val_object = [&](ValueObject &valobj) -> Error { |
138 | 141 | if (is_po) { |
139 | 142 | StreamString temp_result_stream; |
140 | | - if (llvm::Error error = valobj.Dump(temp_result_stream, dump_options)) { |
141 | | - result.AppendError(toString(std::move(error))); |
142 | | - return; |
143 | | - } |
| 143 | + if (Error err = valobj.Dump(temp_result_stream, dump_options)) |
| 144 | + return err; |
144 | 145 | llvm::StringRef output = temp_result_stream.GetString(); |
145 | 146 | maybe_add_hint(output); |
146 | 147 | result.GetOutputStream() << output; |
147 | 148 | } else { |
148 | | - llvm::Error error = |
149 | | - valobj.Dump(result.GetOutputStream(), dump_options); |
150 | | - if (error) { |
151 | | - result.AppendError(toString(std::move(error))); |
152 | | - return; |
153 | | - } |
| 149 | + if (Error err = valobj.Dump(result.GetOutputStream(), dump_options)) |
| 150 | + return err; |
154 | 151 | } |
155 | 152 | m_interpreter.PrintWarningsIfNecessary(result.GetOutputStream(), |
156 | 153 | m_cmd_name); |
157 | 154 | result.SetStatus(eReturnStatusSuccessFinishResult); |
| 155 | + return Error::success(); |
158 | 156 | }; |
159 | 157 |
|
160 | 158 | // First, try `expr` as a _limited_ frame variable expression path: only the |
@@ -188,8 +186,13 @@ void CommandObjectDWIMPrint::DoExecute(StringRef command, |
188 | 186 | expr); |
189 | 187 | } |
190 | 188 |
|
191 | | - dump_val_object(*valobj_sp); |
192 | | - return; |
| 189 | + Error err = dump_val_object(*valobj_sp); |
| 190 | + if (!err) |
| 191 | + return; |
| 192 | + |
| 193 | + // Dump failed, continue on to expression evaluation. |
| 194 | + LLDB_LOG_ERROR(GetLog(LLDBLog::Expressions), std::move(err), |
| 195 | + "could not print frame variable '{1}': {0}", expr); |
193 | 196 | } |
194 | 197 | } |
195 | 198 |
|
@@ -235,8 +238,14 @@ void CommandObjectDWIMPrint::DoExecute(StringRef command, |
235 | 238 | if (auto *state = target.GetPersistentExpressionStateForLanguage(language)) |
236 | 239 | if (auto var_sp = state->GetVariable(expr)) |
237 | 240 | if (auto valobj_sp = var_sp->GetValueObject()) { |
238 | | - dump_val_object(*valobj_sp); |
239 | | - return; |
| 241 | + Error err = dump_val_object(*valobj_sp); |
| 242 | + if (!err) |
| 243 | + return; |
| 244 | + |
| 245 | + // Dump failed, continue on to expression evaluation. |
| 246 | + LLDB_LOG_ERROR(GetLog(LLDBLog::Expressions), std::move(err), |
| 247 | + "could not print persistent variable '{1}': {0}", |
| 248 | + expr); |
240 | 249 | } |
241 | 250 |
|
242 | 251 | // Third, and lastly, try `expr` as a source expression to evaluate. |
@@ -287,10 +296,12 @@ void CommandObjectDWIMPrint::DoExecute(StringRef command, |
287 | 296 | result.AppendNoteWithFormatv("ran `expression {0}{1}`", flags, expr); |
288 | 297 | } |
289 | 298 |
|
290 | | - if (valobj_sp->GetError().GetError() != UserExpression::kNoResult) |
291 | | - dump_val_object(*valobj_sp); |
292 | | - else |
293 | | - result.SetStatus(eReturnStatusSuccessFinishResult); |
| 299 | + if (valobj_sp->GetError().GetError() != UserExpression::kNoResult) { |
| 300 | + if (Error err = dump_val_object(*valobj_sp)) |
| 301 | + result.SetError(std::move(err)); |
| 302 | + } else { |
| 303 | + result.SetStatus(eReturnStatusSuccessFinishNoResult); |
| 304 | + } |
294 | 305 |
|
295 | 306 | if (suppress_result) |
296 | 307 | if (auto result_var_sp = |
|
0 commit comments