[Lldb-commits] [lldb] [lldb] Fix a regression in SBValue::GetObjectDescription() (PR #117242)
Adrian Prantl via lldb-commits
lldb-commits at lists.llvm.org
Thu Nov 21 13:48:23 PST 2024
https://github.com/adrian-prantl updated https://github.com/llvm/llvm-project/pull/117242
>From e4a6563c21c251954b077a27b8375028134aa2f8 Mon Sep 17 00:00:00 2001
From: Adrian Prantl <aprantl at apple.com>
Date: Thu, 21 Nov 2024 13:14:29 -0800
Subject: [PATCH] [lldb] Fix a regression in SBValue::GetObjectDescription()
The old behavior was to return a null string in the error case,when
refactoring the error handling I thought it would be a good idea to
print the error in the description, but that breaks clients that try
to print a description first and then do something else in the error
case. The API is not great but it's clear that in-band errors are also
not a good idea.
rdar://133956263
---
lldb/source/API/SBValue.cpp | 6 ++++--
.../commands/expression/diagnostics/TestExprDiagnostics.py | 5 +++++
2 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/lldb/source/API/SBValue.cpp b/lldb/source/API/SBValue.cpp
index b35c82250d6ba1..a707b9aa7589c7 100644
--- a/lldb/source/API/SBValue.cpp
+++ b/lldb/source/API/SBValue.cpp
@@ -380,8 +380,10 @@ const char *SBValue::GetObjectDescription() {
return nullptr;
llvm::Expected<std::string> str = value_sp->GetObjectDescription();
- if (!str)
- return ConstString("error: " + toString(str.takeError())).AsCString();
+ if (!str) {
+ llvm::consumeError(str.takeError());
+ return nullptr;
+ }
return ConstString(*str).AsCString();
}
diff --git a/lldb/test/API/commands/expression/diagnostics/TestExprDiagnostics.py b/lldb/test/API/commands/expression/diagnostics/TestExprDiagnostics.py
index b9b5bffb87e817..acba37fcf50fcf 100644
--- a/lldb/test/API/commands/expression/diagnostics/TestExprDiagnostics.py
+++ b/lldb/test/API/commands/expression/diagnostics/TestExprDiagnostics.py
@@ -195,6 +195,11 @@ def test_error_type(self):
value = frame.EvaluateExpression('#error("I am error.")')
error = value.GetError()
self.assertEqual(error.GetType(), lldb.eErrorTypeExpression)
+ value = frame.FindVariable('f')
+ self.assertTrue(value.IsValid())
+ desc = value.GetObjectDescription()
+ self.assertEqual(desc, None)
+
def test_command_expr_sbdata(self):
"""Test the structured diagnostics data"""
More information about the lldb-commits
mailing list