- Notifications
You must be signed in to change notification settings - Fork 14.9k
draft: [lldb] Upgrade ValueObject::GetData to return llvm::Expected #130516
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
draft: [lldb] Upgrade ValueObject::GetData to return llvm::Expected #130516
Conversation
|
This isn't finish of course, I'm not to sure on the changes so far and wanted to know if I was going toward the right path in terms what's being change. Before making any more big changes to the code, this presumably might be a big change, considering how many places the |
You can test this locally with the following command:git-clang-format --diff a7d5b3f711b7c852aa1337e329661dd36025865a 02ecd560188ba3eba7148f96ea2d478c2bc8481a --extensions h,cpp -- lldb/include/lldb/ValueObject/ValueObject.h lldb/source/API/SBValue.cpp lldb/source/Breakpoint/Watchpoint.cpp lldb/source/DataFormatters/TypeFormat.cpp lldb/source/Expression/Materializer.cpp lldb/source/Plugins/ABI/AArch64/ABIMacOSX_arm64.cpp lldb/source/Plugins/ABI/AArch64/ABISysV_arm64.cpp lldb/source/Plugins/ABI/ARC/ABISysV_arc.cpp lldb/source/Plugins/ABI/ARM/ABIMacOSX_arm.cpp lldb/source/Plugins/ABI/ARM/ABISysV_arm.cpp lldb/source/Plugins/ABI/LoongArch/ABISysV_loongarch.cpp lldb/source/Plugins/ABI/Mips/ABISysV_mips.cpp lldb/source/Plugins/ABI/Mips/ABISysV_mips64.cpp lldb/source/Plugins/ABI/PowerPC/ABISysV_ppc.cpp lldb/source/Plugins/ABI/PowerPC/ABISysV_ppc64.cpp lldb/source/Plugins/ABI/RISCV/ABISysV_riscv.cpp lldb/source/Plugins/ABI/SystemZ/ABISysV_s390x.cpp lldb/source/Plugins/ABI/X86/ABIMacOSX_i386.cpp lldb/source/Plugins/ABI/X86/ABISysV_i386.cpp lldb/source/Plugins/ABI/X86/ABISysV_x86_64.cpp lldb/source/Plugins/ABI/X86/ABIWindows_x86_64.cpp lldb/source/Plugins/Language/CPlusPlus/CxxStringTypes.cpp lldb/source/Plugins/Language/CPlusPlus/LibCxxList.cpp lldb/source/Plugins/Language/CPlusPlus/LibCxxUnorderedMap.cpp lldb/source/Plugins/Language/ObjC/Cocoa.cpp lldb/source/Plugins/Language/ObjC/NSString.cpp lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp lldb/source/ValueObject/ValueObject.cpp lldb/unittests/ValueObject/DumpValueObjectOptionsTests.cpp View the diff from clang-format here.diff --git a/lldb/source/Breakpoint/Watchpoint.cpp b/lldb/source/Breakpoint/Watchpoint.cpp index a23c6ccab3..1cb5575d63 100644 --- a/lldb/source/Breakpoint/Watchpoint.cpp +++ b/lldb/source/Breakpoint/Watchpoint.cpp @@ -235,7 +235,7 @@ bool Watchpoint::WatchedValueReportable(const ExecutionContext &exe_ctx) { if (!new_data_or_err) { LLDB_LOG_ERRORV(GetLog(LLDBLog::Watchpoints), new_data_or_err.takeError(), - "Failed to extract watchpoint new data: {0}"); + "Failed to extract watchpoint new data: {0}"); return true; } @@ -244,7 +244,7 @@ bool Watchpoint::WatchedValueReportable(const ExecutionContext &exe_ctx) { if (!old_data_or_err) { LLDB_LOG_ERRORV(GetLog(LLDBLog::Watchpoints), old_data_or_err.takeError(), - "Failed to extract watchpoint old data: {0}"); + "Failed to extract watchpoint old data: {0}"); return true; } diff --git a/lldb/source/Expression/Materializer.cpp b/lldb/source/Expression/Materializer.cpp index 31babfebb7..db7f53a53f 100644 --- a/lldb/source/Expression/Materializer.cpp +++ b/lldb/source/Expression/Materializer.cpp @@ -579,8 +579,8 @@ public: m_temporary_allocation_size = data.GetByteSize(); - m_original_data = std::make_shared<DataBufferHeap>( - data.GetDataStart(), data.GetByteSize()); + m_original_data = std::make_shared<DataBufferHeap>(data.GetDataStart(), + data.GetByteSize()); if (!alloc_error.Success()) { err = Status::FromErrorStringWithFormat( diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxxList.cpp b/lldb/source/Plugins/Language/CPlusPlus/LibCxxList.cpp index c6a3b40afb..988b825f94 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) return nullptr; - return CreateValueObjectFromData( - llvm::formatv("[{0}]", idx).str(), *data, - m_backend.GetExecutionContextRef(), m_element_type); + return CreateValueObjectFromData(llvm::formatv("[{0}]", idx).str(), *data, + 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 376a290544..70ce306782 100644 --- a/lldb/source/Plugins/Language/ObjC/Cocoa.cpp +++ b/lldb/source/Plugins/Language/ObjC/Cocoa.cpp @@ -1209,8 +1209,8 @@ bool lldb_private::formatters::ObjCSELSummaryProvider( if (!data) return false; - valobj_sp = ValueObject::CreateValueObjectFromData("text", *data, - exe_ctx, charstar); + valobj_sp = ValueObject::CreateValueObjectFromData("text", *data, exe_ctx, + charstar); } if (!valobj_sp) diff --git a/lldb/unittests/ValueObject/DumpValueObjectOptionsTests.cpp b/lldb/unittests/ValueObject/DumpValueObjectOptionsTests.cpp index c725b6d882..519ed175a2 100644 --- a/lldb/unittests/ValueObject/DumpValueObjectOptionsTests.cpp +++ b/lldb/unittests/ValueObject/DumpValueObjectOptionsTests.cpp @@ -88,7 +88,7 @@ public: 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(); } |
ExecutionContext exe_ctx(valobj->GetExecutionContextRef()); | ||
DataExtractor data; | ||
| ||
auto data_or_err = valobj->GetData(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a practical approach?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it seems to be fine. I don't think there should be any side-effects from this refactor.
I added another wave of refactors, I'll add more changes, once this current wave(commit) is approved. And I'll continue to incrementally add changes to make it easier to manage. |
"couldn't read contents of reference variable %s: %s", | ||
GetName().AsCString(), extract_error.AsCString()); | ||
GetName().AsCString(), llvm::toString(std::move(error)).c_str()); | ||
return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't we just do this from now on?
return; | |
return Status::FromErrorStringWithFormat( | |
"couldn't read contents of reference variable %s: %s", | |
GetName().AsCString(), llvm::toString(std::move(error)).c_str()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Eventually, yes. You just have to draw the line somewhere for each commit.
Hey @adrian-prantl, if you can and when you have time. I was wondering if it'd be okay if you can review this and just so i can make sure it aligns with the standards for this PR, before submitting the final results. I was also curious to know if I'd have to change any test code too, I've tried to unit test but got error relating to "expected" values. Would I need to change something in Error output for `ninja check-lldb-unit`
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like a great start! I made a couple of suggestions inline.
Usually wrapping calls in |
This is taking longer than expected, I'm encountering a lot of linker bugs unrelated the patches I've made. Even after create a fresh clone of llvm without the patches. I'm still encountering issues. One them being #132845 (comment) |
how would i go about doing that? |
DataExtractor data_extractor{&value, sizeof(value), endian, 4}; | ||
auto valobj_sp = ValueObjectConstResult::Create(exe_scope, enum_type, | ||
var_name, data_extractor); | ||
if (llvm::Error error = valobj_sp->Dump(strm, options)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @adrian-prantl,
I didn't make any changes to the unit tests yet. I was a bit confuse on how I'd go about writing a wrapper for this test to imitates the old API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The old function signature was
uint64_t GetData(DataExtractor &data, Status &error);
the new one is
llvm::Expected<DataExtractor> GetData();
so you can do something like
uint64_t GetDataWithStatus(DataExtractor &data, ValueObject &valobj, Status &error) { auto data_extractor_or_err = valobj.GetData(); if (data_extractor_or_err) { data = *data_extractor_or_err; return data.GetSize(); } error = Status::FromError(data_extractor_or_err.takeError()); return 0; }
auto data_or_err = new_value_sp->GetData(); | ||
if (auto err = data_or_err.takeError()) | ||
return Status::FromError(llvm::joinErrors( | ||
llvm::createStringError("Couldn't convert return value to raw data"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it should be this instead?
llvm::createStringError("Couldn't convert return value to raw data"), | |
llvm::createStringError("Couldn't convert return value to raw data: "), |
Original mentioned here: Discourse
This patch consist of changing GetData method in the ValueObject to return a llvm::Expected in order to have more meaningful error messages.
cc: @adrian-prantl