[Lldb-commits] [lldb] [lldb][windows] fix unchecked Expected (PR #178681)
Charles Zablit via lldb-commits
lldb-commits at lists.llvm.org
Thu Jan 29 07:33:37 PST 2026
https://github.com/charles-zablit created https://github.com/llvm/llvm-project/pull/178681
This patch fixes unchecked `Expected<T>` returns from the `CompilerType::GetByteSize` method.
>From 095e0da54146f91e0877e3be8b86e9df7a6c0ab5 Mon Sep 17 00:00:00 2001
From: Charles Zablit <c_zablit at apple.com>
Date: Thu, 29 Jan 2026 15:26:04 +0000
Subject: [PATCH] [lldb][windows] fix unchecked Expected
---
.../include/lldb/Target/ProcessStructReader.h | 28 +++++++++++++------
.../TypeSystem/Clang/TypeSystemClang.cpp | 14 ++++++----
lldb/source/ValueObject/ValueObject.cpp | 4 +--
3 files changed, 31 insertions(+), 15 deletions(-)
diff --git a/lldb/include/lldb/Target/ProcessStructReader.h b/lldb/include/lldb/Target/ProcessStructReader.h
index 0f0b3f69d5509..df3203698afd0 100644
--- a/lldb/include/lldb/Target/ProcessStructReader.h
+++ b/lldb/include/lldb/Target/ProcessStructReader.h
@@ -16,6 +16,7 @@
#include "lldb/Target/Process.h"
#include "lldb/Utility/DataBufferHeap.h"
#include "lldb/Utility/DataExtractor.h"
+#include "lldb/Utility/LLDBLog.h"
#include "lldb/Utility/Status.h"
#include "llvm/ADT/StringMap.h"
@@ -59,21 +60,32 @@ class ProcessStructReader {
// no support for bitfields in here (yet)
if (is_bitfield)
return;
- auto size = field_type.GetByteSize(nullptr);
+ auto size_or_err = field_type.GetByteSize(nullptr);
+ if (!size_or_err) {
+ LLDB_LOG_ERROR(GetLog(LLDBLog::Target), size_or_err.takeError(), "{0}");
+ return;
+ }
+ size_t size = *size_or_err;
+
// no support for things larger than a uint64_t (yet)
- if (!size || *size > 8)
+ if (size > 8)
return;
size_t byte_index = static_cast<size_t>(bit_offset / 8);
- m_fields.insert({name, FieldImpl{field_type, byte_index,
- static_cast<size_t>(*size)}});
+ m_fields.insert(
+ {name, FieldImpl{field_type, byte_index, static_cast<size_t>(size)}});
}
- auto total_size = struct_type.GetByteSize(nullptr);
- if (!total_size)
+ auto total_size_or_err = struct_type.GetByteSize(nullptr);
+ if (!total_size_or_err) {
+ LLDB_LOG_ERROR(GetLog(LLDBLog::Target), total_size_or_err.takeError(),
+ "{0}");
return;
- lldb::WritableDataBufferSP buffer_sp(new DataBufferHeap(*total_size, 0));
+ }
+ size_t total_size = *total_size_or_err;
+
+ lldb::WritableDataBufferSP buffer_sp(new DataBufferHeap(total_size, 0));
Status error;
process->ReadMemoryFromInferior(base_addr, buffer_sp->GetBytes(),
- *total_size, error);
+ total_size, error);
if (error.Fail())
return;
m_data = DataExtractor(buffer_sp, m_byte_order, m_addr_byte_size);
diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
index 34d97a07d73fc..478f10a60a865 100644
--- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
+++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
@@ -885,11 +885,15 @@ lldb::BasicType TypeSystemClang::GetBasicTypeEnumeration(llvm::StringRef name) {
}
uint32_t TypeSystemClang::GetPointerByteSize() {
- if (m_pointer_byte_size == 0)
- if (auto size = GetBasicType(lldb::eBasicTypeVoid)
- .GetPointerType()
- .GetByteSize(nullptr))
- m_pointer_byte_size = *size;
+ if (m_pointer_byte_size != 0)
+ return m_pointer_byte_size;
+ auto size_or_err =
+ GetBasicType(lldb::eBasicTypeVoid).GetPointerType().GetByteSize(nullptr);
+ if (!size_or_err) {
+ LLDB_LOG_ERROR(GetLog(LLDBLog::Types), size_or_err.takeError(), "{0}");
+ return m_pointer_byte_size;
+ }
+ m_pointer_byte_size = *size_or_err;
return m_pointer_byte_size;
}
diff --git a/lldb/source/ValueObject/ValueObject.cpp b/lldb/source/ValueObject/ValueObject.cpp
index 121054e3e92ed..9c453e06b1c31 100644
--- a/lldb/source/ValueObject/ValueObject.cpp
+++ b/lldb/source/ValueObject/ValueObject.cpp
@@ -744,8 +744,8 @@ size_t ValueObject::GetPointeeData(DataExtractor &data, uint32_t item_idx,
}
} break;
case eAddressTypeHost: {
- auto max_bytes =
- GetCompilerType().GetByteSize(exe_ctx.GetBestExecutionContextScope());
+ auto max_bytes = llvm::expectedToOptional(GetCompilerType().GetByteSize(
+ exe_ctx.GetBestExecutionContextScope()));
if (max_bytes && *max_bytes > offset) {
size_t bytes_read = std::min<uint64_t>(*max_bytes - offset, bytes);
addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
More information about the lldb-commits
mailing list