diff options
author | Adrian Prantl <aprantl@apple.com> | 2025-03-05 10:21:19 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-03-05 10:21:19 -0800 |
commit | 878a64f94a264ea4b564d6063614ddb0b5da3f6c (patch) | |
tree | 5aaa6c770d5764fd3f9822882376c85c7ed427ef /lldb/source/Commands/CommandObjectMemory.cpp | |
parent | 03da079968845e1f1312d09ff4e2ecee1933552e (diff) | |
download | llvm-878a64f94a264ea4b564d6063614ddb0b5da3f6c.zip llvm-878a64f94a264ea4b564d6063614ddb0b5da3f6c.tar.gz llvm-878a64f94a264ea4b564d6063614ddb0b5da3f6c.tar.bz2 |
[lldb] Upgrade CompilerType::GetBitSize to return llvm::Expected (#129601)
This patch pushes the error handling boundary for the GetBitSize()
methods from Runtime into the Type and CompilerType APIs. This makes it
easier to diagnose problems thanks to more meaningful error messages
being available. GetBitSize() is often the first thing LLDB asks about a
type, so this method is particularly important for a better user
experience.
rdar://145667239
Diffstat (limited to 'lldb/source/Commands/CommandObjectMemory.cpp')
-rw-r--r-- | lldb/source/Commands/CommandObjectMemory.cpp | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/lldb/source/Commands/CommandObjectMemory.cpp b/lldb/source/Commands/CommandObjectMemory.cpp index f2fa539..7140333 100644 --- a/lldb/source/Commands/CommandObjectMemory.cpp +++ b/lldb/source/Commands/CommandObjectMemory.cpp @@ -519,14 +519,14 @@ protected: --pointer_count; } - std::optional<uint64_t> size = compiler_type.GetByteSize(nullptr); - if (!size) { + auto size_or_err = compiler_type.GetByteSize(nullptr); + if (!size_or_err) { result.AppendErrorWithFormat( - "unable to get the byte size of the type '%s'\n", - view_as_type_cstr); + "unable to get the byte size of the type '%s'\n%s", + view_as_type_cstr, llvm::toString(size_or_err.takeError()).c_str()); return; } - m_format_options.GetByteSizeValue() = *size; + m_format_options.GetByteSizeValue() = *size_or_err; if (!m_format_options.GetCountValue().OptionWasSet()) m_format_options.GetCountValue() = 1; @@ -639,15 +639,16 @@ protected: if (!m_format_options.GetFormatValue().OptionWasSet()) m_format_options.GetFormatValue().SetCurrentValue(eFormatDefault); - std::optional<uint64_t> size = compiler_type.GetByteSize(nullptr); - if (!size) { - result.AppendError("can't get size of type"); + auto size_or_err = compiler_type.GetByteSize(nullptr); + if (!size_or_err) { + result.AppendError(llvm::toString(size_or_err.takeError())); return; } - bytes_read = *size * m_format_options.GetCountValue().GetCurrentValue(); + auto size = *size_or_err; + bytes_read = size * m_format_options.GetCountValue().GetCurrentValue(); if (argc > 0) - addr = addr + (*size * m_memory_options.m_offset.GetCurrentValue()); + addr = addr + (size * m_memory_options.m_offset.GetCurrentValue()); } else if (m_format_options.GetFormatValue().GetCurrentValue() != eFormatCString) { data_sp = std::make_shared<DataBufferHeap>(total_byte_size, '\0'); @@ -1034,8 +1035,8 @@ protected: frame, result_sp)) && result_sp) { uint64_t value = result_sp->GetValueAsUnsigned(0); - std::optional<uint64_t> size = - result_sp->GetCompilerType().GetByteSize(nullptr); + std::optional<uint64_t> size = llvm::expectedToOptional( + result_sp->GetCompilerType().GetByteSize(nullptr)); if (!size) return; switch (*size) { |