[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:54:33 PST 2024


https://github.com/adrian-prantl updated https://github.com/llvm/llvm-project/pull/117242

>From dc8c3877594a513329a2b920b31f314684e6337c 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  | 6 +++++-
 2 files changed, 9 insertions(+), 3 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..e1f1d8c83b632b 100644
--- a/lldb/test/API/commands/expression/diagnostics/TestExprDiagnostics.py
+++ b/lldb/test/API/commands/expression/diagnostics/TestExprDiagnostics.py
@@ -194,7 +194,11 @@ def test_error_type(self):
         frame = thread.GetFrameAtIndex(0)
         value = frame.EvaluateExpression('#error("I am error.")')
         error = value.GetError()
-        self.assertEqual(error.GetType(), lldb.eErrorTypeExpression)
+        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