[Lldb-commits] [lldb] draft: [lldb] Upgrade ValueObject::GetData to return llvm::Expected (PR #130516)
Adrian Prantl via lldb-commits
lldb-commits at lists.llvm.org
Mon Mar 10 08:59:46 PDT 2025
================
@@ -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)
----------------
adrian-prantl wrote:
The important difference between llvm::Error is that it asserts if you don't check the error inside. So you need to explicitly throw away the error here.
In situations where the error really doesn't matter, you can wrap it in `llvm::expectedToOptional()` which will discard the error and return a `std::optional`. In other cases, logging the error is appropriate, for example: `LLDB_LOG_ERRORV(GetLog(LLDBLog::Formatters), data_or_err.takerError(), "Cannot extract data: {0}")`.
And then some functions returns an llvm::Error or a Status, in which case you can just pass the error up.
I think this function would be a candidate for logging.
https://github.com/llvm/llvm-project/pull/130516
More information about the lldb-commits
mailing list