[Lldb-commits] [lldb] draft: [lldb] Upgrade ValueObject::GetData to return llvm::Expected (PR #130516)

Julius Alexandre via lldb-commits lldb-commits at lists.llvm.org
Wed Mar 26 19:48:46 PDT 2025


https://github.com/wizardengineer updated https://github.com/llvm/llvm-project/pull/130516

>From 161bdb32b284d2370b138e72a8a1ad560b258ba9 Mon Sep 17 00:00:00 2001
From: medievalghoul <61852278+medievalghoul at users.noreply.github.com>
Date: Sun, 9 Mar 2025 16:20:47 -0400
Subject: [PATCH 01/18] Change ValueObject::GetData to return llvm::Expected

---
 lldb/include/lldb/ValueObject/ValueObject.h   |  2 +-
 .../AppleObjCRuntime/AppleObjCRuntime.cpp     |  5 ++--
 .../TypeSystem/Clang/TypeSystemClang.cpp      | 12 ++++----
 lldb/source/ValueObject/ValueObject.cpp       | 28 +++++++++++++------
 4 files changed, 30 insertions(+), 17 deletions(-)

diff --git a/lldb/include/lldb/ValueObject/ValueObject.h b/lldb/include/lldb/ValueObject/ValueObject.h
index 06d2589002ed0..2ee7f99718416 100644
--- a/lldb/include/lldb/ValueObject/ValueObject.h
+++ b/lldb/include/lldb/ValueObject/ValueObject.h
@@ -757,7 +757,7 @@ class ValueObject {
   virtual size_t GetPointeeData(DataExtractor &data, uint32_t item_idx = 0,
                                 uint32_t item_count = 1);
 
-  virtual uint64_t GetData(DataExtractor &data, Status &error);
+  virtual llvm::Expected<DataExtractor> GetData();
 
   virtual bool SetData(DataExtractor &data, Status &error);
 
diff --git a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp
index ad60290382c02..69856d4592843 100644
--- a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp
+++ b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp
@@ -551,9 +551,8 @@ ThreadSP AppleObjCRuntime::GetBacktraceThreadFromException(
 
     DataExtractor data;
     data.SetAddressByteSize(dict_entry->GetProcessSP()->GetAddressByteSize());
-    Status error;
-    dict_entry->GetData(data, error);
-    if (error.Fail()) return ThreadSP();
+    auto data_or_err = dict_entry->GetData();
+    if (!data_or_err) return ThreadSP();
 
     lldb::offset_t data_offset = 0;
     auto dict_entry_key = data.GetAddress(&data_offset);
diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
index 4ca4752310868..763a80faa914a 100644
--- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
+++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
@@ -247,13 +247,15 @@ static lldb::addr_t GetVTableAddress(Process &process,
   // We have an object already read from process memory,
   // so just extract VTable pointer from it
 
-  DataExtractor data;
-  Status err;
-  auto size = valobj.GetData(data, err);
-  if (err.Fail() || vbtable_ptr_offset + data.GetAddressByteSize() > size)
+  auto data_or_err = valobj.GetData();
+  if (!data_or_err)
+    return LLDB_INVALID_ADDRESS;
+
+  auto size = data_or_err->GetByteSize();
+  if (vbtable_ptr_offset + data_or_err->GetAddressByteSize() > size)
     return LLDB_INVALID_ADDRESS;
 
-  return data.GetAddress(&vbtable_ptr_offset);
+  return data_or_err->GetAddress(&vbtable_ptr_offset);
 }
 
 static int64_t ReadVBaseOffsetFromVTable(Process &process,
diff --git a/lldb/source/ValueObject/ValueObject.cpp b/lldb/source/ValueObject/ValueObject.cpp
index eac24353de90b..05cbc5489d25e 100644
--- a/lldb/source/ValueObject/ValueObject.cpp
+++ b/lldb/source/ValueObject/ValueObject.cpp
@@ -691,13 +691,20 @@ size_t ValueObject::GetPointeeData(DataExtractor &data, uint32_t item_idx,
       ValueObjectSP pointee_sp = Dereference(error);
       if (error.Fail() || pointee_sp.get() == nullptr)
         return 0;
-      return pointee_sp->GetData(data, error);
+      auto data_or_err = pointee_sp->GetData();
+      if (!data_or_err)
+        return 0;
+      data = *data_or_err;
+      return data.GetByteSize();
     } else {
       ValueObjectSP child_sp = GetChildAtIndex(0);
       if (child_sp.get() == nullptr)
         return 0;
-      Status error;
-      return child_sp->GetData(data, error);
+      auto data_or_err = child_sp->GetData();
+      if (!data_or_err)
+        return 0;
+      data = *data_or_err;
+      return data.GetByteSize();
     }
     return true;
   } else /* (items > 1) */
@@ -764,22 +771,27 @@ size_t ValueObject::GetPointeeData(DataExtractor &data, uint32_t item_idx,
   return 0;
 }
 
-uint64_t ValueObject::GetData(DataExtractor &data, Status &error) {
+llvm::Expected<DataExtractor> ValueObject::GetData() {
   UpdateValueIfNeeded(false);
   ExecutionContext exe_ctx(GetExecutionContextRef());
-  error = m_value.GetValueAsData(&exe_ctx, data, GetModule().get());
+  DataExtractor data;
+  Status error = m_value.GetValueAsData(&exe_ctx, data, GetModule().get());
   if (error.Fail()) {
     if (m_data.GetByteSize()) {
       data = m_data;
       error.Clear();
-      return data.GetByteSize();
+      data.SetAddressByteSize(m_data.GetAddressByteSize());
+      data.SetByteOrder(m_data.GetByteOrder());
+      return data;
     } else {
-      return 0;
+      return llvm::createStringError(
+          "GetData failed: %s",
+          error.AsCString());
     }
   }
   data.SetAddressByteSize(m_data.GetAddressByteSize());
   data.SetByteOrder(m_data.GetByteOrder());
-  return data.GetByteSize();
+  return data;
 }
 
 bool ValueObject::SetData(DataExtractor &data, Status &error) {

>From 7d886e2bee159d6bbe00cec9fd4004f4d71993bf Mon Sep 17 00:00:00 2001
From: medievalghoul <61852278+medievalghoul at users.noreply.github.com>
Date: Sun, 9 Mar 2025 16:43:56 -0400
Subject: [PATCH 02/18] clang format

---
 .../ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp                | 3 ++-
 lldb/source/ValueObject/ValueObject.cpp                       | 4 +---
 2 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp
index 69856d4592843..648e061f3e3c5 100644
--- a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp
+++ b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp
@@ -552,7 +552,8 @@ ThreadSP AppleObjCRuntime::GetBacktraceThreadFromException(
     DataExtractor data;
     data.SetAddressByteSize(dict_entry->GetProcessSP()->GetAddressByteSize());
     auto data_or_err = dict_entry->GetData();
-    if (!data_or_err) return ThreadSP();
+    if (!data_or_err)
+      return ThreadSP();
 
     lldb::offset_t data_offset = 0;
     auto dict_entry_key = data.GetAddress(&data_offset);
diff --git a/lldb/source/ValueObject/ValueObject.cpp b/lldb/source/ValueObject/ValueObject.cpp
index 05cbc5489d25e..4d13e460a2ca7 100644
--- a/lldb/source/ValueObject/ValueObject.cpp
+++ b/lldb/source/ValueObject/ValueObject.cpp
@@ -784,9 +784,7 @@ llvm::Expected<DataExtractor> ValueObject::GetData() {
       data.SetByteOrder(m_data.GetByteOrder());
       return data;
     } else {
-      return llvm::createStringError(
-          "GetData failed: %s",
-          error.AsCString());
+      return llvm::createStringError("GetData failed: %s", error.AsCString());
     }
   }
   data.SetAddressByteSize(m_data.GetAddressByteSize());

>From c6d271b8b3e966c3a0f8548b2362668b05fc6f33 Mon Sep 17 00:00:00 2001
From: medievalghoul <61852278+medievalghoul at users.noreply.github.com>
Date: Sun, 9 Mar 2025 17:17:50 -0400
Subject: [PATCH 03/18] more changes

---
 .../Language/CPlusPlus/CxxStringTypes.cpp        | 16 ++++++----------
 .../Plugins/Language/CPlusPlus/LibCxxList.cpp    | 16 ++++++----------
 lldb/source/Plugins/Language/ObjC/Cocoa.cpp      |  8 +++-----
 lldb/source/Plugins/Language/ObjC/NSString.cpp   |  8 +++-----
 .../ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp   |  7 +++----
 5 files changed, 21 insertions(+), 34 deletions(-)

diff --git a/lldb/source/Plugins/Language/CPlusPlus/CxxStringTypes.cpp b/lldb/source/Plugins/Language/CPlusPlus/CxxStringTypes.cpp
index fc17b76804d9f..c7d4b650d7819 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/CxxStringTypes.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/CxxStringTypes.cpp
@@ -68,11 +68,9 @@ static bool CharStringSummaryProvider(ValueObject &valobj, Stream &stream) {
 
 template <StringElementType ElemType>
 static bool CharSummaryProvider(ValueObject &valobj, Stream &stream) {
-  DataExtractor data;
-  Status error;
-  valobj.GetData(data, error);
+  auto data_or_err = valobj.GetData();
 
-  if (error.Fail())
+  if (!data_or_err)
     return false;
 
   std::string value;
@@ -84,7 +82,7 @@ static bool CharSummaryProvider(ValueObject &valobj, Stream &stream) {
   if (!value.empty())
     stream.Printf("%s ", value.c_str());
 
-  options.SetData(std::move(data));
+  options.SetData(std::move(*data_or_err));
   options.SetStream(&stream);
   options.SetPrefixToken(ElemTraits.first);
   options.SetQuote('\'');
@@ -169,11 +167,9 @@ bool lldb_private::formatters::Char32SummaryProvider(
 
 bool lldb_private::formatters::WCharSummaryProvider(
     ValueObject &valobj, Stream &stream, const TypeSummaryOptions &) {
-  DataExtractor data;
-  Status error;
-  valobj.GetData(data, error);
+  auto data_or_err = valobj.GetData();
 
-  if (error.Fail())
+  if (!data_or_err)
     return false;
 
   // Get a wchar_t basic type from the current type system
@@ -191,7 +187,7 @@ bool lldb_private::formatters::WCharSummaryProvider(
   const uint32_t wchar_size = *size;
 
   StringPrinter::ReadBufferAndDumpToStreamOptions options(valobj);
-  options.SetData(std::move(data));
+  options.SetData(std::move(*data_or_err));
   options.SetStream(&stream);
   options.SetPrefixToken("L");
   options.SetQuote('\'');
diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxxList.cpp b/lldb/source/Plugins/Language/CPlusPlus/LibCxxList.cpp
index ae1ad2bfe7200..12a5ff39382ca 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/LibCxxList.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxxList.cpp
@@ -273,13 +273,11 @@ ValueObjectSP ForwardListFrontEnd::GetChildAtIndex(uint32_t idx) {
 
   // we need to copy current_sp into a new object otherwise we will end up with
   // all items named __value_
-  DataExtractor data;
-  Status error;
-  current_sp->GetData(data, error);
-  if (error.Fail())
+  auto data_or_err = current_sp->GetData();
+  if (!data_or_err)
     return nullptr;
 
-  return CreateValueObjectFromData(llvm::formatv("[{0}]", idx).str(), data,
+  return CreateValueObjectFromData(llvm::formatv("[{0}]", idx).str(), *data_or_err,
                                    m_backend.GetExecutionContextRef(),
                                    m_element_type);
 }
@@ -394,15 +392,13 @@ lldb::ValueObjectSP ListFrontEnd::GetChildAtIndex(uint32_t idx) {
 
   // we need to copy current_sp into a new object otherwise we will end up with
   // all items named __value_
-  DataExtractor data;
-  Status error;
-  current_sp->GetData(data, error);
-  if (error.Fail())
+  auto data_or_err = current_sp->GetData();
+  if (!data_or_err)
     return lldb::ValueObjectSP();
 
   StreamString name;
   name.Printf("[%" PRIu64 "]", (uint64_t)idx);
-  return CreateValueObjectFromData(name.GetString(), data,
+  return CreateValueObjectFromData(name.GetString(), *data_or_err,
                                    m_backend.GetExecutionContextRef(),
                                    m_element_type);
 }
diff --git a/lldb/source/Plugins/Language/ObjC/Cocoa.cpp b/lldb/source/Plugins/Language/ObjC/Cocoa.cpp
index 1d79edbede5d6..8c2582355e524 100644
--- a/lldb/source/Plugins/Language/ObjC/Cocoa.cpp
+++ b/lldb/source/Plugins/Language/ObjC/Cocoa.cpp
@@ -1205,13 +1205,11 @@ bool lldb_private::formatters::ObjCSELSummaryProvider(
     valobj_sp = ValueObject::CreateValueObjectFromAddress("text", data_address,
                                                           exe_ctx, charstar);
   } else {
-    DataExtractor data;
-    Status error;
-    valobj.GetData(data, error);
-    if (error.Fail())
+    auto data_or_err = valobj.GetData();
+    if (!data_or_err)
       return false;
     valobj_sp =
-        ValueObject::CreateValueObjectFromData("text", data, exe_ctx, charstar);
+        ValueObject::CreateValueObjectFromData("text", *data_or_err, exe_ctx, charstar);
   }
 
   if (!valobj_sp)
diff --git a/lldb/source/Plugins/Language/ObjC/NSString.cpp b/lldb/source/Plugins/Language/ObjC/NSString.cpp
index a99d042572bfe..5b6a22c6e6b6c 100644
--- a/lldb/source/Plugins/Language/ObjC/NSString.cpp
+++ b/lldb/source/Plugins/Language/ObjC/NSString.cpp
@@ -291,13 +291,11 @@ bool lldb_private::formatters::NSAttributedStringSummaryProvider(
       "string_ptr", pointer_value, exe_ctx, type));
   if (!child_ptr_sp)
     return false;
-  DataExtractor data;
-  Status error;
-  child_ptr_sp->GetData(data, error);
-  if (error.Fail())
+  auto data_or_err = child_ptr_sp->GetData();
+  if (!data_or_err)
     return false;
   ValueObjectSP child_sp(child_ptr_sp->CreateValueObjectFromData(
-      "string_data", data, exe_ctx, type));
+      "string_data", *data_or_err, exe_ctx, type));
   child_sp->GetValueAsUnsigned(0);
   if (child_sp)
     return NSStringSummaryProvider(*child_sp, stream, options);
diff --git a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp
index 648e061f3e3c5..b82bdf52e186e 100644
--- a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp
+++ b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp
@@ -549,15 +549,14 @@ ThreadSP AppleObjCRuntime::GetBacktraceThreadFromException(
        idx++) {
     ValueObjectSP dict_entry = reserved_dict->GetChildAtIndex(idx);
 
-    DataExtractor data;
-    data.SetAddressByteSize(dict_entry->GetProcessSP()->GetAddressByteSize());
     auto data_or_err = dict_entry->GetData();
     if (!data_or_err)
       return ThreadSP();
+    data_or_err->SetAddressByteSize(dict_entry->GetProcessSP()->GetAddressByteSize());
 
     lldb::offset_t data_offset = 0;
-    auto dict_entry_key = data.GetAddress(&data_offset);
-    auto dict_entry_value = data.GetAddress(&data_offset);
+    auto dict_entry_key = data_or_err->GetAddress(&data_offset);
+    auto dict_entry_value = data_or_err->GetAddress(&data_offset);
 
     auto key_nsstring = objc_object_from_address(dict_entry_key, "key");
     StreamString key_summary;

>From ac8dacc3b351dafb65987e67711a689970af4a4d Mon Sep 17 00:00:00 2001
From: medievalghoul <61852278+medievalghoul at users.noreply.github.com>
Date: Sun, 9 Mar 2025 18:10:30 -0400
Subject: [PATCH 04/18] format

---
 lldb/source/Plugins/Language/CPlusPlus/LibCxxList.cpp       | 6 +++---
 lldb/source/Plugins/Language/ObjC/Cocoa.cpp                 | 4 ++--
 .../ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp              | 3 ++-
 3 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxxList.cpp b/lldb/source/Plugins/Language/CPlusPlus/LibCxxList.cpp
index 12a5ff39382ca..4e2775c5ca266 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/LibCxxList.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxxList.cpp
@@ -277,9 +277,9 @@ ValueObjectSP ForwardListFrontEnd::GetChildAtIndex(uint32_t idx) {
   if (!data_or_err)
     return nullptr;
 
-  return CreateValueObjectFromData(llvm::formatv("[{0}]", idx).str(), *data_or_err,
-                                   m_backend.GetExecutionContextRef(),
-                                   m_element_type);
+  return CreateValueObjectFromData(
+      llvm::formatv("[{0}]", idx).str(), *data_or_err,
+      m_backend.GetExecutionContextRef(), m_element_type);
 }
 
 lldb::ChildCacheState ForwardListFrontEnd::Update() {
diff --git a/lldb/source/Plugins/Language/ObjC/Cocoa.cpp b/lldb/source/Plugins/Language/ObjC/Cocoa.cpp
index 8c2582355e524..ebb36b52af0dd 100644
--- a/lldb/source/Plugins/Language/ObjC/Cocoa.cpp
+++ b/lldb/source/Plugins/Language/ObjC/Cocoa.cpp
@@ -1208,8 +1208,8 @@ bool lldb_private::formatters::ObjCSELSummaryProvider(
     auto data_or_err = valobj.GetData();
     if (!data_or_err)
       return false;
-    valobj_sp =
-        ValueObject::CreateValueObjectFromData("text", *data_or_err, exe_ctx, charstar);
+    valobj_sp = ValueObject::CreateValueObjectFromData("text", *data_or_err,
+                                                       exe_ctx, charstar);
   }
 
   if (!valobj_sp)
diff --git a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp
index b82bdf52e186e..c35e29773ecfe 100644
--- a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp
+++ b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp
@@ -552,7 +552,8 @@ ThreadSP AppleObjCRuntime::GetBacktraceThreadFromException(
     auto data_or_err = dict_entry->GetData();
     if (!data_or_err)
       return ThreadSP();
-    data_or_err->SetAddressByteSize(dict_entry->GetProcessSP()->GetAddressByteSize());
+    data_or_err->SetAddressByteSize(
+        dict_entry->GetProcessSP()->GetAddressByteSize());
 
     lldb::offset_t data_offset = 0;
     auto dict_entry_key = data_or_err->GetAddress(&data_offset);

>From dc926356fd0738d78b0eaba7127d294a270b876a Mon Sep 17 00:00:00 2001
From: medievalghoul <61852278+medievalghoul at users.noreply.github.com>
Date: Mon, 10 Mar 2025 21:54:00 -0400
Subject: [PATCH 05/18] third wave of refactoring

---
 lldb/source/DataFormatters/TypeFormat.cpp     | 43 +++++++++++--------
 lldb/source/Expression/Materializer.cpp       | 36 +++++++---------
 .../Language/CPlusPlus/CxxStringTypes.cpp     |  4 +-
 .../Language/CPlusPlus/LibCxxUnorderedMap.cpp |  8 ++--
 .../TypeSystem/Clang/TypeSystemClang.cpp      |  6 ++-
 5 files changed, 52 insertions(+), 45 deletions(-)

diff --git a/lldb/source/DataFormatters/TypeFormat.cpp b/lldb/source/DataFormatters/TypeFormat.cpp
index f4cb8b46d272a..b829f855bf57d 100644
--- a/lldb/source/DataFormatters/TypeFormat.cpp
+++ b/lldb/source/DataFormatters/TypeFormat.cpp
@@ -46,18 +46,23 @@ bool TypeFormatImpl_Format::FormatObject(ValueObject *valobj,
     Value &value(valobj->GetValue());
     const Value::ContextType context_type = value.GetContextType();
     ExecutionContext exe_ctx(valobj->GetExecutionContextRef());
-    DataExtractor data;
 
+    auto data_or_err = valobj->GetData();
+    if (!data_or_err) {
+          LLDB_LOG_ERRORV(GetLog(LLDBLog::DataFormatters), data_or_err.takeError(), "Failed to extract data: {0}");
+          return false;
+        } 
     if (context_type == Value::ContextType::RegisterInfo) {
       const RegisterInfo *reg_info = value.GetRegisterInfo();
       if (reg_info) {
-        Status error;
-        valobj->GetData(data, error);
-        if (error.Fail())
+        auto data_or_err = valobj->GetData();
+        if (!data_or_err) {
+          LLDB_LOG_ERRORV(GetLog(LLDBLog::Process), data_or_err.takeError(), "Failed to extract data for register info: {0}");
           return false;
-
+        }
+          
         StreamString reg_sstr;
-        DumpDataExtractor(data, &reg_sstr, 0, GetFormat(), reg_info->byte_size,
+        DumpDataExtractor(*data_or_err, &reg_sstr, 0, GetFormat(), reg_info->byte_size,
                           1, UINT32_MAX, LLDB_INVALID_ADDRESS, 0, 0,
                           exe_ctx.GetBestExecutionContextScope());
         dest = std::string(reg_sstr.GetString());
@@ -84,13 +89,14 @@ bool TypeFormatImpl_Format::FormatObject(ValueObject *valobj,
               target_sp->ReadCStringFromMemory(
                   address, (char *)buffer_sp->GetBytes(), max_len, error);
               if (error.Success())
-                data.SetData(buffer_sp);
+                data_or_err->SetData(buffer_sp);
             }
           }
         } else {
-          Status error;
-          valobj->GetData(data, error);
-          if (error.Fail())
+          auto data_or_err = valobj->GetData();
+          if (!data_or_err)
+            LLDB_LOG_ERRORV(GetLog(LLDBLog::DataFormatters), data_or_err.takeError(),
+                "Failed to extract data for CString info to display: {0}:");
             return false;
         }
 
@@ -107,7 +113,7 @@ bool TypeFormatImpl_Format::FormatObject(ValueObject *valobj,
         compiler_type.DumpTypeValue(
             &sstr,                          // The stream to use for display
             GetFormat(),                    // Format to display this type with
-            data,                           // Data to extract from
+            *data_or_err,                   // Data to extract from
             0,                              // Byte offset into "m_data"
             *size_or_err,                   // Byte size of item in "m_data"
             valobj->GetBitfieldBitSize(),   // Bitfield bit size
@@ -184,15 +190,16 @@ bool TypeFormatImpl_EnumType::FormatObject(ValueObject *valobj,
     valobj_enum_type = iter->second;
   if (!valobj_enum_type.IsValid())
     return false;
-  DataExtractor data;
-  Status error;
-  valobj->GetData(data, error);
-  if (error.Fail())
+  auto data_or_err = valobj->GetData();
+  if (!data_or_err) {
+    LLDB_LOG_ERRORV(GetLog(LLDBLog::DataFormatters), data_or_err.takeError(),
+        "Can't extract data related to enum type info: {0}");
     return false;
-  ExecutionContext exe_ctx(valobj->GetExecutionContextRef());
+  }
+      ExecutionContext exe_ctx(valobj->GetExecutionContextRef());
   StreamString sstr;
-  valobj_enum_type.DumpTypeValue(&sstr, lldb::eFormatEnum, data, 0,
-                                 data.GetByteSize(), 0, 0,
+  valobj_enum_type.DumpTypeValue(&sstr, lldb::eFormatEnum, *data_or_err, 0,
+                                 data_or_err->GetByteSize(), 0, 0,
                                  exe_ctx.GetBestExecutionContextScope());
   if (!sstr.GetString().empty())
     dest = std::string(sstr.GetString());
diff --git a/lldb/source/Expression/Materializer.cpp b/lldb/source/Expression/Materializer.cpp
index 8d48b5e50041c..bf895f5e8853f 100644
--- a/lldb/source/Expression/Materializer.cpp
+++ b/lldb/source/Expression/Materializer.cpp
@@ -483,19 +483,17 @@ class EntityVariableBase : public Materializer::Entity {
     }
 
     if (m_is_reference) {
-      DataExtractor valobj_extractor;
-      Status extract_error;
-      valobj_sp->GetData(valobj_extractor, extract_error);
+      auto valobj_extractor_or_err = valobj_sp->GetData();
 
-      if (!extract_error.Success()) {
+      if (auto error = valobj_extractor_or_err.takeError()) {
         err = Status::FromErrorStringWithFormat(
             "couldn't read contents of reference variable %s: %s",
-            GetName().AsCString(), extract_error.AsCString());
+            GetName().AsCString(), llvm::toString(std::move(error)).c_str());
         return;
       }
 
       lldb::offset_t offset = 0;
-      lldb::addr_t reference_addr = valobj_extractor.GetAddress(&offset);
+      lldb::addr_t reference_addr = valobj_extractor_or_err->GetAddress(&offset);
 
       Status write_error;
       map.WritePointerToMemory(load_addr, reference_addr, write_error);
@@ -523,13 +521,11 @@ class EntityVariableBase : public Materializer::Entity {
           return;
         }
       } else {
-        DataExtractor data;
-        Status extract_error;
-        valobj_sp->GetData(data, extract_error);
-        if (!extract_error.Success()) {
+        auto data_or_err = valobj_sp->GetData();
+        if (auto error = data_or_err.takeError()) {
           err = Status::FromErrorStringWithFormat(
               "couldn't get the value of %s: %s", GetName().AsCString(),
-              extract_error.AsCString());
+              llvm::toString(std::move(error)).c_str());
           return;
         }
 
@@ -540,9 +536,9 @@ class EntityVariableBase : public Materializer::Entity {
           return;
         }
 
-        if (data.GetByteSize() <
+        if (data_or_err->GetByteSize() <
             llvm::expectedToOptional(GetByteSize(scope)).value_or(0)) {
-          if (data.GetByteSize() == 0 && !LocationExpressionIsValid()) {
+          if (data_or_err->GetByteSize() == 0 && !LocationExpressionIsValid()) {
             err = Status::FromErrorStringWithFormat(
                 "the variable '%s' has no location, "
                 "it may have been optimized out",
@@ -553,7 +549,7 @@ class EntityVariableBase : public Materializer::Entity {
                 ") is larger than the ValueObject's size (%" PRIu64 ")",
                 GetName().AsCString(),
                 llvm::expectedToOptional(GetByteSize(scope)).value_or(0),
-                data.GetByteSize());
+                data_or_err->GetByteSize());
           }
           return;
         }
@@ -571,14 +567,14 @@ class EntityVariableBase : public Materializer::Entity {
         const bool zero_memory = false;
 
         m_temporary_allocation = map.Malloc(
-            data.GetByteSize(), byte_align,
+            data_or_err->GetByteSize(), byte_align,
             lldb::ePermissionsReadable | lldb::ePermissionsWritable,
             IRMemoryMap::eAllocationPolicyMirror, zero_memory, alloc_error);
 
-        m_temporary_allocation_size = data.GetByteSize();
+        m_temporary_allocation_size = data_or_err->GetByteSize();
 
-        m_original_data = std::make_shared<DataBufferHeap>(data.GetDataStart(),
-                                                           data.GetByteSize());
+        m_original_data = std::make_shared<DataBufferHeap>(data_or_err->GetDataStart(),
+                                                           data_or_err->GetByteSize());
 
         if (!alloc_error.Success()) {
           err = Status::FromErrorStringWithFormat(
@@ -589,8 +585,8 @@ class EntityVariableBase : public Materializer::Entity {
 
         Status write_error;
 
-        map.WriteMemory(m_temporary_allocation, data.GetDataStart(),
-                        data.GetByteSize(), write_error);
+        map.WriteMemory(m_temporary_allocation, data_or_err->GetDataStart(),
+                        data_or_err->GetByteSize(), write_error);
 
         if (!write_error.Success()) {
           err = Status::FromErrorStringWithFormat(
diff --git a/lldb/source/Plugins/Language/CPlusPlus/CxxStringTypes.cpp b/lldb/source/Plugins/Language/CPlusPlus/CxxStringTypes.cpp
index c7d4b650d7819..abf6e46c0ebd2 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/CxxStringTypes.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/CxxStringTypes.cpp
@@ -70,8 +70,10 @@ template <StringElementType ElemType>
 static bool CharSummaryProvider(ValueObject &valobj, Stream &stream) {
   auto data_or_err = valobj.GetData();
 
-  if (!data_or_err)
+  if (!data_or_err) {
+    LLDB_LOG_ERRORV(GetLog(LLDBLog::DataFormatters), data_or_err.takeError(), "Cannot extract data: {0}");
     return false;
+  }
 
   std::string value;
   StringPrinter::ReadBufferAndDumpToStreamOptions options(valobj);
diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxxUnorderedMap.cpp b/lldb/source/Plugins/Language/CPlusPlus/LibCxxUnorderedMap.cpp
index 395ecc489a17e..0049e9aa0a3e2 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/LibCxxUnorderedMap.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxxUnorderedMap.cpp
@@ -207,15 +207,13 @@ lldb::ValueObjectSP lldb_private::formatters::
     return lldb::ValueObjectSP();
   StreamString stream;
   stream.Printf("[%" PRIu64 "]", (uint64_t)idx);
-  DataExtractor data;
-  Status error;
-  val_hash.first->GetData(data, error);
-  if (error.Fail())
+  auto data_or_err = val_hash.first->GetData();
+  if (!data_or_err)
     return lldb::ValueObjectSP();
   const bool thread_and_frame_only_if_stopped = true;
   ExecutionContext exe_ctx = val_hash.first->GetExecutionContextRef().Lock(
       thread_and_frame_only_if_stopped);
-  return CreateValueObjectFromData(stream.GetString(), data, exe_ctx,
+  return CreateValueObjectFromData(stream.GetString(), *data_or_err, exe_ctx,
                                    m_element_type);
 }
 
diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
index 763a80faa914a..6dff7bdcc8c36 100644
--- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
+++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
@@ -248,8 +248,12 @@ static lldb::addr_t GetVTableAddress(Process &process,
   // so just extract VTable pointer from it
 
   auto data_or_err = valobj.GetData();
-  if (!data_or_err)
+  if (!data_or_err) {
+    LLDB_LOG_ERRORV(GetLog(LLDBLog::Types), data_or_err.takeError(), "Extracted data is an invalid address: {0}");
     return LLDB_INVALID_ADDRESS;
+  }
+
+
 
   auto size = data_or_err->GetByteSize();
   if (vbtable_ptr_offset + data_or_err->GetAddressByteSize() > size)

>From 69da662256f7ed99dea5a341184dd8d25c3e7419 Mon Sep 17 00:00:00 2001
From: medievalghoul <61852278+medievalghoul at users.noreply.github.com>
Date: Mon, 10 Mar 2025 22:04:17 -0400
Subject: [PATCH 06/18] third wave: clean up

---
 lldb/source/DataFormatters/TypeFormat.cpp     | 26 +++++++++++--------
 lldb/source/Expression/Materializer.cpp       |  7 ++---
 .../Language/CPlusPlus/CxxStringTypes.cpp     |  8 ++++--
 .../TypeSystem/Clang/TypeSystemClang.cpp      |  5 ++--
 4 files changed, 27 insertions(+), 19 deletions(-)

diff --git a/lldb/source/DataFormatters/TypeFormat.cpp b/lldb/source/DataFormatters/TypeFormat.cpp
index b829f855bf57d..a975536dcbd69 100644
--- a/lldb/source/DataFormatters/TypeFormat.cpp
+++ b/lldb/source/DataFormatters/TypeFormat.cpp
@@ -49,21 +49,24 @@ bool TypeFormatImpl_Format::FormatObject(ValueObject *valobj,
 
     auto data_or_err = valobj->GetData();
     if (!data_or_err) {
-          LLDB_LOG_ERRORV(GetLog(LLDBLog::DataFormatters), data_or_err.takeError(), "Failed to extract data: {0}");
-          return false;
-        } 
+      LLDB_LOG_ERRORV(GetLog(LLDBLog::DataFormatters), data_or_err.takeError(),
+                      "Failed to extract data: {0}");
+      return false;
+    }
     if (context_type == Value::ContextType::RegisterInfo) {
       const RegisterInfo *reg_info = value.GetRegisterInfo();
       if (reg_info) {
         auto data_or_err = valobj->GetData();
         if (!data_or_err) {
-          LLDB_LOG_ERRORV(GetLog(LLDBLog::Process), data_or_err.takeError(), "Failed to extract data for register info: {0}");
+          LLDB_LOG_ERRORV(GetLog(LLDBLog::Process), data_or_err.takeError(),
+                          "Failed to extract data for register info: {0}");
           return false;
         }
-          
+
         StreamString reg_sstr;
-        DumpDataExtractor(*data_or_err, &reg_sstr, 0, GetFormat(), reg_info->byte_size,
-                          1, UINT32_MAX, LLDB_INVALID_ADDRESS, 0, 0,
+        DumpDataExtractor(*data_or_err, &reg_sstr, 0, GetFormat(),
+                          reg_info->byte_size, 1, UINT32_MAX,
+                          LLDB_INVALID_ADDRESS, 0, 0,
                           exe_ctx.GetBestExecutionContextScope());
         dest = std::string(reg_sstr.GetString());
       }
@@ -95,9 +98,10 @@ bool TypeFormatImpl_Format::FormatObject(ValueObject *valobj,
         } else {
           auto data_or_err = valobj->GetData();
           if (!data_or_err)
-            LLDB_LOG_ERRORV(GetLog(LLDBLog::DataFormatters), data_or_err.takeError(),
+            LLDB_LOG_ERRORV(
+                GetLog(LLDBLog::DataFormatters), data_or_err.takeError(),
                 "Failed to extract data for CString info to display: {0}:");
-            return false;
+          return false;
         }
 
         ExecutionContextScope *exe_scope =
@@ -193,10 +197,10 @@ bool TypeFormatImpl_EnumType::FormatObject(ValueObject *valobj,
   auto data_or_err = valobj->GetData();
   if (!data_or_err) {
     LLDB_LOG_ERRORV(GetLog(LLDBLog::DataFormatters), data_or_err.takeError(),
-        "Can't extract data related to enum type info: {0}");
+                    "Can't extract data related to enum type info: {0}");
     return false;
   }
-      ExecutionContext exe_ctx(valobj->GetExecutionContextRef());
+  ExecutionContext exe_ctx(valobj->GetExecutionContextRef());
   StreamString sstr;
   valobj_enum_type.DumpTypeValue(&sstr, lldb::eFormatEnum, *data_or_err, 0,
                                  data_or_err->GetByteSize(), 0, 0,
diff --git a/lldb/source/Expression/Materializer.cpp b/lldb/source/Expression/Materializer.cpp
index bf895f5e8853f..e6c601143c973 100644
--- a/lldb/source/Expression/Materializer.cpp
+++ b/lldb/source/Expression/Materializer.cpp
@@ -493,7 +493,8 @@ class EntityVariableBase : public Materializer::Entity {
       }
 
       lldb::offset_t offset = 0;
-      lldb::addr_t reference_addr = valobj_extractor_or_err->GetAddress(&offset);
+      lldb::addr_t reference_addr =
+          valobj_extractor_or_err->GetAddress(&offset);
 
       Status write_error;
       map.WritePointerToMemory(load_addr, reference_addr, write_error);
@@ -573,8 +574,8 @@ class EntityVariableBase : public Materializer::Entity {
 
         m_temporary_allocation_size = data_or_err->GetByteSize();
 
-        m_original_data = std::make_shared<DataBufferHeap>(data_or_err->GetDataStart(),
-                                                           data_or_err->GetByteSize());
+        m_original_data = std::make_shared<DataBufferHeap>(
+            data_or_err->GetDataStart(), data_or_err->GetByteSize());
 
         if (!alloc_error.Success()) {
           err = Status::FromErrorStringWithFormat(
diff --git a/lldb/source/Plugins/Language/CPlusPlus/CxxStringTypes.cpp b/lldb/source/Plugins/Language/CPlusPlus/CxxStringTypes.cpp
index abf6e46c0ebd2..92ee1b874d0fd 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/CxxStringTypes.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/CxxStringTypes.cpp
@@ -71,7 +71,8 @@ static bool CharSummaryProvider(ValueObject &valobj, Stream &stream) {
   auto data_or_err = valobj.GetData();
 
   if (!data_or_err) {
-    LLDB_LOG_ERRORV(GetLog(LLDBLog::DataFormatters), data_or_err.takeError(), "Cannot extract data: {0}");
+    LLDB_LOG_ERRORV(GetLog(LLDBLog::DataFormatters), data_or_err.takeError(),
+                    "Cannot extract data: {0}");
     return false;
   }
 
@@ -171,8 +172,11 @@ bool lldb_private::formatters::WCharSummaryProvider(
     ValueObject &valobj, Stream &stream, const TypeSummaryOptions &) {
   auto data_or_err = valobj.GetData();
 
-  if (!data_or_err)
+  if (!data_or_err) {
+    LLDB_LOG_ERRORV(GetLog(LLDBLog::DataFormatters), data_or_err.takeError(),
+        "Can't extract data for WChar Summary: {0}")
     return false;
+  }
 
   // Get a wchar_t basic type from the current type system
   CompilerType wchar_compiler_type =
diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
index 6dff7bdcc8c36..fee3884304d87 100644
--- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
+++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
@@ -249,12 +249,11 @@ static lldb::addr_t GetVTableAddress(Process &process,
 
   auto data_or_err = valobj.GetData();
   if (!data_or_err) {
-    LLDB_LOG_ERRORV(GetLog(LLDBLog::Types), data_or_err.takeError(), "Extracted data is an invalid address: {0}");
+    LLDB_LOG_ERRORV(GetLog(LLDBLog::Types), data_or_err.takeError(),
+                    "Extracted data is an invalid address: {0}");
     return LLDB_INVALID_ADDRESS;
   }
 
-
-
   auto size = data_or_err->GetByteSize();
   if (vbtable_ptr_offset + data_or_err->GetAddressByteSize() > size)
     return LLDB_INVALID_ADDRESS;

>From 2a3d58965957bd10b6a3daed7736e0aea2811226 Mon Sep 17 00:00:00 2001
From: medievalghoul <61852278+medievalghoul at users.noreply.github.com>
Date: Tue, 11 Mar 2025 21:55:09 -0400
Subject: [PATCH 07/18] third wave: more clean up

---
 lldb/source/Plugins/Language/CPlusPlus/CxxStringTypes.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lldb/source/Plugins/Language/CPlusPlus/CxxStringTypes.cpp b/lldb/source/Plugins/Language/CPlusPlus/CxxStringTypes.cpp
index 92ee1b874d0fd..b7d7fdf9a7f31 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/CxxStringTypes.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/CxxStringTypes.cpp
@@ -174,7 +174,7 @@ bool lldb_private::formatters::WCharSummaryProvider(
 
   if (!data_or_err) {
     LLDB_LOG_ERRORV(GetLog(LLDBLog::DataFormatters), data_or_err.takeError(),
-        "Can't extract data for WChar Summary: {0}")
+                    "Can't extract data for WChar Summary: {0}");
     return false;
   }
 

>From c3ba85ddf06d5740f890f53002a985b3547d9805 Mon Sep 17 00:00:00 2001
From: medievalghoul <61852278+medievalghoul at users.noreply.github.com>
Date: Wed, 26 Mar 2025 20:43:28 -0400
Subject: [PATCH 08/18] third wave: fixed the readablility

---
 lldb/source/Breakpoint/Watchpoint.cpp         | 21 ++++++++++++-------
 lldb/source/DataFormatters/TypeFormat.cpp     |  6 ++++--
 .../Plugins/Language/CPlusPlus/LibCxxList.cpp |  6 +++---
 .../Language/CPlusPlus/LibCxxUnorderedMap.cpp |  6 +++---
 lldb/source/Plugins/Language/ObjC/Cocoa.cpp   |  7 ++++---
 .../source/Plugins/Language/ObjC/NSString.cpp |  6 +++---
 .../DumpValueObjectOptionsTests.cpp           |  1 +
 7 files changed, 32 insertions(+), 21 deletions(-)

diff --git a/lldb/source/Breakpoint/Watchpoint.cpp b/lldb/source/Breakpoint/Watchpoint.cpp
index 2df848aaa0576..a23c6ccab3f39 100644
--- a/lldb/source/Breakpoint/Watchpoint.cpp
+++ b/lldb/source/Breakpoint/Watchpoint.cpp
@@ -230,18 +230,25 @@ bool Watchpoint::WatchedValueReportable(const ExecutionContext &exe_ctx) {
       exe_ctx.GetBestExecutionContextScope(), g_watch_name.GetStringRef(),
       watch_address, m_type);
   newest_valueobj_sp = newest_valueobj_sp->CreateConstantValue(g_watch_name);
-  Status error;
 
-  DataExtractor new_data;
-  DataExtractor old_data;
+  auto new_data_or_err = newest_valueobj_sp->GetData();
 
-  newest_valueobj_sp->GetData(new_data, error);
-  if (error.Fail())
+  if (!new_data_or_err) {
+    LLDB_LOG_ERRORV(GetLog(LLDBLog::Watchpoints), new_data_or_err.takeError(),
+                          "Failed to extract watchpoint new data: {0}");
     return true;
-  m_new_value_sp->GetData(old_data, error);
-  if (error.Fail())
+  }
+
+  auto new_data = std::move(*new_data_or_err);
+  auto old_data_or_err = m_new_value_sp->GetData();
+
+  if (!old_data_or_err) {
+    LLDB_LOG_ERRORV(GetLog(LLDBLog::Watchpoints), old_data_or_err.takeError(),
+                          "Failed to extract watchpoint old data: {0}");
     return true;
+  }
 
+  auto old_data = std::move(*old_data_or_err);
   if (new_data.GetByteSize() != old_data.GetByteSize() ||
       new_data.GetByteSize() == 0)
     return true;
diff --git a/lldb/source/DataFormatters/TypeFormat.cpp b/lldb/source/DataFormatters/TypeFormat.cpp
index a975536dcbd69..79eb08a493d66 100644
--- a/lldb/source/DataFormatters/TypeFormat.cpp
+++ b/lldb/source/DataFormatters/TypeFormat.cpp
@@ -200,10 +200,12 @@ bool TypeFormatImpl_EnumType::FormatObject(ValueObject *valobj,
                     "Can't extract data related to enum type info: {0}");
     return false;
   }
+
+  auto data = std::move(*data_or_err);
   ExecutionContext exe_ctx(valobj->GetExecutionContextRef());
   StreamString sstr;
-  valobj_enum_type.DumpTypeValue(&sstr, lldb::eFormatEnum, *data_or_err, 0,
-                                 data_or_err->GetByteSize(), 0, 0,
+  valobj_enum_type.DumpTypeValue(&sstr, lldb::eFormatEnum, data, 0,
+                                 data.GetByteSize(), 0, 0,
                                  exe_ctx.GetBestExecutionContextScope());
   if (!sstr.GetString().empty())
     dest = std::string(sstr.GetString());
diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxxList.cpp b/lldb/source/Plugins/Language/CPlusPlus/LibCxxList.cpp
index 4e2775c5ca266..3dd40185cae79 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/LibCxxList.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxxList.cpp
@@ -273,12 +273,12 @@ ValueObjectSP ForwardListFrontEnd::GetChildAtIndex(uint32_t idx) {
 
   // we need to copy current_sp into a new object otherwise we will end up with
   // all items named __value_
-  auto data_or_err = current_sp->GetData();
-  if (!data_or_err)
+  auto data = llvm::expectedToOptional(current_sp->GetData());
+  if (!data)
     return nullptr;
 
   return CreateValueObjectFromData(
-      llvm::formatv("[{0}]", idx).str(), *data_or_err,
+      llvm::formatv("[{0}]", idx).str(), *data,
       m_backend.GetExecutionContextRef(), m_element_type);
 }
 
diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxxUnorderedMap.cpp b/lldb/source/Plugins/Language/CPlusPlus/LibCxxUnorderedMap.cpp
index 0049e9aa0a3e2..11a72f1e8920e 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/LibCxxUnorderedMap.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxxUnorderedMap.cpp
@@ -207,13 +207,13 @@ lldb::ValueObjectSP lldb_private::formatters::
     return lldb::ValueObjectSP();
   StreamString stream;
   stream.Printf("[%" PRIu64 "]", (uint64_t)idx);
-  auto data_or_err = val_hash.first->GetData();
-  if (!data_or_err)
+  auto data = llvm::expectedToOptional(val_hash.first->GetData());
+  if (!data)
     return lldb::ValueObjectSP();
   const bool thread_and_frame_only_if_stopped = true;
   ExecutionContext exe_ctx = val_hash.first->GetExecutionContextRef().Lock(
       thread_and_frame_only_if_stopped);
-  return CreateValueObjectFromData(stream.GetString(), *data_or_err, exe_ctx,
+  return CreateValueObjectFromData(stream.GetString(), *data, exe_ctx,
                                    m_element_type);
 }
 
diff --git a/lldb/source/Plugins/Language/ObjC/Cocoa.cpp b/lldb/source/Plugins/Language/ObjC/Cocoa.cpp
index ebb36b52af0dd..376a290544b34 100644
--- a/lldb/source/Plugins/Language/ObjC/Cocoa.cpp
+++ b/lldb/source/Plugins/Language/ObjC/Cocoa.cpp
@@ -1205,10 +1205,11 @@ bool lldb_private::formatters::ObjCSELSummaryProvider(
     valobj_sp = ValueObject::CreateValueObjectFromAddress("text", data_address,
                                                           exe_ctx, charstar);
   } else {
-    auto data_or_err = valobj.GetData();
-    if (!data_or_err)
+    auto data = llvm::expectedToOptional(valobj.GetData());
+
+    if (!data)
       return false;
-    valobj_sp = ValueObject::CreateValueObjectFromData("text", *data_or_err,
+    valobj_sp = ValueObject::CreateValueObjectFromData("text", *data,
                                                        exe_ctx, charstar);
   }
 
diff --git a/lldb/source/Plugins/Language/ObjC/NSString.cpp b/lldb/source/Plugins/Language/ObjC/NSString.cpp
index 5b6a22c6e6b6c..96848b8d3b7ab 100644
--- a/lldb/source/Plugins/Language/ObjC/NSString.cpp
+++ b/lldb/source/Plugins/Language/ObjC/NSString.cpp
@@ -291,11 +291,11 @@ bool lldb_private::formatters::NSAttributedStringSummaryProvider(
       "string_ptr", pointer_value, exe_ctx, type));
   if (!child_ptr_sp)
     return false;
-  auto data_or_err = child_ptr_sp->GetData();
-  if (!data_or_err)
+  auto data = llvm::expectedToOptional(child_ptr_sp->GetData());
+  if (!data)
     return false;
   ValueObjectSP child_sp(child_ptr_sp->CreateValueObjectFromData(
-      "string_data", *data_or_err, exe_ctx, type));
+      "string_data", *data, exe_ctx, type));
   child_sp->GetValueAsUnsigned(0);
   if (child_sp)
     return NSStringSummaryProvider(*child_sp, stream, options);
diff --git a/lldb/unittests/ValueObject/DumpValueObjectOptionsTests.cpp b/lldb/unittests/ValueObject/DumpValueObjectOptionsTests.cpp
index c3fb8cbeb60ae..c725b6d8825b1 100644
--- a/lldb/unittests/ValueObject/DumpValueObjectOptionsTests.cpp
+++ b/lldb/unittests/ValueObject/DumpValueObjectOptionsTests.cpp
@@ -88,6 +88,7 @@ class ValueObjectMockProcessTest : public ::testing::Test {
                                                       var_name, data_extractor);
       if (llvm::Error error = valobj_sp->Dump(strm, options))
         llvm::consumeError(std::move(error));
+      
       ASSERT_STREQ(strm.GetString().str().c_str(), expected);
       strm.Clear();
     }

>From 613dc2ae5ffa12cbb1dc9a7ff0e06f6e99544891 Mon Sep 17 00:00:00 2001
From: medievalghoul <61852278+medievalghoul at users.noreply.github.com>
Date: Wed, 26 Mar 2025 20:48:05 -0400
Subject: [PATCH 09/18] third wave: fixed format

---
 lldb/source/Expression/Materializer.cpp | 27 ++++++++++++++-----------
 1 file changed, 15 insertions(+), 12 deletions(-)

diff --git a/lldb/source/Expression/Materializer.cpp b/lldb/source/Expression/Materializer.cpp
index e6c601143c973..3669957f3d397 100644
--- a/lldb/source/Expression/Materializer.cpp
+++ b/lldb/source/Expression/Materializer.cpp
@@ -524,12 +524,15 @@ class EntityVariableBase : public Materializer::Entity {
       } else {
         auto data_or_err = valobj_sp->GetData();
         if (auto error = data_or_err.takeError()) {
-          err = Status::FromErrorStringWithFormat(
-              "couldn't get the value of %s: %s", GetName().AsCString(),
-              llvm::toString(std::move(error)).c_str());
-          return;
+            err = Status::FromError(
+                llvm::joinErrors(
+                  llvm::createStringError("couldn't get the value of %s: ", 
+                    GetName().AsCString()), std::move(error)));
+            return;
         }
 
+        auto data = std::move(*data_or_err);
+
         if (m_temporary_allocation != LLDB_INVALID_ADDRESS) {
           err = Status::FromErrorStringWithFormat(
               "trying to create a temporary region for %s but one exists",
@@ -537,9 +540,9 @@ class EntityVariableBase : public Materializer::Entity {
           return;
         }
 
-        if (data_or_err->GetByteSize() <
+        if (data.GetByteSize() <
             llvm::expectedToOptional(GetByteSize(scope)).value_or(0)) {
-          if (data_or_err->GetByteSize() == 0 && !LocationExpressionIsValid()) {
+          if (data.GetByteSize() == 0 && !LocationExpressionIsValid()) {
             err = Status::FromErrorStringWithFormat(
                 "the variable '%s' has no location, "
                 "it may have been optimized out",
@@ -550,7 +553,7 @@ class EntityVariableBase : public Materializer::Entity {
                 ") is larger than the ValueObject's size (%" PRIu64 ")",
                 GetName().AsCString(),
                 llvm::expectedToOptional(GetByteSize(scope)).value_or(0),
-                data_or_err->GetByteSize());
+                data.GetByteSize());
           }
           return;
         }
@@ -568,14 +571,14 @@ class EntityVariableBase : public Materializer::Entity {
         const bool zero_memory = false;
 
         m_temporary_allocation = map.Malloc(
-            data_or_err->GetByteSize(), byte_align,
+            data.GetByteSize(), byte_align,
             lldb::ePermissionsReadable | lldb::ePermissionsWritable,
             IRMemoryMap::eAllocationPolicyMirror, zero_memory, alloc_error);
 
-        m_temporary_allocation_size = data_or_err->GetByteSize();
+        m_temporary_allocation_size = data.GetByteSize();
 
         m_original_data = std::make_shared<DataBufferHeap>(
-            data_or_err->GetDataStart(), data_or_err->GetByteSize());
+            data.GetDataStart(), data.GetByteSize());
 
         if (!alloc_error.Success()) {
           err = Status::FromErrorStringWithFormat(
@@ -586,8 +589,8 @@ class EntityVariableBase : public Materializer::Entity {
 
         Status write_error;
 
-        map.WriteMemory(m_temporary_allocation, data_or_err->GetDataStart(),
-                        data_or_err->GetByteSize(), write_error);
+        map.WriteMemory(m_temporary_allocation, data.GetDataStart(),
+                        data.GetByteSize(), write_error);
 
         if (!write_error.Success()) {
           err = Status::FromErrorStringWithFormat(

>From ae2276f8ce01e5e71a5fdfba4c1aee26d5385d0a Mon Sep 17 00:00:00 2001
From: medievalghoul <61852278+medievalghoul at users.noreply.github.com>
Date: Wed, 26 Mar 2025 20:52:13 -0400
Subject: [PATCH 10/18] forth wave: ABI related code refactoring

---
 lldb/source/API/SBValue.cpp                   | 11 ++++--
 .../Plugins/ABI/AArch64/ABIMacOSX_arm64.cpp   | 18 ++++-----
 .../Plugins/ABI/AArch64/ABISysV_arm64.cpp     | 15 ++++----
 lldb/source/Plugins/ABI/ARC/ABISysV_arc.cpp   | 15 ++++----
 lldb/source/Plugins/ABI/ARM/ABIMacOSX_arm.cpp | 17 +++++----
 lldb/source/Plugins/ABI/ARM/ABISysV_arm.cpp   | 16 ++++----
 .../ABI/LoongArch/ABISysV_loongarch.cpp       | 15 ++++----
 lldb/source/Plugins/ABI/Mips/ABISysV_mips.cpp | 17 ++++-----
 .../Plugins/ABI/Mips/ABISysV_mips64.cpp       | 10 ++---
 .../Plugins/ABI/PowerPC/ABISysV_ppc.cpp       | 30 ++++++++-------
 .../Plugins/ABI/PowerPC/ABISysV_ppc64.cpp     | 37 ++++++++++---------
 .../Plugins/ABI/RISCV/ABISysV_riscv.cpp       | 14 ++++---
 .../Plugins/ABI/SystemZ/ABISysV_s390x.cpp     | 34 ++++++++---------
 .../source/Plugins/ABI/X86/ABIMacOSX_i386.cpp | 17 +++++----
 lldb/source/Plugins/ABI/X86/ABISysV_i386.cpp  | 26 ++++++-------
 .../source/Plugins/ABI/X86/ABISysV_x86_64.cpp | 25 ++++++-------
 .../Plugins/ABI/X86/ABIWindows_x86_64.cpp     | 28 +++++++-------
 17 files changed, 178 insertions(+), 167 deletions(-)

diff --git a/lldb/source/API/SBValue.cpp b/lldb/source/API/SBValue.cpp
index 6b91120f6427a..27ee6131fe850 100644
--- a/lldb/source/API/SBValue.cpp
+++ b/lldb/source/API/SBValue.cpp
@@ -1381,11 +1381,14 @@ lldb::SBData SBValue::GetData() {
   ValueLocker locker;
   lldb::ValueObjectSP value_sp(GetSP(locker));
   if (value_sp) {
+    auto data_or_err = value_sp->GetData();
+    if (!data_or_err) {
+
+      LLDB_LOG_ERRORV(GetLog(LLDBLog::API), data_or_err.takeError(),
+                      "SBValue GetData failed to extract info: {0}");
+    }
     DataExtractorSP data_sp(new DataExtractor());
-    Status error;
-    value_sp->GetData(*data_sp, error);
-    if (error.Success())
-      *sb_data = data_sp;
+    *sb_data = data_sp;
   }
 
   return sb_data;
diff --git a/lldb/source/Plugins/ABI/AArch64/ABIMacOSX_arm64.cpp b/lldb/source/Plugins/ABI/AArch64/ABIMacOSX_arm64.cpp
index 4b3018bb40a49..8c3edf28c5318 100644
--- a/lldb/source/Plugins/ABI/AArch64/ABIMacOSX_arm64.cpp
+++ b/lldb/source/Plugins/ABI/AArch64/ABIMacOSX_arm64.cpp
@@ -256,15 +256,15 @@ ABIMacOSX_arm64::SetReturnValueObject(lldb::StackFrameSP &frame_sp,
   RegisterContext *reg_ctx = thread->GetRegisterContext().get();
 
   if (reg_ctx) {
-    DataExtractor data;
-    Status data_error;
-    const uint64_t byte_size = new_value_sp->GetData(data, data_error);
-    if (data_error.Fail()) {
-      error = Status::FromErrorStringWithFormat(
-          "Couldn't convert return value to raw data: %s",
-          data_error.AsCString());
-      return error;
-    }
+    auto data_or_err = new_value_sp->GetData();
+
+    if (auto error = data_or_err.takeError())
+      return Status::FromError(llvm::joinErrors(
+          llvm::createStringError("Couldn't convert return value to raw data"),
+          std::move(error)));
+
+    auto data = std::move(*data_or_err);
+    const uint64_t byte_size = data.GetByteSize();
 
     const uint32_t type_flags = return_value_type.GetTypeInfo(nullptr);
     if (type_flags & eTypeIsScalar || type_flags & eTypeIsPointer) {
diff --git a/lldb/source/Plugins/ABI/AArch64/ABISysV_arm64.cpp b/lldb/source/Plugins/ABI/AArch64/ABISysV_arm64.cpp
index ca794cd604fb1..fe73546924bdf 100644
--- a/lldb/source/Plugins/ABI/AArch64/ABISysV_arm64.cpp
+++ b/lldb/source/Plugins/ABI/AArch64/ABISysV_arm64.cpp
@@ -296,15 +296,14 @@ Status ABISysV_arm64::SetReturnValueObject(lldb::StackFrameSP &frame_sp,
   RegisterContext *reg_ctx = thread->GetRegisterContext().get();
 
   if (reg_ctx) {
-    DataExtractor data;
-    Status data_error;
-    const uint64_t byte_size = new_value_sp->GetData(data, data_error);
-    if (data_error.Fail()) {
-      error = Status::FromErrorStringWithFormat(
-          "Couldn't convert return value to raw data: %s",
-          data_error.AsCString());
-      return error;
+    auto data_or_err = new_value_sp->GetData();
+    if (auto error = data_or_err.takeError()) {
+      return Status::FromError(llvm::joinErrors(
+          llvm::createStringError("Couldn't convert return value to raw data"),
+          std::move(error)));
     }
+    auto data = std::move(*data_or_err);
+    const uint64_t byte_size = data.GetByteSize();
 
     const uint32_t type_flags = return_value_type.GetTypeInfo(nullptr);
     if (type_flags & eTypeIsScalar || type_flags & eTypeIsPointer) {
diff --git a/lldb/source/Plugins/ABI/ARC/ABISysV_arc.cpp b/lldb/source/Plugins/ABI/ARC/ABISysV_arc.cpp
index 21bc0f28db0b9..2a573e51a3b70 100644
--- a/lldb/source/Plugins/ABI/ARC/ABISysV_arc.cpp
+++ b/lldb/source/Plugins/ABI/ARC/ABISysV_arc.cpp
@@ -332,15 +332,16 @@ Status ABISysV_arc::SetReturnValueObject(StackFrameSP &frame_sp,
     return result;
   }
 
-  DataExtractor data;
-  size_t num_bytes = new_value_sp->GetData(data, result);
+  auto data_or_err = new_value_sp->GetData();
 
-  if (result.Fail()) {
-    result = Status::FromErrorStringWithFormat(
-        "Couldn't convert return value to raw data: %s", result.AsCString());
-    return result;
-  }
+  if (auto error = data_or_err.takeError())
+    return Status::FromError(llvm::joinErrors(
+        llvm::createStringError("Couldn't convert return value to raw data"),
+        std::move(error)));
+
+  auto data = std::move(*data_or_err);
 
+  size_t num_bytes = data.GetByteSize();
   if (num_bytes <= 2 * reg_size) {
     offset_t offset = 0;
     uint64_t raw_value = data.GetMaxU64(&offset, num_bytes);
diff --git a/lldb/source/Plugins/ABI/ARM/ABIMacOSX_arm.cpp b/lldb/source/Plugins/ABI/ARM/ABIMacOSX_arm.cpp
index 27d0474cc9d19..8671a7b0f04aa 100644
--- a/lldb/source/Plugins/ABI/ARM/ABIMacOSX_arm.cpp
+++ b/lldb/source/Plugins/ABI/ARM/ABIMacOSX_arm.cpp
@@ -1703,15 +1703,16 @@ Status ABIMacOSX_arm::SetReturnValueObject(lldb::StackFrameSP &frame_sp,
   bool set_it_simple = false;
   if (compiler_type.IsIntegerOrEnumerationType(is_signed) ||
       compiler_type.IsPointerType()) {
-    DataExtractor data;
-    Status data_error;
-    size_t num_bytes = new_value_sp->GetData(data, data_error);
-    if (data_error.Fail()) {
-      error = Status::FromErrorStringWithFormat(
-          "Couldn't convert return value to raw data: %s",
-          data_error.AsCString());
-      return error;
+    auto data_or_err = new_value_sp->GetData();
+    if (auto error = data_or_err.takeError()) {
+      return Status::FromError(llvm::joinErrors(
+          llvm::createStringError("Couldn't convert return value to raw data"),
+          std::move(error)));
     }
+
+    auto data = std::move(*data_or_err);
+
+    size_t num_bytes = data.GetByteSize();
     lldb::offset_t offset = 0;
     if (num_bytes <= 8) {
       const RegisterInfo *r0_info = reg_ctx->GetRegisterInfoByName("r0", 0);
diff --git a/lldb/source/Plugins/ABI/ARM/ABISysV_arm.cpp b/lldb/source/Plugins/ABI/ARM/ABISysV_arm.cpp
index cf051b48e3fc1..95a4bbf0f33db 100644
--- a/lldb/source/Plugins/ABI/ARM/ABISysV_arm.cpp
+++ b/lldb/source/Plugins/ABI/ARM/ABISysV_arm.cpp
@@ -1849,15 +1849,15 @@ Status ABISysV_arm::SetReturnValueObject(lldb::StackFrameSP &frame_sp,
   bool set_it_simple = false;
   if (compiler_type.IsIntegerOrEnumerationType(is_signed) ||
       compiler_type.IsPointerType()) {
-    DataExtractor data;
-    Status data_error;
-    size_t num_bytes = new_value_sp->GetData(data, data_error);
-    if (data_error.Fail()) {
-      error = Status::FromErrorStringWithFormat(
-          "Couldn't convert return value to raw data: %s",
-          data_error.AsCString());
-      return error;
+    auto data_or_err = new_value_sp->GetData();
+    if (auto error = data_or_err.takeError()) {
+      return Status::FromError(llvm::joinErrors(
+          llvm::createStringError("Couldn't convert return value to raw data"),
+          std::move(error)));
     }
+    auto data = std::move(*data_or_err);
+
+    size_t num_bytes = data.GetByteSize();
     lldb::offset_t offset = 0;
     if (num_bytes <= 8) {
       const RegisterInfo *r0_info = reg_ctx->GetRegisterInfo(
diff --git a/lldb/source/Plugins/ABI/LoongArch/ABISysV_loongarch.cpp b/lldb/source/Plugins/ABI/LoongArch/ABISysV_loongarch.cpp
index 14ef8a0177aac..57047aa4858a1 100644
--- a/lldb/source/Plugins/ABI/LoongArch/ABISysV_loongarch.cpp
+++ b/lldb/source/Plugins/ABI/LoongArch/ABISysV_loongarch.cpp
@@ -267,15 +267,16 @@ Status ABISysV_loongarch::SetReturnValueObject(StackFrameSP &frame_sp,
     return result;
   }
 
-  DataExtractor data;
-  size_t num_bytes = new_value_sp->GetData(data, result);
+  auto data_or_err = new_value_sp->GetData();
 
-  if (result.Fail()) {
-    result = Status::FromErrorStringWithFormat(
-        "Couldn't convert return value to raw data: %s", result.AsCString());
-    return result;
-  }
+  if (auto error = data_or_err.takeError())
+    return Status::FromError(llvm::joinErrors(
+        llvm::createStringError("Couldn't convert return value to raw data"),
+        std::move(error)));
+
+  auto data = std::move(*data_or_err);
 
+  size_t num_bytes = data.GetByteSize();
   size_t reg_size = m_is_la64 ? 8 : 4;
   // Currently, we only support sizeof(data) <= 2 * reg_size.
   // 1. If the (`size` <= reg_size), the `data` will be returned through `ARG1`.
diff --git a/lldb/source/Plugins/ABI/Mips/ABISysV_mips.cpp b/lldb/source/Plugins/ABI/Mips/ABISysV_mips.cpp
index a2b60a07e9ca2..73d2046f5d703 100644
--- a/lldb/source/Plugins/ABI/Mips/ABISysV_mips.cpp
+++ b/lldb/source/Plugins/ABI/Mips/ABISysV_mips.cpp
@@ -716,16 +716,15 @@ Status ABISysV_mips::SetReturnValueObject(lldb::StackFrameSP &frame_sp,
   bool set_it_simple = false;
   if (compiler_type.IsIntegerOrEnumerationType(is_signed) ||
       compiler_type.IsPointerType()) {
-    DataExtractor data;
-    Status data_error;
-    size_t num_bytes = new_value_sp->GetData(data, data_error);
-    if (data_error.Fail()) {
-      error = Status::FromErrorStringWithFormat(
-          "Couldn't convert return value to raw data: %s",
-          data_error.AsCString());
-      return error;
-    }
 
+    auto data_or_err = new_value_sp->GetData();
+    if (auto error = data_or_err.takeError())
+      return Status::FromError(llvm::joinErrors(
+          llvm::createStringError("Couldn't convert return value to raw data"),
+          std::move(error)));
+
+    auto data = std::move(*data_or_err);
+    size_t num_bytes = data.GetByteSize();
     lldb::offset_t offset = 0;
     if (num_bytes <= 8) {
       const RegisterInfo *r2_info = reg_ctx->GetRegisterInfoByName("r2", 0);
diff --git a/lldb/source/Plugins/ABI/Mips/ABISysV_mips64.cpp b/lldb/source/Plugins/ABI/Mips/ABISysV_mips64.cpp
index 763d6140558f6..13a46ab2f6a30 100644
--- a/lldb/source/Plugins/ABI/Mips/ABISysV_mips64.cpp
+++ b/lldb/source/Plugins/ABI/Mips/ABISysV_mips64.cpp
@@ -674,16 +674,16 @@ Status ABISysV_mips64::SetReturnValueObject(lldb::StackFrameSP &frame_sp,
   if (!reg_ctx)
     error = Status::FromErrorString("no registers are available");
 
-  DataExtractor data;
-  Status data_error;
-  size_t num_bytes = new_value_sp->GetData(data, data_error);
-  if (data_error.Fail()) {
+  auto data_or_err = new_value_sp->GetData();
+  if (auto err = data_or_err.takeError()) {
     error = Status::FromErrorStringWithFormat(
         "Couldn't convert return value to raw data: %s",
-        data_error.AsCString());
+        llvm::toString(std::move(err)).c_str());
     return error;
   }
 
+  auto data = std::move(*data_or_err);
+  size_t num_bytes = data.GetByteSize();
   const uint32_t type_flags = compiler_type.GetTypeInfo(nullptr);
 
   if (type_flags & eTypeIsScalar || type_flags & eTypeIsPointer) {
diff --git a/lldb/source/Plugins/ABI/PowerPC/ABISysV_ppc.cpp b/lldb/source/Plugins/ABI/PowerPC/ABISysV_ppc.cpp
index 93e1fa48039fe..54cd8fb908c50 100644
--- a/lldb/source/Plugins/ABI/PowerPC/ABISysV_ppc.cpp
+++ b/lldb/source/Plugins/ABI/PowerPC/ABISysV_ppc.cpp
@@ -436,13 +436,15 @@ Status ABISysV_ppc::SetReturnValueObject(lldb::StackFrameSP &frame_sp,
       compiler_type.IsPointerType()) {
     const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoByName("r3", 0);
 
-    DataExtractor data;
-    Status data_error;
-    size_t num_bytes = new_value_sp->GetData(data, data_error);
-    if (data_error.Fail())
+    auto data_or_err = new_value_sp->GetData();
+    if (auto err = data_or_err.takeError())
       return Status::FromErrorStringWithFormat(
           "Couldn't convert return value to raw data: %s",
-          data_error.AsCString());
+          llvm::toString(std::move(err)).c_str());
+
+    auto data = std::move(*data_or_err);
+
+    size_t num_bytes = data.GetByteSize();
     lldb::offset_t offset = 0;
     if (num_bytes <= 8) {
       uint64_t raw_value = data.GetMaxU64(&offset, num_bytes);
@@ -466,16 +468,16 @@ Status ABISysV_ppc::SetReturnValueObject(lldb::StackFrameSP &frame_sp,
         return error;
       }
       if (*bit_width <= 64) {
-        DataExtractor data;
-        Status data_error;
-        size_t num_bytes = new_value_sp->GetData(data, data_error);
-        if (data_error.Fail()) {
-          error = Status::FromErrorStringWithFormat(
-              "Couldn't convert return value to raw data: %s",
-              data_error.AsCString());
-          return error;
-        }
+        auto data_or_err = new_value_sp->GetData();
+
+        if (auto error = data_or_err.takeError())
+          return Status::FromError(
+              llvm::joinErrors(llvm::createStringError(
+                                   "Couldn't convert return value to raw data"),
+                               std::move(error)));
 
+        auto data = std::move(*data_or_err);
+        size_t num_bytes = data.GetByteSize();
         unsigned char buffer[16];
         ByteOrder byte_order = data.GetByteOrder();
 
diff --git a/lldb/source/Plugins/ABI/PowerPC/ABISysV_ppc64.cpp b/lldb/source/Plugins/ABI/PowerPC/ABISysV_ppc64.cpp
index 8e9b56ddc2efe..2db4da6b76fa3 100644
--- a/lldb/source/Plugins/ABI/PowerPC/ABISysV_ppc64.cpp
+++ b/lldb/source/Plugins/ABI/PowerPC/ABISysV_ppc64.cpp
@@ -319,15 +319,16 @@ Status ABISysV_ppc64::SetReturnValueObject(lldb::StackFrameSP &frame_sp,
       compiler_type.IsPointerType()) {
     const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoByName("r3", 0);
 
-    DataExtractor data;
-    Status data_error;
-    size_t num_bytes = new_value_sp->GetData(data, data_error);
-    if (data_error.Fail()) {
-      error = Status::FromErrorStringWithFormat(
-          "Couldn't convert return value to raw data: %s",
-          data_error.AsCString());
-      return error;
-    }
+    auto data_or_err = new_value_sp->GetData();
+
+    if (auto error = data_or_err.takeError())
+      return Status::FromError(llvm::joinErrors(
+          llvm::createStringError("Couldn't convert return value to raw data"),
+          std::move(error)));
+
+    auto data = std::move(*data_or_err);
+
+    size_t num_bytes = data.GetByteSize();
     lldb::offset_t offset = 0;
     if (num_bytes <= 8) {
       uint64_t raw_value = data.GetMaxU64(&offset, num_bytes);
@@ -351,16 +352,16 @@ Status ABISysV_ppc64::SetReturnValueObject(lldb::StackFrameSP &frame_sp,
         return error;
       }
       if (*bit_width <= 64) {
-        DataExtractor data;
-        Status data_error;
-        size_t num_bytes = new_value_sp->GetData(data, data_error);
-        if (data_error.Fail()) {
-          error = Status::FromErrorStringWithFormat(
-              "Couldn't convert return value to raw data: %s",
-              data_error.AsCString());
-          return error;
-        }
+        auto data_or_err = new_value_sp->GetData();
+
+        if (auto error = data_or_err.takeError())
+          return Status::FromError(
+              llvm::joinErrors(llvm::createStringError(
+                                   "Couldn't convert return value to raw data"),
+                               std::move(error)));
 
+        auto data = std::move(*data_or_err);
+        size_t num_bytes = data.GetByteSize();
         unsigned char buffer[16];
         ByteOrder byte_order = data.GetByteOrder();
 
diff --git a/lldb/source/Plugins/ABI/RISCV/ABISysV_riscv.cpp b/lldb/source/Plugins/ABI/RISCV/ABISysV_riscv.cpp
index 99263ce391f34..60284d048bcfb 100644
--- a/lldb/source/Plugins/ABI/RISCV/ABISysV_riscv.cpp
+++ b/lldb/source/Plugins/ABI/RISCV/ABISysV_riscv.cpp
@@ -388,15 +388,17 @@ Status ABISysV_riscv::SetReturnValueObject(StackFrameSP &frame_sp,
     return result;
   }
 
-  DataExtractor data;
-  size_t num_bytes = new_value_sp->GetData(data, result);
+  auto data_or_err = new_value_sp->GetData();
 
-  if (result.Fail()) {
-    result = Status::FromErrorStringWithFormat(
-        "Couldn't convert return value to raw data: %s", result.AsCString());
-    return result;
+  if (auto error = data_or_err.takeError()) {
+    return Status::FromError(llvm::joinErrors(
+        llvm::createStringError("Couldn't convert return value to raw data: "),
+        std::move(error)));
   }
 
+  auto data = std::move(*data_or_err);
+  size_t num_bytes = data.GetByteSize();
+
   size_t reg_size = m_is_rv64 ? 8 : 4;
   if (num_bytes <= 2 * reg_size) {
     offset_t offset = 0;
diff --git a/lldb/source/Plugins/ABI/SystemZ/ABISysV_s390x.cpp b/lldb/source/Plugins/ABI/SystemZ/ABISysV_s390x.cpp
index 89a8381f3fe4a..3703cbe8f89c9 100644
--- a/lldb/source/Plugins/ABI/SystemZ/ABISysV_s390x.cpp
+++ b/lldb/source/Plugins/ABI/SystemZ/ABISysV_s390x.cpp
@@ -403,15 +403,16 @@ Status ABISysV_s390x::SetReturnValueObject(lldb::StackFrameSP &frame_sp,
       compiler_type.IsPointerType()) {
     const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoByName("r2", 0);
 
-    DataExtractor data;
-    Status data_error;
-    size_t num_bytes = new_value_sp->GetData(data, data_error);
-    if (data_error.Fail()) {
-      error = Status::FromErrorStringWithFormat(
+    auto data_or_err = new_value_sp->GetData();
+    if (auto error = data_or_err.takeError()) {
+      return Status::FromErrorStringWithFormat(
           "Couldn't convert return value to raw data: %s",
-          data_error.AsCString());
-      return error;
+          llvm::toString(std::move(error)).c_str());
     }
+
+    auto data = std::move(*data_or_err);
+
+    size_t num_bytes = data.GetByteSize();
     lldb::offset_t offset = 0;
     if (num_bytes <= 8) {
       uint64_t raw_value = data.GetMaxU64(&offset, num_bytes);
@@ -437,16 +438,15 @@ Status ABISysV_s390x::SetReturnValueObject(lldb::StackFrameSP &frame_sp,
       if (*bit_width <= 64) {
         const RegisterInfo *f0_info = reg_ctx->GetRegisterInfoByName("f0", 0);
         RegisterValue f0_value;
-        DataExtractor data;
-        Status data_error;
-        size_t num_bytes = new_value_sp->GetData(data, data_error);
-        if (data_error.Fail()) {
-          error = Status::FromErrorStringWithFormat(
-              "Couldn't convert return value to raw data: %s",
-              data_error.AsCString());
-          return error;
-        }
-
+        auto data_or_err = new_value_sp->GetData();
+        if (auto error = data_or_err.takeError())
+          return Status::FromError(
+              llvm::joinErrors(llvm::createStringError(
+                                   "Couldn't convert return value to raw data"),
+                               std::move(error)));
+
+        auto data = std::move(*data_or_err);
+        size_t num_bytes = data.GetByteSize();
         unsigned char buffer[8];
         ByteOrder byte_order = data.GetByteOrder();
 
diff --git a/lldb/source/Plugins/ABI/X86/ABIMacOSX_i386.cpp b/lldb/source/Plugins/ABI/X86/ABIMacOSX_i386.cpp
index 5ede8d2c1db23..89ff4c2dc9dd8 100644
--- a/lldb/source/Plugins/ABI/X86/ABIMacOSX_i386.cpp
+++ b/lldb/source/Plugins/ABI/X86/ABIMacOSX_i386.cpp
@@ -206,30 +206,31 @@ Status ABIMacOSX_i386::SetReturnValueObject(lldb::StackFrameSP &frame_sp,
   bool set_it_simple = false;
   if (compiler_type.IsIntegerOrEnumerationType(is_signed) ||
       compiler_type.IsPointerType()) {
-    DataExtractor data;
-    Status data_error;
-    size_t num_bytes = new_value_sp->GetData(data, data_error);
-    if (data_error.Fail()) {
+    auto data_or_err = new_value_sp->GetData();
+    if (auto err = data_or_err.takeError()) {
       error = Status::FromErrorStringWithFormat(
           "Couldn't convert return value to raw data: %s",
-          data_error.AsCString());
+          llvm::toString(std::move(err)).c_str());
       return error;
     }
+    size_t num_bytes = data_or_err->GetByteSize();
+
     lldb::offset_t offset = 0;
     if (num_bytes <= 8) {
       const RegisterInfo *eax_info = reg_ctx->GetRegisterInfoByName("eax", 0);
       if (num_bytes <= 4) {
-        uint32_t raw_value = data.GetMaxU32(&offset, num_bytes);
+        uint32_t raw_value = data_or_err->GetMaxU32(&offset, num_bytes);
 
         if (reg_ctx->WriteRegisterFromUnsigned(eax_info, raw_value))
           set_it_simple = true;
       } else {
-        uint32_t raw_value = data.GetMaxU32(&offset, 4);
+        uint32_t raw_value = data_or_err->GetMaxU32(&offset, 4);
 
         if (reg_ctx->WriteRegisterFromUnsigned(eax_info, raw_value)) {
           const RegisterInfo *edx_info =
               reg_ctx->GetRegisterInfoByName("edx", 0);
-          uint32_t raw_value = data.GetMaxU32(&offset, num_bytes - offset);
+          uint32_t raw_value =
+              data_or_err->GetMaxU32(&offset, num_bytes - offset);
 
           if (reg_ctx->WriteRegisterFromUnsigned(edx_info, raw_value))
             set_it_simple = true;
diff --git a/lldb/source/Plugins/ABI/X86/ABISysV_i386.cpp b/lldb/source/Plugins/ABI/X86/ABISysV_i386.cpp
index bf3547085052a..11aa626828ca1 100644
--- a/lldb/source/Plugins/ABI/X86/ABISysV_i386.cpp
+++ b/lldb/source/Plugins/ABI/X86/ABISysV_i386.cpp
@@ -215,17 +215,16 @@ Status ABISysV_i386::SetReturnValueObject(lldb::StackFrameSP &frame_sp,
   const uint32_t type_flags = compiler_type.GetTypeInfo();
   Thread *thread = frame_sp->GetThread().get();
   RegisterContext *reg_ctx = thread->GetRegisterContext().get();
-  DataExtractor data;
-  Status data_error;
-  size_t num_bytes = new_value_sp->GetData(data, data_error);
+  auto data_or_err = new_value_sp->GetData();
   bool register_write_successful = true;
 
-  if (data_error.Fail()) {
+  if (auto err = data_or_err.takeError()) {
     error = Status::FromErrorStringWithFormat(
         "Couldn't convert return value to raw data: %s",
-        data_error.AsCString());
+        llvm::toString(std::move(err)).c_str());
     return error;
   }
+  size_t num_bytes = data_or_err->GetByteSize();
 
   // Following "IF ELSE" block categorizes various 'Fundamental Data Types'.
   // The terminology 'Fundamental Data Types' used here is adopted from Table
@@ -240,7 +239,7 @@ Status ABISysV_i386::SetReturnValueObject(lldb::StackFrameSP &frame_sp,
     }
     lldb::offset_t offset = 0;
     const RegisterInfo *eax_info = reg_ctx->GetRegisterInfoByName("eax", 0);
-    uint32_t raw_value = data.GetMaxU32(&offset, num_bytes);
+    uint32_t raw_value = data_or_err->GetMaxU32(&offset, num_bytes);
     register_write_successful =
         reg_ctx->WriteRegisterFromUnsigned(eax_info, raw_value);
   } else if ((type_flags & eTypeIsScalar) ||
@@ -259,9 +258,10 @@ Status ABISysV_i386::SetReturnValueObject(lldb::StackFrameSP &frame_sp,
         // handle it
         break;
       case 8: {
-        uint32_t raw_value_low = data.GetMaxU32(&offset, 4);
+        uint32_t raw_value_low = data_or_err->GetMaxU32(&offset, 4);
         const RegisterInfo *edx_info = reg_ctx->GetRegisterInfoByName("edx", 0);
-        uint32_t raw_value_high = data.GetMaxU32(&offset, num_bytes - offset);
+        uint32_t raw_value_high =
+            data_or_err->GetMaxU32(&offset, num_bytes - offset);
         register_write_successful =
             (reg_ctx->WriteRegisterFromUnsigned(eax_info, raw_value_low) &&
              reg_ctx->WriteRegisterFromUnsigned(edx_info, raw_value_high));
@@ -270,7 +270,7 @@ Status ABISysV_i386::SetReturnValueObject(lldb::StackFrameSP &frame_sp,
       case 4:
       case 2:
       case 1: {
-        uint32_t raw_value = data.GetMaxU32(&offset, num_bytes);
+        uint32_t raw_value = data_or_err->GetMaxU32(&offset, num_bytes);
         register_write_successful =
             reg_ctx->WriteRegisterFromUnsigned(eax_info, raw_value);
         break;
@@ -278,7 +278,7 @@ Status ABISysV_i386::SetReturnValueObject(lldb::StackFrameSP &frame_sp,
       }
     } else if (type_flags & eTypeIsEnumeration) // handles enum
     {
-      uint32_t raw_value = data.GetMaxU32(&offset, num_bytes);
+      uint32_t raw_value = data_or_err->GetMaxU32(&offset, num_bytes);
       register_write_successful =
           reg_ctx->WriteRegisterFromUnsigned(eax_info, raw_value);
     } else if (type_flags & eTypeIsFloat) // 'Floating Point'
@@ -314,11 +314,11 @@ Status ABISysV_i386::SetReturnValueObject(lldb::StackFrameSP &frame_sp,
       {
         long double value_long_dbl = 0.0;
         if (num_bytes == 4)
-          value_long_dbl = data.GetFloat(&offset);
+          value_long_dbl = data_or_err->GetFloat(&offset);
         else if (num_bytes == 8)
-          value_long_dbl = data.GetDouble(&offset);
+          value_long_dbl = data_or_err->GetDouble(&offset);
         else if (num_bytes == 12)
-          value_long_dbl = data.GetLongDouble(&offset);
+          value_long_dbl = data_or_err->GetLongDouble(&offset);
         else {
           error = Status::FromErrorString(
               "Invalid number of bytes for this return type");
diff --git a/lldb/source/Plugins/ABI/X86/ABISysV_x86_64.cpp b/lldb/source/Plugins/ABI/X86/ABISysV_x86_64.cpp
index c6dba91cd4613..d859726c85670 100644
--- a/lldb/source/Plugins/ABI/X86/ABISysV_x86_64.cpp
+++ b/lldb/source/Plugins/ABI/X86/ABISysV_x86_64.cpp
@@ -317,18 +317,18 @@ Status ABISysV_x86_64::SetReturnValueObject(lldb::StackFrameSP &frame_sp,
       compiler_type.IsPointerType()) {
     const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoByName("rax", 0);
 
-    DataExtractor data;
-    Status data_error;
-    size_t num_bytes = new_value_sp->GetData(data, data_error);
-    if (data_error.Fail()) {
+    auto data_or_err = new_value_sp->GetData();
+    if (auto err = data_or_err.takeError()) {
       error = Status::FromErrorStringWithFormat(
           "Couldn't convert return value to raw data: %s",
-          data_error.AsCString());
+          llvm::toString(std::move(err)).c_str());
       return error;
     }
+
+    size_t num_bytes = data_or_err->GetByteSize();
     lldb::offset_t offset = 0;
     if (num_bytes <= 8) {
-      uint64_t raw_value = data.GetMaxU64(&offset, num_bytes);
+      uint64_t raw_value = data_or_err->GetMaxU64(&offset, num_bytes);
 
       if (reg_ctx->WriteRegisterFromUnsigned(reg_info, raw_value))
         set_it_simple = true;
@@ -352,20 +352,19 @@ Status ABISysV_x86_64::SetReturnValueObject(lldb::StackFrameSP &frame_sp,
         const RegisterInfo *xmm0_info =
             reg_ctx->GetRegisterInfoByName("xmm0", 0);
         RegisterValue xmm0_value;
-        DataExtractor data;
-        Status data_error;
-        size_t num_bytes = new_value_sp->GetData(data, data_error);
-        if (data_error.Fail()) {
+        auto data_or_err = new_value_sp->GetData();
+        if (auto err = data_or_err.takeError()) {
           error = Status::FromErrorStringWithFormat(
               "Couldn't convert return value to raw data: %s",
-              data_error.AsCString());
+              llvm::toString(std::move(err)).c_str());
           return error;
         }
 
+        size_t num_bytes = data_or_err->GetByteSize();
         unsigned char buffer[16];
-        ByteOrder byte_order = data.GetByteOrder();
+        ByteOrder byte_order = data_or_err->GetByteOrder();
 
-        data.CopyByteOrderedData(0, num_bytes, buffer, 16, byte_order);
+        data_or_err->CopyByteOrderedData(0, num_bytes, buffer, 16, byte_order);
         xmm0_value.SetBytes(buffer, 16, byte_order);
         reg_ctx->WriteRegister(xmm0_info, xmm0_value);
         set_it_simple = true;
diff --git a/lldb/source/Plugins/ABI/X86/ABIWindows_x86_64.cpp b/lldb/source/Plugins/ABI/X86/ABIWindows_x86_64.cpp
index 04f0bf112ae64..87f0278643e1e 100644
--- a/lldb/source/Plugins/ABI/X86/ABIWindows_x86_64.cpp
+++ b/lldb/source/Plugins/ABI/X86/ABIWindows_x86_64.cpp
@@ -322,18 +322,20 @@ Status ABIWindows_x86_64::SetReturnValueObject(lldb::StackFrameSP &frame_sp,
       compiler_type.IsPointerType()) {
     const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoByName("rax", 0);
 
-    DataExtractor data;
-    Status data_error;
-    size_t num_bytes = new_value_sp->GetData(data, data_error);
-    if (data_error.Fail()) {
+    auto data_or_err = new_value_sp->GetData();
+
+    if (auto err = data_or_err.takeError()) {
       error = Status::FromErrorStringWithFormat(
           "Couldn't convert return value to raw data: %s",
-          data_error.AsCString());
+          llvm::toString(std::move(err)).c_str());
       return error;
     }
+
+    size_t num_bytes = data_or_err->GetByteSize();
+
     lldb::offset_t offset = 0;
     if (num_bytes <= 8) {
-      uint64_t raw_value = data.GetMaxU64(&offset, num_bytes);
+      uint64_t raw_value = data_or_err->GetMaxU64(&offset, num_bytes);
 
       if (reg_ctx->WriteRegisterFromUnsigned(reg_info, raw_value))
         set_it_simple = true;
@@ -357,20 +359,20 @@ Status ABIWindows_x86_64::SetReturnValueObject(lldb::StackFrameSP &frame_sp,
         const RegisterInfo *xmm0_info =
             reg_ctx->GetRegisterInfoByName("xmm0", 0);
         RegisterValue xmm0_value;
-        DataExtractor data;
-        Status data_error;
-        size_t num_bytes = new_value_sp->GetData(data, data_error);
-        if (data_error.Fail()) {
+
+        auto data_or_err = new_value_sp->GetData();
+        if (auto err = data_or_err.takeError()) {
           error = Status::FromErrorStringWithFormat(
               "Couldn't convert return value to raw data: %s",
-              data_error.AsCString());
+              llvm::toString(std::move(err)).c_str());
           return error;
         }
+        size_t num_bytes = data_or_err->GetByteSize();
 
         unsigned char buffer[16];
-        ByteOrder byte_order = data.GetByteOrder();
+        ByteOrder byte_order = data_or_err->GetByteOrder();
 
-        data.CopyByteOrderedData(0, num_bytes, buffer, 16, byte_order);
+        data_or_err->CopyByteOrderedData(0, num_bytes, buffer, 16, byte_order);
         xmm0_value.SetBytes(buffer, 16, byte_order);
         reg_ctx->WriteRegister(xmm0_info, xmm0_value);
         set_it_simple = true;

>From 058a5036a53703c5506a238145dfb83d1ef3859d Mon Sep 17 00:00:00 2001
From: medievalghoul <61852278+medievalghoul at users.noreply.github.com>
Date: Wed, 26 Mar 2025 21:22:14 -0400
Subject: [PATCH 11/18] forth wave: fix format

---
 lldb/source/API/SBValue.cpp | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/lldb/source/API/SBValue.cpp b/lldb/source/API/SBValue.cpp
index 27ee6131fe850..baeedc8703de7 100644
--- a/lldb/source/API/SBValue.cpp
+++ b/lldb/source/API/SBValue.cpp
@@ -1382,11 +1382,10 @@ lldb::SBData SBValue::GetData() {
   lldb::ValueObjectSP value_sp(GetSP(locker));
   if (value_sp) {
     auto data_or_err = value_sp->GetData();
-    if (!data_or_err) {
-
+    if (!data_or_err)
       LLDB_LOG_ERRORV(GetLog(LLDBLog::API), data_or_err.takeError(),
                       "SBValue GetData failed to extract info: {0}");
-    }
+
     DataExtractorSP data_sp(new DataExtractor());
     *sb_data = data_sp;
   }

>From 83dcfb0be19edbcc9a867bc2c6c8e835fc5232d7 Mon Sep 17 00:00:00 2001
From: medievalghoul <61852278+medievalghoul at users.noreply.github.com>
Date: Wed, 26 Mar 2025 21:32:06 -0400
Subject: [PATCH 12/18] forth wave: fix more formats

---
 lldb/source/DataFormatters/TypeFormat.cpp | 3 ++-
 lldb/source/Expression/Materializer.cpp   | 3 +--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/lldb/source/DataFormatters/TypeFormat.cpp b/lldb/source/DataFormatters/TypeFormat.cpp
index 79eb08a493d66..255f8ad41232f 100644
--- a/lldb/source/DataFormatters/TypeFormat.cpp
+++ b/lldb/source/DataFormatters/TypeFormat.cpp
@@ -53,6 +53,7 @@ bool TypeFormatImpl_Format::FormatObject(ValueObject *valobj,
                       "Failed to extract data: {0}");
       return false;
     }
+    auto data = std::move(*data_or_err);
     if (context_type == Value::ContextType::RegisterInfo) {
       const RegisterInfo *reg_info = value.GetRegisterInfo();
       if (reg_info) {
@@ -92,7 +93,7 @@ bool TypeFormatImpl_Format::FormatObject(ValueObject *valobj,
               target_sp->ReadCStringFromMemory(
                   address, (char *)buffer_sp->GetBytes(), max_len, error);
               if (error.Success())
-                data_or_err->SetData(buffer_sp);
+                data.SetData(buffer_sp);
             }
           }
         } else {
diff --git a/lldb/source/Expression/Materializer.cpp b/lldb/source/Expression/Materializer.cpp
index 3669957f3d397..d1afd9232e7fb 100644
--- a/lldb/source/Expression/Materializer.cpp
+++ b/lldb/source/Expression/Materializer.cpp
@@ -525,8 +525,7 @@ class EntityVariableBase : public Materializer::Entity {
         auto data_or_err = valobj_sp->GetData();
         if (auto error = data_or_err.takeError()) {
             err = Status::FromError(
-                llvm::joinErrors(
-                  llvm::createStringError("couldn't get the value of %s: ", 
+                llvm::joinErrors(llvm::createStringError("couldn't get the value of %s: ", 
                     GetName().AsCString()), std::move(error)));
             return;
         }

>From ea4f3c3c6520d5ca45eced51b3bb690f7820b94c Mon Sep 17 00:00:00 2001
From: medievalghoul <61852278+medievalghoul at users.noreply.github.com>
Date: Wed, 26 Mar 2025 21:46:05 -0400
Subject: [PATCH 13/18] fix error message

---
 lldb/source/Expression/Materializer.cpp | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/lldb/source/Expression/Materializer.cpp b/lldb/source/Expression/Materializer.cpp
index d1afd9232e7fb..8b8c07a0393dc 100644
--- a/lldb/source/Expression/Materializer.cpp
+++ b/lldb/source/Expression/Materializer.cpp
@@ -486,10 +486,12 @@ class EntityVariableBase : public Materializer::Entity {
       auto valobj_extractor_or_err = valobj_sp->GetData();
 
       if (auto error = valobj_extractor_or_err.takeError()) {
-        err = Status::FromErrorStringWithFormat(
-            "couldn't read contents of reference variable %s: %s",
-            GetName().AsCString(), llvm::toString(std::move(error)).c_str());
+        err = Status::FromError(llvm::joinErrors(
+            llvm::createStringError("couldn't read contents of reference variable %s: ",
+                                    GetName().AsCString()),
+            std::move(error)));
         return;
+
       }
 
       lldb::offset_t offset = 0;
@@ -524,10 +526,11 @@ class EntityVariableBase : public Materializer::Entity {
       } else {
         auto data_or_err = valobj_sp->GetData();
         if (auto error = data_or_err.takeError()) {
-            err = Status::FromError(
-                llvm::joinErrors(llvm::createStringError("couldn't get the value of %s: ", 
-                    GetName().AsCString()), std::move(error)));
-            return;
+          err = Status::FromError(llvm::joinErrors(
+              llvm::createStringError("couldn't get the value of %s: ",
+                                      GetName().AsCString()),
+              std::move(error)));
+          return;
         }
 
         auto data = std::move(*data_or_err);

>From 48e953514c7f198cabc541b24a6fa1de42fcd713 Mon Sep 17 00:00:00 2001
From: medievalghoul <61852278+medievalghoul at users.noreply.github.com>
Date: Wed, 26 Mar 2025 21:52:35 -0400
Subject: [PATCH 14/18] error message fix

---
 lldb/source/Expression/Materializer.cpp         |  6 +++---
 lldb/source/Plugins/ABI/Mips/ABISysV_mips64.cpp | 10 ++++------
 2 files changed, 7 insertions(+), 9 deletions(-)

diff --git a/lldb/source/Expression/Materializer.cpp b/lldb/source/Expression/Materializer.cpp
index 8b8c07a0393dc..31babfebb7cd8 100644
--- a/lldb/source/Expression/Materializer.cpp
+++ b/lldb/source/Expression/Materializer.cpp
@@ -487,11 +487,11 @@ class EntityVariableBase : public Materializer::Entity {
 
       if (auto error = valobj_extractor_or_err.takeError()) {
         err = Status::FromError(llvm::joinErrors(
-            llvm::createStringError("couldn't read contents of reference variable %s: ",
-                                    GetName().AsCString()),
+            llvm::createStringError(
+                "couldn't read contents of reference variable %s: ",
+                GetName().AsCString()),
             std::move(error)));
         return;
-
       }
 
       lldb::offset_t offset = 0;
diff --git a/lldb/source/Plugins/ABI/Mips/ABISysV_mips64.cpp b/lldb/source/Plugins/ABI/Mips/ABISysV_mips64.cpp
index 13a46ab2f6a30..1bd29ccab354d 100644
--- a/lldb/source/Plugins/ABI/Mips/ABISysV_mips64.cpp
+++ b/lldb/source/Plugins/ABI/Mips/ABISysV_mips64.cpp
@@ -675,12 +675,10 @@ Status ABISysV_mips64::SetReturnValueObject(lldb::StackFrameSP &frame_sp,
     error = Status::FromErrorString("no registers are available");
 
   auto data_or_err = new_value_sp->GetData();
-  if (auto err = data_or_err.takeError()) {
-    error = Status::FromErrorStringWithFormat(
-        "Couldn't convert return value to raw data: %s",
-        llvm::toString(std::move(err)).c_str());
-    return error;
-  }
+  if (auto err = data_or_err.takeError())
+    return Status::FromError(llvm::joinErrors(
+        llvm::createStringError("Couldn't convert return value to raw data"),
+        std::move(error)));
 
   auto data = std::move(*data_or_err);
   size_t num_bytes = data.GetByteSize();

>From 437917b186f4dae60b71896c8014f3f1d662523d Mon Sep 17 00:00:00 2001
From: medievalghoul <61852278+medievalghoul at users.noreply.github.com>
Date: Wed, 26 Mar 2025 21:59:23 -0400
Subject: [PATCH 15/18] s390x ABI error message fix

---
 lldb/source/Plugins/ABI/SystemZ/ABISysV_s390x.cpp | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/lldb/source/Plugins/ABI/SystemZ/ABISysV_s390x.cpp b/lldb/source/Plugins/ABI/SystemZ/ABISysV_s390x.cpp
index 3703cbe8f89c9..0f69236cf8a5e 100644
--- a/lldb/source/Plugins/ABI/SystemZ/ABISysV_s390x.cpp
+++ b/lldb/source/Plugins/ABI/SystemZ/ABISysV_s390x.cpp
@@ -404,11 +404,10 @@ Status ABISysV_s390x::SetReturnValueObject(lldb::StackFrameSP &frame_sp,
     const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoByName("r2", 0);
 
     auto data_or_err = new_value_sp->GetData();
-    if (auto error = data_or_err.takeError()) {
-      return Status::FromErrorStringWithFormat(
-          "Couldn't convert return value to raw data: %s",
-          llvm::toString(std::move(error)).c_str());
-    }
+    if (auto error = data_or_err.takeError())
+      return Status::FromError(llvm::joinErrors(
+          llvm::createStringError("Couldn't convert return value to raw data"),
+          std::move(error)));
 
     auto data = std::move(*data_or_err);
 

>From 9980b08b26b5dd3c095484fd5dace68700da1bc4 Mon Sep 17 00:00:00 2001
From: medievalghoul <61852278+medievalghoul at users.noreply.github.com>
Date: Wed, 26 Mar 2025 22:27:18 -0400
Subject: [PATCH 16/18] more fix error messaging and format

---
 .../source/Plugins/ABI/X86/ABIMacOSX_i386.cpp | 21 ++++++-----
 lldb/source/Plugins/ABI/X86/ABISysV_i386.cpp  | 31 ++++++++--------
 .../source/Plugins/ABI/X86/ABISysV_x86_64.cpp | 35 ++++++++++---------
 .../Plugins/ABI/X86/ABIWindows_x86_64.cpp     | 35 ++++++++++---------
 4 files changed, 61 insertions(+), 61 deletions(-)

diff --git a/lldb/source/Plugins/ABI/X86/ABIMacOSX_i386.cpp b/lldb/source/Plugins/ABI/X86/ABIMacOSX_i386.cpp
index 89ff4c2dc9dd8..4f66d27392808 100644
--- a/lldb/source/Plugins/ABI/X86/ABIMacOSX_i386.cpp
+++ b/lldb/source/Plugins/ABI/X86/ABIMacOSX_i386.cpp
@@ -207,30 +207,29 @@ Status ABIMacOSX_i386::SetReturnValueObject(lldb::StackFrameSP &frame_sp,
   if (compiler_type.IsIntegerOrEnumerationType(is_signed) ||
       compiler_type.IsPointerType()) {
     auto data_or_err = new_value_sp->GetData();
-    if (auto err = data_or_err.takeError()) {
-      error = Status::FromErrorStringWithFormat(
-          "Couldn't convert return value to raw data: %s",
-          llvm::toString(std::move(err)).c_str());
-      return error;
-    }
-    size_t num_bytes = data_or_err->GetByteSize();
+    if (auto error = data_or_err.takeError())
+      return Status::FromError(llvm::joinErrors(
+          llvm::createStringError("Couldn't convert return value to raw data"),
+          std::move(error)));
+
+    auto data = std::move(*data_or_err);
+    size_t num_bytes = data.GetByteSize();
 
     lldb::offset_t offset = 0;
     if (num_bytes <= 8) {
       const RegisterInfo *eax_info = reg_ctx->GetRegisterInfoByName("eax", 0);
       if (num_bytes <= 4) {
-        uint32_t raw_value = data_or_err->GetMaxU32(&offset, num_bytes);
+        uint32_t raw_value = data.GetMaxU32(&offset, num_bytes);
 
         if (reg_ctx->WriteRegisterFromUnsigned(eax_info, raw_value))
           set_it_simple = true;
       } else {
-        uint32_t raw_value = data_or_err->GetMaxU32(&offset, 4);
+        uint32_t raw_value = data.GetMaxU32(&offset, 4);
 
         if (reg_ctx->WriteRegisterFromUnsigned(eax_info, raw_value)) {
           const RegisterInfo *edx_info =
               reg_ctx->GetRegisterInfoByName("edx", 0);
-          uint32_t raw_value =
-              data_or_err->GetMaxU32(&offset, num_bytes - offset);
+          uint32_t raw_value = data.GetMaxU32(&offset, num_bytes - offset);
 
           if (reg_ctx->WriteRegisterFromUnsigned(edx_info, raw_value))
             set_it_simple = true;
diff --git a/lldb/source/Plugins/ABI/X86/ABISysV_i386.cpp b/lldb/source/Plugins/ABI/X86/ABISysV_i386.cpp
index 11aa626828ca1..fa8233bb444d1 100644
--- a/lldb/source/Plugins/ABI/X86/ABISysV_i386.cpp
+++ b/lldb/source/Plugins/ABI/X86/ABISysV_i386.cpp
@@ -218,13 +218,13 @@ Status ABISysV_i386::SetReturnValueObject(lldb::StackFrameSP &frame_sp,
   auto data_or_err = new_value_sp->GetData();
   bool register_write_successful = true;
 
-  if (auto err = data_or_err.takeError()) {
-    error = Status::FromErrorStringWithFormat(
-        "Couldn't convert return value to raw data: %s",
-        llvm::toString(std::move(err)).c_str());
-    return error;
-  }
-  size_t num_bytes = data_or_err->GetByteSize();
+  if (auto error = data_or_err.takeError())
+    return Status::FromError(llvm::joinErrors(
+        llvm::createStringError("Couldn't convert return value to raw data"),
+        std::move(error)));
+
+  auto data = std::move(*data_or_err);
+  size_t num_bytes = data.GetByteSize();
 
   // Following "IF ELSE" block categorizes various 'Fundamental Data Types'.
   // The terminology 'Fundamental Data Types' used here is adopted from Table
@@ -239,7 +239,7 @@ Status ABISysV_i386::SetReturnValueObject(lldb::StackFrameSP &frame_sp,
     }
     lldb::offset_t offset = 0;
     const RegisterInfo *eax_info = reg_ctx->GetRegisterInfoByName("eax", 0);
-    uint32_t raw_value = data_or_err->GetMaxU32(&offset, num_bytes);
+    uint32_t raw_value = data.GetMaxU32(&offset, num_bytes);
     register_write_successful =
         reg_ctx->WriteRegisterFromUnsigned(eax_info, raw_value);
   } else if ((type_flags & eTypeIsScalar) ||
@@ -258,10 +258,9 @@ Status ABISysV_i386::SetReturnValueObject(lldb::StackFrameSP &frame_sp,
         // handle it
         break;
       case 8: {
-        uint32_t raw_value_low = data_or_err->GetMaxU32(&offset, 4);
+        uint32_t raw_value_low = data.GetMaxU32(&offset, 4);
         const RegisterInfo *edx_info = reg_ctx->GetRegisterInfoByName("edx", 0);
-        uint32_t raw_value_high =
-            data_or_err->GetMaxU32(&offset, num_bytes - offset);
+        uint32_t raw_value_high = data.GetMaxU32(&offset, num_bytes - offset);
         register_write_successful =
             (reg_ctx->WriteRegisterFromUnsigned(eax_info, raw_value_low) &&
              reg_ctx->WriteRegisterFromUnsigned(edx_info, raw_value_high));
@@ -270,7 +269,7 @@ Status ABISysV_i386::SetReturnValueObject(lldb::StackFrameSP &frame_sp,
       case 4:
       case 2:
       case 1: {
-        uint32_t raw_value = data_or_err->GetMaxU32(&offset, num_bytes);
+        uint32_t raw_value = data.GetMaxU32(&offset, num_bytes);
         register_write_successful =
             reg_ctx->WriteRegisterFromUnsigned(eax_info, raw_value);
         break;
@@ -278,7 +277,7 @@ Status ABISysV_i386::SetReturnValueObject(lldb::StackFrameSP &frame_sp,
       }
     } else if (type_flags & eTypeIsEnumeration) // handles enum
     {
-      uint32_t raw_value = data_or_err->GetMaxU32(&offset, num_bytes);
+      uint32_t raw_value = data.GetMaxU32(&offset, num_bytes);
       register_write_successful =
           reg_ctx->WriteRegisterFromUnsigned(eax_info, raw_value);
     } else if (type_flags & eTypeIsFloat) // 'Floating Point'
@@ -314,11 +313,11 @@ Status ABISysV_i386::SetReturnValueObject(lldb::StackFrameSP &frame_sp,
       {
         long double value_long_dbl = 0.0;
         if (num_bytes == 4)
-          value_long_dbl = data_or_err->GetFloat(&offset);
+          value_long_dbl = data.GetFloat(&offset);
         else if (num_bytes == 8)
-          value_long_dbl = data_or_err->GetDouble(&offset);
+          value_long_dbl = data.GetDouble(&offset);
         else if (num_bytes == 12)
-          value_long_dbl = data_or_err->GetLongDouble(&offset);
+          value_long_dbl = data.GetLongDouble(&offset);
         else {
           error = Status::FromErrorString(
               "Invalid number of bytes for this return type");
diff --git a/lldb/source/Plugins/ABI/X86/ABISysV_x86_64.cpp b/lldb/source/Plugins/ABI/X86/ABISysV_x86_64.cpp
index d859726c85670..a9dad32a20df0 100644
--- a/lldb/source/Plugins/ABI/X86/ABISysV_x86_64.cpp
+++ b/lldb/source/Plugins/ABI/X86/ABISysV_x86_64.cpp
@@ -318,17 +318,17 @@ Status ABISysV_x86_64::SetReturnValueObject(lldb::StackFrameSP &frame_sp,
     const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoByName("rax", 0);
 
     auto data_or_err = new_value_sp->GetData();
-    if (auto err = data_or_err.takeError()) {
-      error = Status::FromErrorStringWithFormat(
-          "Couldn't convert return value to raw data: %s",
-          llvm::toString(std::move(err)).c_str());
-      return error;
-    }
+    if (auto error = data_or_err.takeError())
+      return Status::FromError(llvm::joinErrors(
+          llvm::createStringError("Couldn't convert return value to raw data"),
+          std::move(error)));
+
+    auto data = std::move(*data_or_err);
 
-    size_t num_bytes = data_or_err->GetByteSize();
+    size_t num_bytes = data.GetByteSize();
     lldb::offset_t offset = 0;
     if (num_bytes <= 8) {
-      uint64_t raw_value = data_or_err->GetMaxU64(&offset, num_bytes);
+      uint64_t raw_value = data.GetMaxU64(&offset, num_bytes);
 
       if (reg_ctx->WriteRegisterFromUnsigned(reg_info, raw_value))
         set_it_simple = true;
@@ -353,18 +353,19 @@ Status ABISysV_x86_64::SetReturnValueObject(lldb::StackFrameSP &frame_sp,
             reg_ctx->GetRegisterInfoByName("xmm0", 0);
         RegisterValue xmm0_value;
         auto data_or_err = new_value_sp->GetData();
-        if (auto err = data_or_err.takeError()) {
-          error = Status::FromErrorStringWithFormat(
-              "Couldn't convert return value to raw data: %s",
-              llvm::toString(std::move(err)).c_str());
-          return error;
-        }
+        if (auto err = data_or_err.takeError())
+          return Status::FromError(
+              llvm::joinErrors(llvm::createStringError(
+                                   "Couldn't convert return value to raw data"),
+                               std::move(err)));
+
+        auto data = std::move(*data_or_err);
 
-        size_t num_bytes = data_or_err->GetByteSize();
+        size_t num_bytes = data.GetByteSize();
         unsigned char buffer[16];
-        ByteOrder byte_order = data_or_err->GetByteOrder();
+        ByteOrder byte_order = data.GetByteOrder();
 
-        data_or_err->CopyByteOrderedData(0, num_bytes, buffer, 16, byte_order);
+        data.CopyByteOrderedData(0, num_bytes, buffer, 16, byte_order);
         xmm0_value.SetBytes(buffer, 16, byte_order);
         reg_ctx->WriteRegister(xmm0_info, xmm0_value);
         set_it_simple = true;
diff --git a/lldb/source/Plugins/ABI/X86/ABIWindows_x86_64.cpp b/lldb/source/Plugins/ABI/X86/ABIWindows_x86_64.cpp
index 87f0278643e1e..cb2b00dc91a99 100644
--- a/lldb/source/Plugins/ABI/X86/ABIWindows_x86_64.cpp
+++ b/lldb/source/Plugins/ABI/X86/ABIWindows_x86_64.cpp
@@ -324,18 +324,18 @@ Status ABIWindows_x86_64::SetReturnValueObject(lldb::StackFrameSP &frame_sp,
 
     auto data_or_err = new_value_sp->GetData();
 
-    if (auto err = data_or_err.takeError()) {
-      error = Status::FromErrorStringWithFormat(
-          "Couldn't convert return value to raw data: %s",
-          llvm::toString(std::move(err)).c_str());
-      return error;
-    }
+    if (auto err = data_or_err.takeError())
+      return Status::FromError(llvm::joinErrors(
+          llvm::createStringError("Couldn't convert return value to raw data"),
+          std::move(err)));
+
+    auto data = std::move(*data_or_err);
 
-    size_t num_bytes = data_or_err->GetByteSize();
+    size_t num_bytes = data.GetByteSize();
 
     lldb::offset_t offset = 0;
     if (num_bytes <= 8) {
-      uint64_t raw_value = data_or_err->GetMaxU64(&offset, num_bytes);
+      uint64_t raw_value = data.GetMaxU64(&offset, num_bytes);
 
       if (reg_ctx->WriteRegisterFromUnsigned(reg_info, raw_value))
         set_it_simple = true;
@@ -361,18 +361,19 @@ Status ABIWindows_x86_64::SetReturnValueObject(lldb::StackFrameSP &frame_sp,
         RegisterValue xmm0_value;
 
         auto data_or_err = new_value_sp->GetData();
-        if (auto err = data_or_err.takeError()) {
-          error = Status::FromErrorStringWithFormat(
-              "Couldn't convert return value to raw data: %s",
-              llvm::toString(std::move(err)).c_str());
-          return error;
-        }
-        size_t num_bytes = data_or_err->GetByteSize();
+        if (auto err = data_or_err.takeError())
+          return Status::FromError(
+              llvm::joinErrors(llvm::createStringError(
+                                   "Couldn't convert return value to raw data"),
+                               std::move(err)));
+
+        auto data = std::move(*data_or_err);
+        size_t num_bytes = data.GetByteSize();
 
         unsigned char buffer[16];
-        ByteOrder byte_order = data_or_err->GetByteOrder();
+        ByteOrder byte_order = data.GetByteOrder();
 
-        data_or_err->CopyByteOrderedData(0, num_bytes, buffer, 16, byte_order);
+        data.CopyByteOrderedData(0, num_bytes, buffer, 16, byte_order);
         xmm0_value.SetBytes(buffer, 16, byte_order);
         reg_ctx->WriteRegister(xmm0_info, xmm0_value);
         set_it_simple = true;

>From c075196e3c99b307eb7293aafb2be04893456df1 Mon Sep 17 00:00:00 2001
From: medievalghoul <61852278+medievalghoul at users.noreply.github.com>
Date: Wed, 26 Mar 2025 22:31:00 -0400
Subject: [PATCH 17/18] fixed logic in TypeFormat.cpp

---
 lldb/source/DataFormatters/TypeFormat.cpp | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/lldb/source/DataFormatters/TypeFormat.cpp b/lldb/source/DataFormatters/TypeFormat.cpp
index 255f8ad41232f..29fd1f6742bb5 100644
--- a/lldb/source/DataFormatters/TypeFormat.cpp
+++ b/lldb/source/DataFormatters/TypeFormat.cpp
@@ -98,11 +98,12 @@ bool TypeFormatImpl_Format::FormatObject(ValueObject *valobj,
           }
         } else {
           auto data_or_err = valobj->GetData();
-          if (!data_or_err)
+          if (!data_or_err) {
             LLDB_LOG_ERRORV(
                 GetLog(LLDBLog::DataFormatters), data_or_err.takeError(),
                 "Failed to extract data for CString info to display: {0}:");
-          return false;
+            return false;
+          }
         }
 
         ExecutionContextScope *exe_scope =

>From 8fcb2054fe56093d76fbda4a9f813d39fd43d24a Mon Sep 17 00:00:00 2001
From: medievalghoul <61852278+medievalghoul at users.noreply.github.com>
Date: Wed, 26 Mar 2025 22:48:21 -0400
Subject: [PATCH 18/18] fixed more logic

---
 lldb/source/Plugins/ABI/Mips/ABISysV_mips64.cpp | 2 +-
 lldb/source/Plugins/ABI/PowerPC/ABISysV_ppc.cpp | 7 ++++---
 lldb/source/ValueObject/ValueObject.cpp         | 5 +++--
 3 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/lldb/source/Plugins/ABI/Mips/ABISysV_mips64.cpp b/lldb/source/Plugins/ABI/Mips/ABISysV_mips64.cpp
index 1bd29ccab354d..b65cbd4dd9de0 100644
--- a/lldb/source/Plugins/ABI/Mips/ABISysV_mips64.cpp
+++ b/lldb/source/Plugins/ABI/Mips/ABISysV_mips64.cpp
@@ -678,7 +678,7 @@ Status ABISysV_mips64::SetReturnValueObject(lldb::StackFrameSP &frame_sp,
   if (auto err = data_or_err.takeError())
     return Status::FromError(llvm::joinErrors(
         llvm::createStringError("Couldn't convert return value to raw data"),
-        std::move(error)));
+        std::move(err)));
 
   auto data = std::move(*data_or_err);
   size_t num_bytes = data.GetByteSize();
diff --git a/lldb/source/Plugins/ABI/PowerPC/ABISysV_ppc.cpp b/lldb/source/Plugins/ABI/PowerPC/ABISysV_ppc.cpp
index 54cd8fb908c50..f7b0347dd4df5 100644
--- a/lldb/source/Plugins/ABI/PowerPC/ABISysV_ppc.cpp
+++ b/lldb/source/Plugins/ABI/PowerPC/ABISysV_ppc.cpp
@@ -438,9 +438,10 @@ Status ABISysV_ppc::SetReturnValueObject(lldb::StackFrameSP &frame_sp,
 
     auto data_or_err = new_value_sp->GetData();
     if (auto err = data_or_err.takeError())
-      return Status::FromErrorStringWithFormat(
-          "Couldn't convert return value to raw data: %s",
-          llvm::toString(std::move(err)).c_str());
+      return Status::FromError(llvm::joinErrors(
+          llvm::createStringError("Couldn't convert return value to raw data"),
+          std::move(err)));
+
 
     auto data = std::move(*data_or_err);
 
diff --git a/lldb/source/ValueObject/ValueObject.cpp b/lldb/source/ValueObject/ValueObject.cpp
index 4d13e460a2ca7..e4544f2d43bcf 100644
--- a/lldb/source/ValueObject/ValueObject.cpp
+++ b/lldb/source/ValueObject/ValueObject.cpp
@@ -691,7 +691,8 @@ size_t ValueObject::GetPointeeData(DataExtractor &data, uint32_t item_idx,
       ValueObjectSP pointee_sp = Dereference(error);
       if (error.Fail() || pointee_sp.get() == nullptr)
         return 0;
-      auto data_or_err = pointee_sp->GetData();
+      
+      auto data_or_err = llvm::expectedToOptional(pointee_sp->GetData());
       if (!data_or_err)
         return 0;
       data = *data_or_err;
@@ -700,7 +701,7 @@ size_t ValueObject::GetPointeeData(DataExtractor &data, uint32_t item_idx,
       ValueObjectSP child_sp = GetChildAtIndex(0);
       if (child_sp.get() == nullptr)
         return 0;
-      auto data_or_err = child_sp->GetData();
+      auto data_or_err = llvm::expectedToOptional(child_sp->GetData());
       if (!data_or_err)
         return 0;
       data = *data_or_err;



More information about the lldb-commits mailing list