[Lldb-commits] [lldb] [lldb] Change the implementation of Status to store an llvm::Error (NFC) (PR #106774)
Pavel Labath via lldb-commits
lldb-commits at lists.llvm.org
Wed Sep 11 01:58:21 PDT 2024
================
@@ -181,29 +241,61 @@ const char *Status::AsCString(const char *default_error_str) const {
// Clear the error and any cached error string that it might contain.
void Status::Clear() {
- m_code = 0;
- m_type = eErrorTypeInvalid;
- m_string.clear();
+ if (m_error)
+ LLDB_LOG_ERRORV(GetLog(LLDBLog::API), std::move(m_error),
+ "dropping error {0}");
+ m_error = llvm::Error::success();
+ llvm::consumeError(std::move(m_error));
}
// Access the error value.
-Status::ValueType Status::GetError() const { return m_code; }
+Status::ValueType Status::GetError() const {
+ Status::ValueType result = 0;
+ llvm::visitErrors(m_error, [&](const llvm::ErrorInfoBase &error) {
+ std::error_code ec = error.convertToErrorCode();
+ if (ec.category() == std::generic_category() ||
+ ec.category() == generic_category() ||
+ ec.category() == expression_category())
+ result = ec.value();
+ else
+ result = 0xff;
+ });
+ return result;
+}
// Access the error type.
-ErrorType Status::GetType() const { return m_type; }
+ErrorType Status::GetType() const {
+ ErrorType result = eErrorTypeInvalid;
+ llvm::visitErrors(m_error, [&](const llvm::ErrorInfoBase &error) {
+ if (error.isA<MachKernelError>())
+ result = eErrorTypeMachKernel;
+ else if (error.isA<Win32Error>())
+ result = eErrorTypeWin32;
+ else if (error.isA<ExpressionError>())
+ result = eErrorTypeExpression;
+ else if (error.convertToErrorCode().category() == std::generic_category())
+ result = eErrorTypePOSIX;
+ else if (error.convertToErrorCode().category() == generic_category() ||
----------------
labath wrote:
Ah, I now see that this does not repeat the condition because `generic_category() != std::generic_category()`. What would you say to renaming this to `lldb_generic_category()` so that it's harder to confuse the two?
https://github.com/llvm/llvm-project/pull/106774
More information about the lldb-commits
mailing list