-
Notifications
You must be signed in to change notification settings - Fork 14.9k
[lldb/API] Mark SBValue with error as invalid #158759
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
base: main
Are you sure you want to change the base?
Conversation
@llvm/pr-subscribers-lldb Author: Med Ismail Bennani (medismailben) ChangesThis patch fixes the return value of That alignes better the expectation that an Full diff: https://github.com/llvm/llvm-project/pull/158759.diff 3 Files Affected:
diff --git a/lldb/source/API/SBValue.cpp b/lldb/source/API/SBValue.cpp
index e300ecee3f8ac..77cc7d1681829 100644
--- a/lldb/source/API/SBValue.cpp
+++ b/lldb/source/API/SBValue.cpp
@@ -97,7 +97,8 @@ class ValueImpl {
// they depend on. So I have no good way to make that check without
// tracking that in all the ValueObject subclasses.
TargetSP target_sp = m_valobj_sp->GetTargetSP();
- return target_sp && target_sp->IsValid();
+ return target_sp && target_sp->IsValid() &&
+ m_valobj_sp->GetError().Success();
}
}
diff --git a/lldb/test/API/python_api/sbvalue_is_valid/TestSBValueIsValid.py b/lldb/test/API/python_api/sbvalue_is_valid/TestSBValueIsValid.py
new file mode 100644
index 0000000000000..a3d43c1bdeeb2
--- /dev/null
+++ b/lldb/test/API/python_api/sbvalue_is_valid/TestSBValueIsValid.py
@@ -0,0 +1,3 @@
+import lldbsuite.test.lldbinline as lldbinline
+
+lldbinline.MakeInlineTest(__file__, globals())
diff --git a/lldb/test/API/python_api/sbvalue_is_valid/main.cpp b/lldb/test/API/python_api/sbvalue_is_valid/main.cpp
new file mode 100644
index 0000000000000..2a1dfe06faa77
--- /dev/null
+++ b/lldb/test/API/python_api/sbvalue_is_valid/main.cpp
@@ -0,0 +1,6 @@
+int main () {
+ int i = 42;
+ return 0; //% v1 = self.frame().EvaluateExpression("test"); v2 = self.frame().EvaluateExpression("i");
+ //% self.assertFalse(v1.IsValid())
+ //% self.assertTrue(v2.IsValid())
+}
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
4dfdf37
to
9744d60
Compare
I fixed the formatting and most of the failures. I only need to find the right way to return the errors through DAP: prior to this change, errors were returned as part of the value object string, since the object was still considered valid but now that it's marked invalid, the return string is empty. @JDevlieghere what would be the right approach here ? |
9744d60
to
b204ad1
Compare
This patch fixes the return value of `SBValue::IsValid` if `GetError` returns a failing `SBError`. That alignes better the expectation that an `SBValue` is invalid if it has an error. Signed-off-by: Med Ismail Bennani <[email protected]>
b204ad1
to
2df7756
Compare
I was under the impression that these two ( @adrian-prantl / @jimingham Do I misremember? |
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.
This doesn't sound like a good idea to me. IsValid means "will I get meaningful information back if I ask a question of this object". You certainly want to know whether the Error state of the SBValue is in fact valid. So an SBValue with valid error information should always be in the IsValid = true state.
Note, another way to do this would be to have default constructed SBValues have a Failed error state of "Nothing in me now". Then you could dispense with SBValie.IsValid altogether, since there wouldn't be any SBValues that don't at least have valid error states. |
This behavior is counterintuitive. Once you have an In C++, That makes IsValid() in its current form effectively useless: it never provides actionable information. Since we cannot remove |
I'm not sure I follow this argument. You talk about |
My argument is that given that
|
This patch fixes the return value of
SBValue::IsValid
ifGetError
returns a failingSBError
.That alignes better the expectation that an
SBValue
is invalid if it has an error.