From fdbe7c7faa547b16bf6da0fedbb7234b6ee3adef Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere Date: Mon, 1 May 2023 20:34:51 -0700 Subject: [lldb] Refactor OptionValue to return a std::optional (NFC) Refactor OptionValue to return a std::optional instead of taking a fail value. This allows the caller to handle situations where there's no value, instead of being unable to distinguish between the absence of a value and the value happening the match the fail value. When a fail value is required, std::optional::value_or() provides the same functionality. --- lldb/source/Commands/CommandObjectMemory.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'lldb/source/Commands/CommandObjectMemory.cpp') diff --git a/lldb/source/Commands/CommandObjectMemory.cpp b/lldb/source/Commands/CommandObjectMemory.cpp index 70dd6ea..9034243 100644 --- a/lldb/source/Commands/CommandObjectMemory.cpp +++ b/lldb/source/Commands/CommandObjectMemory.cpp @@ -1047,18 +1047,20 @@ protected: DataBufferHeap buffer; if (m_memory_options.m_string.OptionWasSet()) { - llvm::StringRef str = m_memory_options.m_string.GetStringValue(); - if (str.empty()) { + std::optional str = + m_memory_options.m_string.GetStringValue(); + if (!str) { result.AppendError("search string must have non-zero length."); return false; } - buffer.CopyData(str); + buffer.CopyData(*str); } else if (m_memory_options.m_expr.OptionWasSet()) { StackFrame *frame = m_exe_ctx.GetFramePtr(); ValueObjectSP result_sp; if ((eExpressionCompleted == process->GetTarget().EvaluateExpression( - m_memory_options.m_expr.GetStringValue(), frame, result_sp)) && + m_memory_options.m_expr.GetStringValue().value_or(""), frame, + result_sp)) && result_sp) { uint64_t value = result_sp->GetValueAsUnsigned(0); std::optional size = -- cgit v1.1