[Lldb-commits] [lldb] [lldb] fix unconsumed llvm::Expected's errors (PR #193257)
Charles Zablit via lldb-commits
lldb-commits at lists.llvm.org
Fri May 1 04:06:57 PDT 2026
https://github.com/charles-zablit updated https://github.com/llvm/llvm-project/pull/193257
>From 2253894e045dc753bf462124fb94e49afa62ddc5 Mon Sep 17 00:00:00 2001
From: Charles Zablit <c_zablit at apple.com>
Date: Tue, 21 Apr 2026 18:16:26 +0200
Subject: [PATCH 1/4] [lldb] fix unconsumed llvm::Expected's errors
---
lldb/source/API/SBProcess.cpp | 4 +++-
lldb/source/Host/posix/MainLoopPosix.cpp | 8 ++++++--
lldb/source/Interpreter/ScriptInterpreter.cpp | 2 +-
lldb/source/Plugins/Language/CPlusPlus/LibStdcpp.cpp | 8 +++++---
.../Plugins/Language/CPlusPlus/MsvcStlDeque.cpp | 8 +++++---
.../Plugins/Language/CPlusPlus/MsvcStlVector.cpp | 9 ++++++---
.../Plugins/Process/minidump/ProcessMinidump.cpp | 12 ++++++++----
.../Plugins/Process/scripted/ScriptedThread.cpp | 1 +
.../SymbolFile/NativePDB/PdbAstBuilderClang.cpp | 2 ++
.../SymbolFile/NativePDB/SymbolFileNativePDB.cpp | 12 +++++++++---
.../Debuginfod/SymbolLocatorDebuginfod.cpp | 4 +++-
lldb/source/Symbol/SymbolFileOnDemand.cpp | 5 +++--
lldb/source/Target/Statistics.cpp | 2 ++
lldb/source/Target/Target.cpp | 4 +++-
lldb/source/ValueObject/DILEval.cpp | 4 +++-
lldb/source/ValueObject/ValueObject.cpp | 10 ++++++++--
lldb/source/ValueObject/ValueObjectMemory.cpp | 2 ++
17 files changed, 70 insertions(+), 27 deletions(-)
diff --git a/lldb/source/API/SBProcess.cpp b/lldb/source/API/SBProcess.cpp
index 14ce236b4f1b5..5a2743eef668c 100644
--- a/lldb/source/API/SBProcess.cpp
+++ b/lldb/source/API/SBProcess.cpp
@@ -1041,8 +1041,10 @@ SBStructuredData SBProcess::GetExtendedCrashInformation() {
auto expected_data =
platform_sp->FetchExtendedCrashInformation(*process_sp.get());
- if (!expected_data)
+ if (!expected_data) {
+ llvm::consumeError(expected_data.takeError());
return data;
+ }
StructuredData::ObjectSP fetched_data = *expected_data;
data.m_impl_up->SetObjectSP(fetched_data);
diff --git a/lldb/source/Host/posix/MainLoopPosix.cpp b/lldb/source/Host/posix/MainLoopPosix.cpp
index c6fe7814bd22e..927fb670417ab 100644
--- a/lldb/source/Host/posix/MainLoopPosix.cpp
+++ b/lldb/source/Host/posix/MainLoopPosix.cpp
@@ -392,6 +392,10 @@ bool MainLoopPosix::Interrupt() {
return true;
char c = '.';
- llvm::Expected<size_t> result = m_interrupt_pipe.Write(&c, 1);
- return result && *result != 0;
+ llvm::Expected<size_t> result_or_err = m_interrupt_pipe.Write(&c, 1);
+ if (!result_or_err) {
+ llvm::consumeError(result_or_err.takeError());
+ return false;
+ }
+ return *result_or_err != 0;
}
diff --git a/lldb/source/Interpreter/ScriptInterpreter.cpp b/lldb/source/Interpreter/ScriptInterpreter.cpp
index b00f4db528ce3..448c3714a7a05 100644
--- a/lldb/source/Interpreter/ScriptInterpreter.cpp
+++ b/lldb/source/Interpreter/ScriptInterpreter.cpp
@@ -263,7 +263,7 @@ ScriptInterpreterIORedirect::Create(bool enable_io, Debugger &debugger,
auto nullout = FileSystem::Instance().Open(FileSpec(FileSystem::DEV_NULL),
File::eOpenOptionWriteOnly);
if (!nullout)
- return nullin.takeError();
+ return nullout.takeError();
return std::unique_ptr<ScriptInterpreterIORedirect>(
new ScriptInterpreterIORedirect(std::move(*nullin), std::move(*nullout)));
diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibStdcpp.cpp b/lldb/source/Plugins/Language/CPlusPlus/LibStdcpp.cpp
index f0701da4ae22f..a292aacc3cad1 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/LibStdcpp.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/LibStdcpp.cpp
@@ -470,10 +470,12 @@ bool formatters::LibStdcppVariantSummaryProvider(
if (!index_obj || !data_obj)
return false;
- auto index_bytes = index_obj->GetByteSize();
- if (!index_bytes)
+ auto index_bytes_or_err = index_obj->GetByteSize();
+ if (!index_bytes_or_err) {
+ llvm::consumeError(index_bytes_or_err.takeError());
return false;
- auto npos_value = LibStdcppVariantNposValue(*index_bytes);
+ }
+ auto npos_value = LibStdcppVariantNposValue(*index_bytes_or_err);
auto index = index_obj->GetValueAsUnsigned(0);
if (index == npos_value) {
stream.Printf(" No Value");
diff --git a/lldb/source/Plugins/Language/CPlusPlus/MsvcStlDeque.cpp b/lldb/source/Plugins/Language/CPlusPlus/MsvcStlDeque.cpp
index ed5d6ff1a4f10..d7b70ebf7d6e9 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/MsvcStlDeque.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/MsvcStlDeque.cpp
@@ -141,16 +141,18 @@ lldb_private::formatters::MsvcStlDequeSyntheticFrontEnd::Update() {
if (!element_type)
return lldb::eRefetch;
}
- auto element_size = element_type.GetByteSize(nullptr);
- if (!element_size)
+ auto element_size_or_err = element_type.GetByteSize(nullptr);
+ if (!element_size_or_err) {
+ llvm::consumeError(element_size_or_err.takeError());
return lldb::eRefetch;
+ }
m_map = map_sp.get();
m_exe_ctx_ref = m_backend.GetExecutionContextRef();
m_block_size = block_size.ULongLong();
m_offset = offset;
m_map_size = map_size;
- m_element_size = *element_size;
+ m_element_size = *element_size_or_err;
m_element_type = element_type;
m_size = size;
return lldb::eRefetch;
diff --git a/lldb/source/Plugins/Language/CPlusPlus/MsvcStlVector.cpp b/lldb/source/Plugins/Language/CPlusPlus/MsvcStlVector.cpp
index a5e909a7ae05e..1a2e0691ee1cd 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/MsvcStlVector.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/MsvcStlVector.cpp
@@ -247,9 +247,12 @@ lldb_private::formatters::MsvcStlVectorBoolSyntheticFrontEnd::Update() {
CompilerType begin_ty = begin_sp->GetCompilerType().GetPointeeType();
if (!begin_ty.IsValid())
return lldb::ChildCacheState::eRefetch;
- llvm::Expected<uint64_t> element_bit_size = begin_ty.GetBitSize(nullptr);
- if (!element_bit_size)
+ llvm::Expected<uint64_t> element_bit_size_or_err =
+ begin_ty.GetBitSize(nullptr);
+ if (!element_bit_size_or_err) {
+ llvm::consumeError(element_bit_size_or_err.takeError());
return lldb::ChildCacheState::eRefetch;
+ }
uint64_t base_data_address = begin_sp->GetValueAsUnsigned(0);
if (!base_data_address)
@@ -257,7 +260,7 @@ lldb_private::formatters::MsvcStlVectorBoolSyntheticFrontEnd::Update() {
m_exe_ctx_ref = exe_ctx_ref;
m_count = count;
- m_element_bit_size = *element_bit_size;
+ m_element_bit_size = *element_bit_size_or_err;
m_base_data_address = base_data_address;
return lldb::ChildCacheState::eRefetch;
}
diff --git a/lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp b/lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp
index ac33470bb1c23..0a3f95cf5cee7 100644
--- a/lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp
+++ b/lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp
@@ -208,17 +208,21 @@ Status ProcessMinidump::DoLoadCore() {
m_thread_list = m_minidump_parser->GetThreads();
auto exception_stream_it = m_minidump_parser->GetExceptionStreams();
- for (auto exception_stream : exception_stream_it) {
+ for (auto exception_stream_or_err : exception_stream_it) {
// If we can't read an exception stream skip it
// We should probably serve a warning
- if (!exception_stream)
+ if (!exception_stream_or_err) {
+ llvm::consumeError(exception_stream_or_err.takeError());
continue;
+ }
+ const llvm::minidump::ExceptionStream &exception_stream =
+ *exception_stream_or_err;
if (!m_exceptions_by_tid
- .try_emplace(exception_stream->ThreadId, exception_stream.get())
+ .try_emplace(exception_stream.ThreadId, exception_stream)
.second) {
return Status::FromErrorStringWithFormatv(
- "Duplicate exception stream for tid {0}", exception_stream->ThreadId);
+ "Duplicate exception stream for tid {0}", exception_stream.ThreadId);
}
}
diff --git a/lldb/source/Plugins/Process/scripted/ScriptedThread.cpp b/lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
index eafd4b90ce296..7539cc7eb3545 100644
--- a/lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
+++ b/lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
@@ -258,6 +258,7 @@ bool ScriptedThread::LoadArtificialStackFrames() {
auto frame_from_script_obj_or_err = create_frame_from_script_object(idx);
if (!frame_from_script_obj_or_err) {
+ llvm::consumeError(frame_from_script_obj_or_err.takeError());
return ScriptedInterface::ErrorWithMessage<bool>(
LLVM_PRETTY_FUNCTION,
llvm::Twine("Couldn't add artificial frame (" + llvm::Twine(idx) +
diff --git a/lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilderClang.cpp b/lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilderClang.cpp
index b07302bc7c7bf..9d5ba762da757 100644
--- a/lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilderClang.cpp
+++ b/lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilderClang.cpp
@@ -908,6 +908,8 @@ clang::FunctionDecl *PdbAstBuilderClang::CreateFunctionDecl(
index.tpi().findFullDeclForForwardRef(class_index);
if (eti) {
tag_record = CVTagRecord::create(index.tpi().getType(*eti)).asTag();
+ } else {
+ llvm::consumeError(eti.takeError());
}
}
diff --git a/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp b/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp
index 176f1f992c02d..60d4a197554bb 100644
--- a/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp
+++ b/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp
@@ -1497,8 +1497,10 @@ bool SymbolFileNativePDB::ParseLineTable(CompileUnit &comp_unit) {
for (const LineColumnEntry &group : lines) {
llvm::Expected<uint32_t> file_index_or_err =
GetFileIndex(*cii, group.NameIndex);
- if (!file_index_or_err)
+ if (!file_index_or_err) {
+ llvm::consumeError(file_index_or_err.takeError());
continue;
+ }
uint32_t file_index = file_index_or_err.get();
lldbassert(!group.LineNumbers.empty());
CompilandIndexItem::GlobalLineTable::Entry line_entry(
@@ -1701,8 +1703,10 @@ void SymbolFileNativePDB::ParseInlineSite(PdbCompilandSymId id,
FileSpec decl_file;
llvm::Expected<uint32_t> file_index_or_err =
GetFileIndex(*cii, inlinee_line.Header->FileID);
- if (!file_index_or_err)
+ if (!file_index_or_err) {
+ llvm::consumeError(file_index_or_err.takeError());
return;
+ }
uint32_t file_offset = file_index_or_err.get();
decl_file = files.GetFileSpecAtIndex(file_offset);
uint32_t decl_line = inlinee_line.Header->SourceLineNum;
@@ -1937,8 +1941,10 @@ size_t SymbolFileNativePDB::ParseSymbolArrayInScope(
void SymbolFileNativePDB::DumpClangAST(Stream &s, llvm::StringRef filter,
bool show_color) {
auto ts_or_err = GetTypeSystemForLanguage(eLanguageTypeC_plus_plus);
- if (!ts_or_err)
+ if (!ts_or_err) {
+ llvm::consumeError(ts_or_err.takeError());
return;
+ }
auto ts = *ts_or_err;
TypeSystemClang *clang = llvm::dyn_cast_or_null<TypeSystemClang>(ts.get());
if (!clang)
diff --git a/lldb/source/Plugins/SymbolLocator/Debuginfod/SymbolLocatorDebuginfod.cpp b/lldb/source/Plugins/SymbolLocator/Debuginfod/SymbolLocatorDebuginfod.cpp
index 1ffbc349a5841..75ba7c91ebabc 100644
--- a/lldb/source/Plugins/SymbolLocator/Debuginfod/SymbolLocatorDebuginfod.cpp
+++ b/lldb/source/Plugins/SymbolLocator/Debuginfod/SymbolLocatorDebuginfod.cpp
@@ -173,8 +173,10 @@ GetFileForModule(const ModuleSpec &module_spec,
PluginProperties &plugin_props = GetGlobalPluginProperties();
llvm::Expected<std::string> cache_path_or_err = plugin_props.GetCachePath();
// A cache location is *required*.
- if (!cache_path_or_err)
+ if (!cache_path_or_err) {
+ llvm::consumeError(cache_path_or_err.takeError());
return {};
+ }
std::string cache_path = *cache_path_or_err;
llvm::SmallVector<llvm::StringRef> debuginfod_urls =
llvm::getDefaultDebuginfodUrls();
diff --git a/lldb/source/Symbol/SymbolFileOnDemand.cpp b/lldb/source/Symbol/SymbolFileOnDemand.cpp
index 5ff4d7d23fc81..fec1146bf4ad9 100644
--- a/lldb/source/Symbol/SymbolFileOnDemand.cpp
+++ b/lldb/source/Symbol/SymbolFileOnDemand.cpp
@@ -515,10 +515,11 @@ SymbolFileOnDemand::GetParameterStackSize(const Symbol &symbol) {
if (log) {
llvm::Expected<lldb::addr_t> stack_size =
m_sym_file_impl->GetParameterStackSize(symbol);
- if (stack_size) {
+ if (stack_size)
LLDB_LOG(log, "{0} stack size would return for symbol {1} if hydrated.",
*stack_size, symbol.GetName());
- }
+ else
+ llvm::consumeError(stack_size.takeError());
}
return SymbolFile::GetParameterStackSize(symbol);
}
diff --git a/lldb/source/Target/Statistics.cpp b/lldb/source/Target/Statistics.cpp
index 4a38500a22307..01f61eca396ef 100644
--- a/lldb/source/Target/Statistics.cpp
+++ b/lldb/source/Target/Statistics.cpp
@@ -507,6 +507,8 @@ llvm::json::Value DebuggerStats::ReportStatistics(
if (auto json_transcript = llvm::json::parse(buffer))
global_stats.try_emplace("transcript",
std::move(json_transcript.get()));
+ else
+ llvm::consumeError(json_transcript.takeError());
}
}
diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp
index 97bbbc0f9e5a2..aaf4594802666 100644
--- a/lldb/source/Target/Target.cpp
+++ b/lldb/source/Target/Target.cpp
@@ -4203,8 +4203,10 @@ Target::StopHookScripted::HandleStop(ExecutionContext &exc_ctx,
auto should_stop_or_err = m_interface_sp->HandleStop(exc_ctx, stream);
output_sp->PutCString(
reinterpret_cast<StreamString *>(stream.get())->GetData());
- if (!should_stop_or_err)
+ if (!should_stop_or_err) {
+ llvm::consumeError(should_stop_or_err.takeError());
return StopHookResult::KeepStopped;
+ }
return *should_stop_or_err ? StopHookResult::KeepStopped
: StopHookResult::RequestContinue;
diff --git a/lldb/source/ValueObject/DILEval.cpp b/lldb/source/ValueObject/DILEval.cpp
index 7801b9225f19e..a03c3b9ab0652 100644
--- a/lldb/source/ValueObject/DILEval.cpp
+++ b/lldb/source/ValueObject/DILEval.cpp
@@ -94,7 +94,7 @@ Interpreter::UnaryConversion(lldb::ValueObjectSP valobj, uint32_t location) {
llvm::Expected<uint64_t> uint_bit_size =
uint_type.GetBitSize(m_exe_ctx_scope.get());
if (!uint_bit_size)
- return int_bit_size.takeError();
+ return uint_bit_size.takeError();
if (bitfield_size < *int_bit_size ||
(in_type.IsSigned() && bitfield_size == *int_bit_size))
return valobj->CastToBasicType(int_type);
@@ -1283,6 +1283,7 @@ Interpreter::VerifyArithmeticCast(CompilerType source_type,
} else {
std::string errMsg = llvm::formatv("unable to get byte size for type {0}",
target_type.TypeDescription());
+ llvm::consumeError(temp.takeError());
return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(errMsg), location,
target_type.TypeDescription().length());
@@ -1293,6 +1294,7 @@ Interpreter::VerifyArithmeticCast(CompilerType source_type,
} else {
std::string errMsg = llvm::formatv("unable to get byte size for type {0}",
source_type.TypeDescription());
+ llvm::consumeError(temp.takeError());
return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(errMsg), location,
source_type.TypeDescription().length());
diff --git a/lldb/source/ValueObject/ValueObject.cpp b/lldb/source/ValueObject/ValueObject.cpp
index 6a12a2e45b2e1..90910608127fa 100644
--- a/lldb/source/ValueObject/ValueObject.cpp
+++ b/lldb/source/ValueObject/ValueObject.cpp
@@ -1191,11 +1191,13 @@ llvm::Expected<bool> ValueObject::GetValueAsBool() {
auto value_or_err = GetValueAsAPSInt();
if (value_or_err)
return value_or_err->getBoolValue();
+ llvm::consumeError(value_or_err.takeError());
}
if (HasFloatingRepresentation(val_type)) {
auto value_or_err = GetValueAsAPFloat();
if (value_or_err)
return value_or_err->isNonZero();
+ llvm::consumeError(value_or_err.takeError());
}
if (val_type.IsArrayType())
return GetAddressOf().address != 0;
@@ -1275,15 +1277,19 @@ void ValueObject::SetValueFromInteger(lldb::ValueObjectSP new_val_sp,
auto value_or_err = new_val_sp->GetValueAsAPSInt();
if (value_or_err)
SetValueFromInteger(*value_or_err, error, can_update_var);
- else
+ else {
+ llvm::consumeError(value_or_err.takeError());
error = Status::FromErrorString("error getting APSInt from new_val_sp");
+ }
} else if (HasFloatingRepresentation(new_val_type)) {
auto value_or_err = new_val_sp->GetValueAsAPFloat();
if (value_or_err)
SetValueFromInteger(value_or_err->bitcastToAPInt(), error,
can_update_var);
- else
+ else {
+ llvm::consumeError(value_or_err.takeError());
error = Status::FromErrorString("error getting APFloat from new_val_sp");
+ }
} else if (new_val_type.IsPointerType()) {
bool success = true;
uint64_t int_val = new_val_sp->GetValueAsUnsigned(0, &success);
diff --git a/lldb/source/ValueObject/ValueObjectMemory.cpp b/lldb/source/ValueObject/ValueObjectMemory.cpp
index 3d8d80c6ec480..590d8b10682ff 100644
--- a/lldb/source/ValueObject/ValueObjectMemory.cpp
+++ b/lldb/source/ValueObject/ValueObjectMemory.cpp
@@ -149,6 +149,8 @@ llvm::Expected<uint64_t> ValueObjectMemory::GetByteSize() {
if (auto size =
m_type_sp->GetByteSize(exe_ctx.GetBestExecutionContextScope()))
return *size;
+ else
+ llvm::consumeError(size.takeError());
return llvm::createStringError("could not get byte size of memory object");
}
return m_compiler_type.GetByteSize(exe_ctx.GetBestExecutionContextScope());
>From c499bf26f2a1168b18d12f1cb6342ab76e782272 Mon Sep 17 00:00:00 2001
From: Charles Zablit <c_zablit at apple.com>
Date: Thu, 23 Apr 2026 17:55:46 +0100
Subject: [PATCH 2/4] fixup! [lldb] fix unconsumed llvm::Expected's errors
---
lldb/source/API/SBProcess.cpp | 3 ++-
lldb/source/Host/posix/MainLoopPosix.cpp | 4 +++-
.../Plugins/Language/CPlusPlus/LibStdcpp.cpp | 5 +++-
.../Language/CPlusPlus/MsvcStlDeque.cpp | 5 +++-
.../Language/CPlusPlus/MsvcStlVector.cpp | 4 +++-
.../Process/minidump/ProcessMinidump.cpp | 4 +++-
.../Process/scripted/ScriptedThread.cpp | 7 +++---
.../NativePDB/PdbAstBuilderClang.cpp | 4 +++-
.../NativePDB/SymbolFileNativePDB.cpp | 9 ++++---
.../Debuginfod/SymbolLocatorDebuginfod.cpp | 3 ++-
lldb/source/Symbol/SymbolFileOnDemand.cpp | 3 ++-
lldb/source/Target/Statistics.cpp | 4 +++-
lldb/source/Target/Target.cpp | 3 ++-
lldb/source/ValueObject/DILEval.cpp | 7 ++++--
lldb/source/ValueObject/ValueObject.cpp | 24 +++++++------------
lldb/source/ValueObject/ValueObjectMemory.cpp | 4 +++-
16 files changed, 57 insertions(+), 36 deletions(-)
diff --git a/lldb/source/API/SBProcess.cpp b/lldb/source/API/SBProcess.cpp
index 5a2743eef668c..77d82581469fa 100644
--- a/lldb/source/API/SBProcess.cpp
+++ b/lldb/source/API/SBProcess.cpp
@@ -1042,7 +1042,8 @@ SBStructuredData SBProcess::GetExtendedCrashInformation() {
platform_sp->FetchExtendedCrashInformation(*process_sp.get());
if (!expected_data) {
- llvm::consumeError(expected_data.takeError());
+ LLDB_LOG_ERROR(GetLog(LLDBLog::API), expected_data.takeError(),
+ "FetchExtendedCrashInformation failed: {0}");
return data;
}
diff --git a/lldb/source/Host/posix/MainLoopPosix.cpp b/lldb/source/Host/posix/MainLoopPosix.cpp
index 927fb670417ab..b84411d3aa754 100644
--- a/lldb/source/Host/posix/MainLoopPosix.cpp
+++ b/lldb/source/Host/posix/MainLoopPosix.cpp
@@ -9,6 +9,7 @@
#include "lldb/Host/posix/MainLoopPosix.h"
#include "lldb/Host/Config.h"
#include "lldb/Host/PosixApi.h"
+#include "lldb/Utility/LLDBLog.h"
#include "lldb/Utility/Status.h"
#include "llvm/Config/llvm-config.h"
#include "llvm/Support/Errno.h"
@@ -394,7 +395,8 @@ bool MainLoopPosix::Interrupt() {
char c = '.';
llvm::Expected<size_t> result_or_err = m_interrupt_pipe.Write(&c, 1);
if (!result_or_err) {
- llvm::consumeError(result_or_err.takeError());
+ LLDB_LOG_ERROR(GetLog(LLDBLog::Host), result_or_err.takeError(),
+ "interrupt pipe write failed: {0}");
return false;
}
return *result_or_err != 0;
diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibStdcpp.cpp b/lldb/source/Plugins/Language/CPlusPlus/LibStdcpp.cpp
index a292aacc3cad1..c5e6d8cba45fd 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/LibStdcpp.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/LibStdcpp.cpp
@@ -19,6 +19,7 @@
#include "lldb/Target/Target.h"
#include "lldb/Utility/DataBufferHeap.h"
#include "lldb/Utility/Endian.h"
+#include "lldb/Utility/LLDBLog.h"
#include "lldb/Utility/Status.h"
#include "lldb/Utility/Stream.h"
#include "lldb/ValueObject/ValueObject.h"
@@ -472,7 +473,9 @@ bool formatters::LibStdcppVariantSummaryProvider(
auto index_bytes_or_err = index_obj->GetByteSize();
if (!index_bytes_or_err) {
- llvm::consumeError(index_bytes_or_err.takeError());
+ LLDB_LOG_ERROR(GetLog(LLDBLog::DataFormatters),
+ index_bytes_or_err.takeError(),
+ "failed to get variant index byte size: {0}");
return false;
}
auto npos_value = LibStdcppVariantNposValue(*index_bytes_or_err);
diff --git a/lldb/source/Plugins/Language/CPlusPlus/MsvcStlDeque.cpp b/lldb/source/Plugins/Language/CPlusPlus/MsvcStlDeque.cpp
index d7b70ebf7d6e9..7cfd90259fdea 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/MsvcStlDeque.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/MsvcStlDeque.cpp
@@ -10,6 +10,7 @@
#include "lldb/DataFormatters/FormattersHelpers.h"
#include "lldb/DataFormatters/TypeSynthetic.h"
+#include "lldb/Utility/LLDBLog.h"
#include "llvm/Support/ErrorExtras.h"
using namespace lldb;
@@ -143,7 +144,9 @@ lldb_private::formatters::MsvcStlDequeSyntheticFrontEnd::Update() {
}
auto element_size_or_err = element_type.GetByteSize(nullptr);
if (!element_size_or_err) {
- llvm::consumeError(element_size_or_err.takeError());
+ LLDB_LOG_ERROR(GetLog(LLDBLog::DataFormatters),
+ element_size_or_err.takeError(),
+ "failed to get deque element byte size: {0}");
return lldb::eRefetch;
}
diff --git a/lldb/source/Plugins/Language/CPlusPlus/MsvcStlVector.cpp b/lldb/source/Plugins/Language/CPlusPlus/MsvcStlVector.cpp
index 1a2e0691ee1cd..ef35dba27a207 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/MsvcStlVector.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/MsvcStlVector.cpp
@@ -250,7 +250,9 @@ lldb_private::formatters::MsvcStlVectorBoolSyntheticFrontEnd::Update() {
llvm::Expected<uint64_t> element_bit_size_or_err =
begin_ty.GetBitSize(nullptr);
if (!element_bit_size_or_err) {
- llvm::consumeError(element_bit_size_or_err.takeError());
+ LLDB_LOG_ERROR(GetLog(LLDBLog::DataFormatters),
+ element_bit_size_or_err.takeError(),
+ "failed to get vector<bool> element bit size: {0}");
return lldb::ChildCacheState::eRefetch;
}
diff --git a/lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp b/lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp
index 0a3f95cf5cee7..2f0bfa6f751ae 100644
--- a/lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp
+++ b/lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp
@@ -212,7 +212,9 @@ Status ProcessMinidump::DoLoadCore() {
// If we can't read an exception stream skip it
// We should probably serve a warning
if (!exception_stream_or_err) {
- llvm::consumeError(exception_stream_or_err.takeError());
+ LLDB_LOG_ERROR(GetLog(LLDBLog::Process),
+ exception_stream_or_err.takeError(),
+ "failed to read exception stream: {0}");
continue;
}
const llvm::minidump::ExceptionStream &exception_stream =
diff --git a/lldb/source/Plugins/Process/scripted/ScriptedThread.cpp b/lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
index 7539cc7eb3545..9d8213a78176f 100644
--- a/lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
+++ b/lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
@@ -258,11 +258,12 @@ bool ScriptedThread::LoadArtificialStackFrames() {
auto frame_from_script_obj_or_err = create_frame_from_script_object(idx);
if (!frame_from_script_obj_or_err) {
- llvm::consumeError(frame_from_script_obj_or_err.takeError());
return ScriptedInterface::ErrorWithMessage<bool>(
LLVM_PRETTY_FUNCTION,
- llvm::Twine("Couldn't add artificial frame (" + llvm::Twine(idx) +
- llvm::Twine(") to ScriptedThread StackFrameList."))
+ llvm::Twine(
+ "Couldn't add artificial frame (" + llvm::Twine(idx) +
+ llvm::Twine(") to ScriptedThread StackFrameList: ") +
+ llvm::toString(frame_from_script_obj_or_err.takeError()))
.str(),
error, LLDBLog::Thread);
} else {
diff --git a/lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilderClang.cpp b/lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilderClang.cpp
index 9d5ba762da757..e4ae61f4df3d5 100644
--- a/lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilderClang.cpp
+++ b/lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilderClang.cpp
@@ -24,6 +24,7 @@
#include "lldb/Core/Module.h"
#include "lldb/Symbol/ObjectFile.h"
#include "lldb/Utility/LLDBAssert.h"
+#include "lldb/Utility/LLDBLog.h"
#include <optional>
#include <string_view>
@@ -909,7 +910,8 @@ clang::FunctionDecl *PdbAstBuilderClang::CreateFunctionDecl(
if (eti) {
tag_record = CVTagRecord::create(index.tpi().getType(*eti)).asTag();
} else {
- llvm::consumeError(eti.takeError());
+ LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), eti.takeError(),
+ "failed to find full decl for forward ref: {0}");
}
}
diff --git a/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp b/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp
index 60d4a197554bb..ec6e89b10e776 100644
--- a/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp
+++ b/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp
@@ -1498,7 +1498,8 @@ bool SymbolFileNativePDB::ParseLineTable(CompileUnit &comp_unit) {
llvm::Expected<uint32_t> file_index_or_err =
GetFileIndex(*cii, group.NameIndex);
if (!file_index_or_err) {
- llvm::consumeError(file_index_or_err.takeError());
+ LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), file_index_or_err.takeError(),
+ "failed to get file index for line entry: {0}");
continue;
}
uint32_t file_index = file_index_or_err.get();
@@ -1704,7 +1705,8 @@ void SymbolFileNativePDB::ParseInlineSite(PdbCompilandSymId id,
llvm::Expected<uint32_t> file_index_or_err =
GetFileIndex(*cii, inlinee_line.Header->FileID);
if (!file_index_or_err) {
- llvm::consumeError(file_index_or_err.takeError());
+ LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), file_index_or_err.takeError(),
+ "failed to get file index for inline site: {0}");
return;
}
uint32_t file_offset = file_index_or_err.get();
@@ -1942,7 +1944,8 @@ void SymbolFileNativePDB::DumpClangAST(Stream &s, llvm::StringRef filter,
bool show_color) {
auto ts_or_err = GetTypeSystemForLanguage(eLanguageTypeC_plus_plus);
if (!ts_or_err) {
- llvm::consumeError(ts_or_err.takeError());
+ LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), ts_or_err.takeError(),
+ "failed to get C++ type system: {0}");
return;
}
auto ts = *ts_or_err;
diff --git a/lldb/source/Plugins/SymbolLocator/Debuginfod/SymbolLocatorDebuginfod.cpp b/lldb/source/Plugins/SymbolLocator/Debuginfod/SymbolLocatorDebuginfod.cpp
index 75ba7c91ebabc..bdd4875634d55 100644
--- a/lldb/source/Plugins/SymbolLocator/Debuginfod/SymbolLocatorDebuginfod.cpp
+++ b/lldb/source/Plugins/SymbolLocator/Debuginfod/SymbolLocatorDebuginfod.cpp
@@ -174,7 +174,8 @@ GetFileForModule(const ModuleSpec &module_spec,
llvm::Expected<std::string> cache_path_or_err = plugin_props.GetCachePath();
// A cache location is *required*.
if (!cache_path_or_err) {
- llvm::consumeError(cache_path_or_err.takeError());
+ LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), cache_path_or_err.takeError(),
+ "debuginfod cache path unavailable: {0}");
return {};
}
std::string cache_path = *cache_path_or_err;
diff --git a/lldb/source/Symbol/SymbolFileOnDemand.cpp b/lldb/source/Symbol/SymbolFileOnDemand.cpp
index fec1146bf4ad9..bc31536b3794e 100644
--- a/lldb/source/Symbol/SymbolFileOnDemand.cpp
+++ b/lldb/source/Symbol/SymbolFileOnDemand.cpp
@@ -519,7 +519,8 @@ SymbolFileOnDemand::GetParameterStackSize(const Symbol &symbol) {
LLDB_LOG(log, "{0} stack size would return for symbol {1} if hydrated.",
*stack_size, symbol.GetName());
else
- llvm::consumeError(stack_size.takeError());
+ LLDB_LOG_ERROR(log, stack_size.takeError(),
+ "failed to get parameter stack size: {0}");
}
return SymbolFile::GetParameterStackSize(symbol);
}
diff --git a/lldb/source/Target/Statistics.cpp b/lldb/source/Target/Statistics.cpp
index 01f61eca396ef..9c29f374ce5c9 100644
--- a/lldb/source/Target/Statistics.cpp
+++ b/lldb/source/Target/Statistics.cpp
@@ -17,6 +17,7 @@
#include "lldb/Target/Process.h"
#include "lldb/Target/Target.h"
#include "lldb/Target/UnixSignals.h"
+#include "lldb/Utility/LLDBLog.h"
#include "lldb/Utility/StructuredData.h"
using namespace lldb;
@@ -508,7 +509,8 @@ llvm::json::Value DebuggerStats::ReportStatistics(
global_stats.try_emplace("transcript",
std::move(json_transcript.get()));
else
- llvm::consumeError(json_transcript.takeError());
+ LLDB_LOG_ERROR(GetLog(LLDBLog::Target), json_transcript.takeError(),
+ "failed to parse transcript JSON: {0}");
}
}
diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp
index aaf4594802666..36515822fc7cb 100644
--- a/lldb/source/Target/Target.cpp
+++ b/lldb/source/Target/Target.cpp
@@ -4204,7 +4204,8 @@ Target::StopHookScripted::HandleStop(ExecutionContext &exc_ctx,
output_sp->PutCString(
reinterpret_cast<StreamString *>(stream.get())->GetData());
if (!should_stop_or_err) {
- llvm::consumeError(should_stop_or_err.takeError());
+ LLDB_LOG_ERROR(GetLog(LLDBLog::Target), should_stop_or_err.takeError(),
+ "scripted stop hook HandleStop failed: {0}");
return StopHookResult::KeepStopped;
}
diff --git a/lldb/source/ValueObject/DILEval.cpp b/lldb/source/ValueObject/DILEval.cpp
index a03c3b9ab0652..04d485d4c0943 100644
--- a/lldb/source/ValueObject/DILEval.cpp
+++ b/lldb/source/ValueObject/DILEval.cpp
@@ -12,6 +12,7 @@
#include "lldb/Symbol/TypeSystem.h"
#include "lldb/Symbol/VariableList.h"
#include "lldb/Target/RegisterContext.h"
+#include "lldb/Utility/LLDBLog.h"
#include "lldb/ValueObject/DILAST.h"
#include "lldb/ValueObject/DILParser.h"
#include "lldb/ValueObject/ValueObject.h"
@@ -1283,7 +1284,8 @@ Interpreter::VerifyArithmeticCast(CompilerType source_type,
} else {
std::string errMsg = llvm::formatv("unable to get byte size for type {0}",
target_type.TypeDescription());
- llvm::consumeError(temp.takeError());
+ LLDB_LOG_ERROR(GetLog(LLDBLog::Expressions), temp.takeError(),
+ "GetByteSize failed: {0}");
return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(errMsg), location,
target_type.TypeDescription().length());
@@ -1294,7 +1296,8 @@ Interpreter::VerifyArithmeticCast(CompilerType source_type,
} else {
std::string errMsg = llvm::formatv("unable to get byte size for type {0}",
source_type.TypeDescription());
- llvm::consumeError(temp.takeError());
+ LLDB_LOG_ERROR(GetLog(LLDBLog::Expressions), temp.takeError(),
+ "GetByteSize failed: {0}");
return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(errMsg), location,
source_type.TypeDescription().length());
diff --git a/lldb/source/ValueObject/ValueObject.cpp b/lldb/source/ValueObject/ValueObject.cpp
index 90910608127fa..521336b1c0ef1 100644
--- a/lldb/source/ValueObject/ValueObject.cpp
+++ b/lldb/source/ValueObject/ValueObject.cpp
@@ -1188,16 +1188,12 @@ llvm::Expected<bool> ValueObject::GetValueAsBool() {
CompilerType val_type = GetCompilerType();
if (val_type.IsInteger() || val_type.IsUnscopedEnumerationType() ||
val_type.IsPointerType()) {
- auto value_or_err = GetValueAsAPSInt();
- if (value_or_err)
- return value_or_err->getBoolValue();
- llvm::consumeError(value_or_err.takeError());
+ if (auto maybe_value = llvm::expectedToOptional(GetValueAsAPSInt()))
+ return maybe_value->getBoolValue();
}
if (HasFloatingRepresentation(val_type)) {
- auto value_or_err = GetValueAsAPFloat();
- if (value_or_err)
- return value_or_err->isNonZero();
- llvm::consumeError(value_or_err.takeError());
+ if (auto maybe_value = llvm::expectedToOptional(GetValueAsAPFloat()))
+ return maybe_value->isNonZero();
}
if (val_type.IsArrayType())
return GetAddressOf().address != 0;
@@ -1277,19 +1273,15 @@ void ValueObject::SetValueFromInteger(lldb::ValueObjectSP new_val_sp,
auto value_or_err = new_val_sp->GetValueAsAPSInt();
if (value_or_err)
SetValueFromInteger(*value_or_err, error, can_update_var);
- else {
- llvm::consumeError(value_or_err.takeError());
- error = Status::FromErrorString("error getting APSInt from new_val_sp");
- }
+ else
+ error = Status::FromError(value_or_err.takeError());
} else if (HasFloatingRepresentation(new_val_type)) {
auto value_or_err = new_val_sp->GetValueAsAPFloat();
if (value_or_err)
SetValueFromInteger(value_or_err->bitcastToAPInt(), error,
can_update_var);
- else {
- llvm::consumeError(value_or_err.takeError());
- error = Status::FromErrorString("error getting APFloat from new_val_sp");
- }
+ else
+ error = Status::FromError(value_or_err.takeError());
} else if (new_val_type.IsPointerType()) {
bool success = true;
uint64_t int_val = new_val_sp->GetValueAsUnsigned(0, &success);
diff --git a/lldb/source/ValueObject/ValueObjectMemory.cpp b/lldb/source/ValueObject/ValueObjectMemory.cpp
index 590d8b10682ff..6b160ff970868 100644
--- a/lldb/source/ValueObject/ValueObjectMemory.cpp
+++ b/lldb/source/ValueObject/ValueObjectMemory.cpp
@@ -12,6 +12,7 @@
#include "lldb/Target/ExecutionContext.h"
#include "lldb/Target/Target.h"
#include "lldb/Utility/DataExtractor.h"
+#include "lldb/Utility/LLDBLog.h"
#include "lldb/Utility/Scalar.h"
#include "lldb/Utility/Status.h"
#include "lldb/ValueObject/ValueObject.h"
@@ -150,7 +151,8 @@ llvm::Expected<uint64_t> ValueObjectMemory::GetByteSize() {
m_type_sp->GetByteSize(exe_ctx.GetBestExecutionContextScope()))
return *size;
else
- llvm::consumeError(size.takeError());
+ LLDB_LOG_ERROR(GetLog(LLDBLog::Types), size.takeError(),
+ "failed to get byte size from type: {0}");
return llvm::createStringError("could not get byte size of memory object");
}
return m_compiler_type.GetByteSize(exe_ctx.GetBestExecutionContextScope());
>From c9af5036977d7b739f66fe8121b301e24b1b89d0 Mon Sep 17 00:00:00 2001
From: Charles Zablit <c_zablit at apple.com>
Date: Tue, 28 Apr 2026 16:35:47 +0100
Subject: [PATCH 3/4] address comments
---
lldb/source/ValueObject/ValueObject.cpp | 16 ++++++++++++----
1 file changed, 12 insertions(+), 4 deletions(-)
diff --git a/lldb/source/ValueObject/ValueObject.cpp b/lldb/source/ValueObject/ValueObject.cpp
index 521336b1c0ef1..1db64e48cfc8c 100644
--- a/lldb/source/ValueObject/ValueObject.cpp
+++ b/lldb/source/ValueObject/ValueObject.cpp
@@ -1188,12 +1188,20 @@ llvm::Expected<bool> ValueObject::GetValueAsBool() {
CompilerType val_type = GetCompilerType();
if (val_type.IsInteger() || val_type.IsUnscopedEnumerationType() ||
val_type.IsPointerType()) {
- if (auto maybe_value = llvm::expectedToOptional(GetValueAsAPSInt()))
- return maybe_value->getBoolValue();
+ auto value_or_err = GetValueAsAPSInt();
+ if (value_or_err)
+ return value_or_err->getBoolValue();
+ else
+ LLDB_LOG_ERROR(GetLog(LLDBLog::Types), value_or_err.takeError(),
+ "GetValueAsAPSInt failed: {0}");
}
if (HasFloatingRepresentation(val_type)) {
- if (auto maybe_value = llvm::expectedToOptional(GetValueAsAPFloat()))
- return maybe_value->isNonZero();
+ auto value_or_err = GetValueAsAPFloat();
+ if (value_or_err)
+ return value_or_err->isNonZero();
+ else
+ LLDB_LOG_ERROR(GetLog(LLDBLog::Types), value_or_err.takeError(),
+ "GetValueAsAPFloat failed: {0}");
}
if (val_type.IsArrayType())
return GetAddressOf().address != 0;
>From c516351e0cf07c88ee1440af00e5dfee24156d43 Mon Sep 17 00:00:00 2001
From: Charles Zablit <c_zablit at apple.com>
Date: Fri, 1 May 2026 13:06:39 +0200
Subject: [PATCH 4/4] fixup Twine build
---
lldb/source/Plugins/Process/scripted/ScriptedThread.cpp | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/lldb/source/Plugins/Process/scripted/ScriptedThread.cpp b/lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
index 9d8213a78176f..3cf37d9547e2b 100644
--- a/lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
+++ b/lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
@@ -169,8 +169,7 @@ bool ScriptedThread::LoadArtificialStackFrames() {
LLVM_PRETTY_FUNCTION,
llvm::Twine(
"StackFrame array size (" + llvm::Twine(arr_size) +
- llvm::Twine(
- ") is greater than maximum authorized for a StackFrameList."))
+ ") is greater than maximum authorized for a StackFrameList.")
.str(),
error, LLDBLog::Thread);
More information about the lldb-commits
mailing list