-
Notifications
You must be signed in to change notification settings - Fork 14.9k
[lldb] Print ValueObject when GetObjectDescription fails #152417
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] Print ValueObject when GetObjectDescription fails #152417
Conversation
@llvm/pr-subscribers-lldb Author: Dave Lee (kastiglione) ChangesFull diff: https://github.com/llvm/llvm-project/pull/152417.diff 1 Files Affected:
diff --git a/lldb/source/DataFormatters/ValueObjectPrinter.cpp b/lldb/source/DataFormatters/ValueObjectPrinter.cpp
index c2f8bb3ea05bc..c5a6de2de35f2 100644
--- a/lldb/source/DataFormatters/ValueObjectPrinter.cpp
+++ b/lldb/source/DataFormatters/ValueObjectPrinter.cpp
@@ -9,6 +9,7 @@
#include "lldb/DataFormatters/ValueObjectPrinter.h"
#include "lldb/DataFormatters/DataVisualization.h"
+#include "lldb/Expression/DiagnosticManager.h"
#include "lldb/Interpreter/CommandInterpreter.h"
#include "lldb/Target/Language.h"
#include "lldb/Target/Target.h"
@@ -150,6 +151,11 @@ llvm::Expected<std::string> ValueObjectPrinter::GetDescriptionForDisplay() {
if (maybe_str)
return maybe_str;
+ if (maybe_str.errorIsA<lldb_private::ExpressionError>())
+ // Propagate expression errors to expose diagnostics to the user.
+ // Without this early exit, the summary/value may be shown without errors.
+ return maybe_str;
+
const char *str = nullptr;
if (!str)
str = valobj.GetSummaryAsCString();
|
If this change is accepted, I will also revert #151374 |
// Propagate expression errors to expose diagnostics to the user. | ||
// Without this early exit, the summary/value may be shown without errors. | ||
return maybe_str; | ||
|
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.
Would this be testable by running an expression that fails reliably? For example by implementing a [-description] method that crashes?
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.
Unfortunately no
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.
@adrian-prantl I've added a test for this with the recent reworking. See TestObjCFailingDescription.py
The way we've been doing the
So it's supposed to handle the case where we haven't yet printed any value or summary for the Is that your intent? |
I think it would be more in line with user's expectations if, instead of directly returning maybe_string in this case, you build a new string that has:
or something like that. |
Our experience is that people think |
The ultimate intent is to show errors preventing an expected successful object description. If producing an object description fails, printing an object's address (value) is not what users expect. We can change this to print the error and the value, but I don't expect any users to find any use from the value/address when their intended |
it's my intent when the failure is a compiler reason – which is to make a distinction that this is a more narrow change than "some reason". |
I don't like the usage pattern, but I know there are a substantial number of Darwin developers who ONLY know So I'm not sure that slice of our users would be happy with this change. OTOH, since I'm not a fan of that usage pattern, I don't myself care one way or the other. I'll happily direct their complaints to you ;-) |
Following a offline conversation with Jim, I've updated this PR. See the description for details on the changes. |
You said above that this code wouldn't get used if the description expression crashed. Why is that? Even if we can't get a diagnostic error from the crash process, it would be nice to use this same codepath to do:
or something? If it did that we could also write a test here, which would make this feel better... The code looks okay except it would be nice to change all the places where we're saying "DisableObjectiveC" to say "DisableObjectDescription" or something (and It will look really silly when this goes to the swift fork and we're using |
Originally, that was the case.
agree, and it does so. I was in the process of writing tests, which I've now added. |
I've renamed the various use_objc names to use_object_desc. |
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.
LGTM
This case looks like:
|
This fixes a few bugs, effectively through a fallback to `p` when `po` fails. The motivating bug this fixes is when an error within the compiler causes `po` to fail. Previously when that happened, only its value (typically an object's address) was printed – and problematically, no compiler diagnostics were shown. With this change, compiler diagnostics are shown, _and_ the object is fully printed (ie `p`). Another bug this fixes is when `po` is used on a type that doesn't provide an object description (such as a struct). Again, the normal `ValueObject` printing is used. Additionally, this also improves how lldb handles an object description method that fails in some way. Now an error will be shown (it wasn't before), and the value will be printed normally. (cherry picked from commit ae7e1b8)
…riable fails in dwim-print" (#153824) Reverts llvm/llvm-project#151374 Superseded by llvm/llvm-project#152417
This fixes a few bugs, effectively through a fallback to `p` when `po` fails. The motivating bug this fixes is when an error within the compiler causes `po` to fail. Previously when that happened, only its value (typically an object's address) was printed – and problematically, no compiler diagnostics were shown. With this change, compiler diagnostics are shown, _and_ the object is fully printed (ie `p`). Another bug this fixes is when `po` is used on a type that doesn't provide an object description (such as a struct). Again, the normal `ValueObject` printing is used. Additionally, this also improves how lldb handles an object description method that fails in some way. Now an error will be shown (it wasn't before), and the value will be printed normally. (cherry picked from commit ae7e1b8)
This fixes a few bugs, effectively through a fallback to `p` when `po` fails. The motivating bug this fixes is when an error within the compiler causes `po` to fail. Previously when that happened, only its value (typically an object's address) was printed – and problematically, no compiler diagnostics were shown. With this change, compiler diagnostics are shown, _and_ the object is fully printed (ie `p`). Another bug this fixes is when `po` is used on a type that doesn't provide an object description (such as a struct). Again, the normal `ValueObject` printing is used. Additionally, this also improves how lldb handles an object description method that fails in some way. Now an error will be shown (it wasn't before), and the value will be printed normally. (cherry picked from commit ae7e1b8)
This fixes a few bugs, effectively through a fallback to
p
whenpo
fails.The motivating bug this fixes is when an error within the compiler causes
po
to fail. Previously when that happened, only its value (typically an object's address) was printed – and problematically, no compiler diagnostics were shown. With this change, compiler diagnostics are shown, and the object is fully printed (iep
).Another bug this fixes is when
po
is used on a type that doesn't provide an object description (such as a struct). Again, the normalValueObject
printing is used.Additionally, this also improves how lldb handles an object description method that fails in some way. Now an error will be shown (it wasn't before), and the value will be printed normally.