-
Notifications
You must be signed in to change notification settings - Fork 14.8k
[lldb] Fallback to expression eval when Dump of variable fails in dwim-print #151374
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[lldb] Fallback to expression eval when Dump of variable fails in dwim-print #151374
Conversation
@llvm/pr-subscribers-lldb Author: Dave Lee (kastiglione) ChangesFull diff: https://github.com/llvm/llvm-project/pull/151374.diff 1 Files Affected:
diff --git a/lldb/source/Commands/CommandObjectDWIMPrint.cpp b/lldb/source/Commands/CommandObjectDWIMPrint.cpp
index a2c004d0ee97f..5b788d7d0c5a2 100644
--- a/lldb/source/Commands/CommandObjectDWIMPrint.cpp
+++ b/lldb/source/Commands/CommandObjectDWIMPrint.cpp
@@ -23,6 +23,7 @@
#include "lldb/lldb-enumerations.h"
#include "lldb/lldb-forward.h"
#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Error.h"
#include <regex>
@@ -132,27 +133,22 @@ void CommandObjectDWIMPrint::DoExecute(StringRef command,
};
// Dump `valobj` according to whether `po` was requested or not.
- auto dump_val_object = [&](ValueObject &valobj) {
+ auto dump_val_object = [&](ValueObject &valobj) -> Error {
if (is_po) {
StreamString temp_result_stream;
- if (llvm::Error error = valobj.Dump(temp_result_stream, dump_options)) {
- result.AppendError(toString(std::move(error)));
- return;
- }
+ if (Error err = valobj.Dump(temp_result_stream, dump_options))
+ return err;
llvm::StringRef output = temp_result_stream.GetString();
maybe_add_hint(output);
result.GetOutputStream() << output;
} else {
- llvm::Error error =
- valobj.Dump(result.GetOutputStream(), dump_options);
- if (error) {
- result.AppendError(toString(std::move(error)));
- return;
- }
+ if (Error err = valobj.Dump(result.GetOutputStream(), dump_options))
+ return err;
}
m_interpreter.PrintWarningsIfNecessary(result.GetOutputStream(),
m_cmd_name);
result.SetStatus(eReturnStatusSuccessFinishResult);
+ return Error::success();
};
// First, try `expr` as a _limited_ frame variable expression path: only the
@@ -186,8 +182,11 @@ void CommandObjectDWIMPrint::DoExecute(StringRef command,
expr);
}
- dump_val_object(*valobj_sp);
- return;
+ bool failed = errorToBool(dump_val_object(*valobj_sp));
+ if (!failed)
+ return;
+
+ // Dump failed, continue on to expression evaluation.
}
}
@@ -196,8 +195,9 @@ void CommandObjectDWIMPrint::DoExecute(StringRef command,
if (auto *state = target.GetPersistentExpressionStateForLanguage(language))
if (auto var_sp = state->GetVariable(expr))
if (auto valobj_sp = var_sp->GetValueObject()) {
- dump_val_object(*valobj_sp);
- return;
+ bool failed = errorToBool(dump_val_object(*valobj_sp));
+ if (!failed)
+ return;
}
// Third, and lastly, try `expr` as a source expression to evaluate.
@@ -248,10 +248,12 @@ void CommandObjectDWIMPrint::DoExecute(StringRef command,
result.AppendNoteWithFormatv("ran `expression {0}{1}`", flags, expr);
}
- if (valobj_sp->GetError().GetError() != UserExpression::kNoResult)
- dump_val_object(*valobj_sp);
- else
+ if (valobj_sp->GetError().GetError() != UserExpression::kNoResult) {
+ if (Error err = dump_val_object(*valobj_sp))
+ result.SetError(std::move(err));
+ } else {
result.SetStatus(eReturnStatusSuccessFinishNoResult);
+ }
if (suppress_result)
if (auto result_var_sp =
|
return; | ||
|
||
// Dump failed, continue on to expression evaluation. | ||
LLDB_LOG_ERROR(GetLog(LLDBLog::Expressions), std::move(err), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm confused about the order of the arguments to this macro. The error comes first, then the format string, then the other parameter?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yup – error, format, params
…m-print (llvm#151374) Previously, when dwim-print finds a frame variables, it returns immediately after calling `Dump`, even if `Dump` returns an error. This is most likely to happen when evaluating an object description, ie `po`. This changes dwim-print to continue on to expression evaluation when `Dump`ing a variable returns an error . This is to allow for diagnostics that match `expression`. (cherry picked from commit f23c10f)
…m-print (llvm#151374) Previously, when dwim-print finds a frame variables, it returns immediately after calling `Dump`, even if `Dump` returns an error. This is most likely to happen when evaluating an object description, ie `po`. This changes dwim-print to continue on to expression evaluation when `Dump`ing a variable returns an error . This is to allow for diagnostics that match `expression`.
…riable fails in dwim-print" (#153824) Reverts llvm/llvm-project#151374 Superseded by llvm/llvm-project#152417
Previously, when dwim-print finds a frame variables, it returns immediately after calling
Dump
, even ifDump
returns an error. This is most likely to happen when evaluating an object description, iepo
.This changes dwim-print to continue on to expression evaluation when
Dump
ing a variable returns an error . This is to allow for more complete diagnostics whenpo
fails.