Raphael Isemann | 8081428 | 2020-01-24 08:23:27 +0100 | [diff] [blame] | 1 | //===-- Status.cpp --------------------------------------------------------===// |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 9 | #include "lldb/Utility/Status.h" |
Zachary Turner | 4479ac1 | 2017-04-06 18:12:24 +0000 | [diff] [blame] | 10 | |
| 11 | #include "lldb/Utility/VASPrintf.h" |
Jonas Devlieghere | 672d2c1 | 2018-11-11 23:16:43 +0000 | [diff] [blame] | 12 | #include "lldb/lldb-defines.h" |
| 13 | #include "lldb/lldb-enumerations.h" |
| 14 | #include "llvm/ADT/SmallString.h" |
| 15 | #include "llvm/ADT/StringRef.h" |
Pavel Labath | 10c41f3 | 2017-06-06 14:06:17 +0000 | [diff] [blame] | 16 | #include "llvm/Support/Errno.h" |
Jonas Devlieghere | 672d2c1 | 2018-11-11 23:16:43 +0000 | [diff] [blame] | 17 | #include "llvm/Support/FormatProviders.h" |
Zachary Turner | 4479ac1 | 2017-04-06 18:12:24 +0000 | [diff] [blame] | 18 | |
| 19 | #include <cerrno> |
| 20 | #include <cstdarg> |
Jonas Devlieghere | 672d2c1 | 2018-11-11 23:16:43 +0000 | [diff] [blame] | 21 | #include <string> |
Zachary Turner | 4479ac1 | 2017-04-06 18:12:24 +0000 | [diff] [blame] | 22 | #include <system_error> |
| 23 | |
Charles Davis | 322fc84 | 2013-08-27 06:13:56 +0000 | [diff] [blame] | 24 | #ifdef __APPLE__ |
Charles Davis | 510938e | 2013-08-27 05:04:57 +0000 | [diff] [blame] | 25 | #include <mach/mach.h> |
Charles Davis | 322fc84 | 2013-08-27 06:13:56 +0000 | [diff] [blame] | 26 | #endif |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 27 | |
Aaron Smith | c3d447f | 2018-10-19 18:58:24 +0000 | [diff] [blame] | 28 | #ifdef _WIN32 |
| 29 | #include <windows.h> |
| 30 | #endif |
Jonas Devlieghere | 672d2c1 | 2018-11-11 23:16:43 +0000 | [diff] [blame] | 31 | #include <stdint.h> |
Eugene Zelenko | a74f37a | 2016-03-10 23:57:12 +0000 | [diff] [blame] | 32 | |
Zachary Turner | 4479ac1 | 2017-04-06 18:12:24 +0000 | [diff] [blame] | 33 | namespace llvm { |
| 34 | class raw_ostream; |
| 35 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 36 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 37 | using namespace lldb; |
| 38 | using namespace lldb_private; |
| 39 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 40 | Status::Status() : m_code(0), m_type(eErrorTypeInvalid), m_string() {} |
Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 41 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 42 | Status::Status(ValueType err, ErrorType type) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 43 | : m_code(err), m_type(type), m_string() {} |
Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 44 | |
Pavel Labath | f512b97 | 2020-04-23 15:55:39 +0200 | [diff] [blame] | 45 | // This logic is confusing because c++ calls the traditional (posix) errno codes |
| 46 | // "generic errors", while we use the term "generic" to mean completely |
| 47 | // arbitrary (text-based) errors. |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 48 | Status::Status(std::error_code EC) |
Pavel Labath | f512b97 | 2020-04-23 15:55:39 +0200 | [diff] [blame] | 49 | : m_code(EC.value()), |
| 50 | m_type(EC.category() == std::generic_category() ? eErrorTypePOSIX |
| 51 | : eErrorTypeGeneric), |
Zachary Turner | 7d86ee5 | 2017-03-08 17:56:08 +0000 | [diff] [blame] | 52 | m_string(EC.message()) {} |
| 53 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 54 | Status::Status(const char *format, ...) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 55 | : m_code(0), m_type(eErrorTypeInvalid), m_string() { |
| 56 | va_list args; |
| 57 | va_start(args, format); |
| 58 | SetErrorToGenericError(); |
| 59 | SetErrorStringWithVarArg(format, args); |
| 60 | va_end(args); |
Enrico Granata | f2bbf71 | 2011-07-15 02:26:42 +0000 | [diff] [blame] | 61 | } |
| 62 | |
Pavel Labath | 3adc408 | 2017-06-15 11:23:26 +0000 | [diff] [blame] | 63 | const Status &Status::operator=(llvm::Error error) { |
| 64 | if (!error) { |
| 65 | Clear(); |
| 66 | return *this; |
| 67 | } |
Pavel Labath | a24a3a3 | 2017-05-18 12:46:50 +0000 | [diff] [blame] | 68 | |
| 69 | // if the error happens to be a errno error, preserve the error code |
| 70 | error = llvm::handleErrors( |
| 71 | std::move(error), [&](std::unique_ptr<llvm::ECError> e) -> llvm::Error { |
| 72 | std::error_code ec = e->convertToErrorCode(); |
| 73 | if (ec.category() == std::generic_category()) { |
| 74 | m_code = ec.value(); |
| 75 | m_type = ErrorType::eErrorTypePOSIX; |
| 76 | return llvm::Error::success(); |
| 77 | } |
| 78 | return llvm::Error(std::move(e)); |
| 79 | }); |
| 80 | |
| 81 | // Otherwise, just preserve the message |
Pavel Labath | 3adc408 | 2017-06-15 11:23:26 +0000 | [diff] [blame] | 82 | if (error) { |
| 83 | SetErrorToGenericError(); |
Pavel Labath | a24a3a3 | 2017-05-18 12:46:50 +0000 | [diff] [blame] | 84 | SetErrorString(llvm::toString(std::move(error))); |
Pavel Labath | 3adc408 | 2017-06-15 11:23:26 +0000 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | return *this; |
Pavel Labath | a24a3a3 | 2017-05-18 12:46:50 +0000 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | llvm::Error Status::ToError() const { |
| 91 | if (Success()) |
| 92 | return llvm::Error::success(); |
| 93 | if (m_type == ErrorType::eErrorTypePOSIX) |
Aaron Smith | c3d447f | 2018-10-19 18:58:24 +0000 | [diff] [blame] | 94 | return llvm::errorCodeToError( |
| 95 | std::error_code(m_code, std::generic_category())); |
Pavel Labath | a24a3a3 | 2017-05-18 12:46:50 +0000 | [diff] [blame] | 96 | return llvm::make_error<llvm::StringError>(AsCString(), |
| 97 | llvm::inconvertibleErrorCode()); |
| 98 | } |
| 99 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 100 | Status::~Status() = default; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 101 | |
Aaron Smith | c3d447f | 2018-10-19 18:58:24 +0000 | [diff] [blame] | 102 | #ifdef _WIN32 |
| 103 | static std::string RetrieveWin32ErrorString(uint32_t error_code) { |
| 104 | char *buffer = nullptr; |
| 105 | std::string message; |
| 106 | // Retrieve win32 system error. |
Alexandre Ganea | bdad3ec | 2019-11-28 14:15:13 -0500 | [diff] [blame] | 107 | // First, attempt to load a en-US message |
Aaron Smith | c3d447f | 2018-10-19 18:58:24 +0000 | [diff] [blame] | 108 | if (::FormatMessageA( |
| 109 | FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | |
| 110 | FORMAT_MESSAGE_MAX_WIDTH_MASK, |
Alexandre Ganea | bdad3ec | 2019-11-28 14:15:13 -0500 | [diff] [blame] | 111 | NULL, error_code, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), |
Aaron Smith | c3d447f | 2018-10-19 18:58:24 +0000 | [diff] [blame] | 112 | (LPSTR)&buffer, 0, NULL)) { |
| 113 | message.assign(buffer); |
| 114 | ::LocalFree(buffer); |
| 115 | } |
Alexandre Ganea | bdad3ec | 2019-11-28 14:15:13 -0500 | [diff] [blame] | 116 | // If the previous didn't work, use the default OS language |
| 117 | else if (::FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | |
| 118 | FORMAT_MESSAGE_FROM_SYSTEM | |
| 119 | FORMAT_MESSAGE_MAX_WIDTH_MASK, |
| 120 | NULL, error_code, 0, (LPSTR)&buffer, 0, NULL)) { |
| 121 | message.assign(buffer); |
| 122 | ::LocalFree(buffer); |
| 123 | } |
Aaron Smith | c3d447f | 2018-10-19 18:58:24 +0000 | [diff] [blame] | 124 | return message; |
| 125 | } |
| 126 | #endif |
| 127 | |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 128 | // Get the error value as a NULL C string. The error string will be fetched and |
| 129 | // cached on demand. The cached error string value will remain until the error |
| 130 | // value is changed or cleared. |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 131 | const char *Status::AsCString(const char *default_error_str) const { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 132 | if (Success()) |
| 133 | return nullptr; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 134 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 135 | if (m_string.empty()) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 136 | switch (m_type) { |
| 137 | case eErrorTypeMachKernel: |
| 138 | #if defined(__APPLE__) |
Pavel Labath | 10c41f3 | 2017-06-06 14:06:17 +0000 | [diff] [blame] | 139 | if (const char *s = ::mach_error_string(m_code)) |
| 140 | m_string.assign(s); |
Eli Friedman | 6eb685c | 2010-06-10 23:45:58 +0000 | [diff] [blame] | 141 | #endif |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 142 | break; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 143 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 144 | case eErrorTypePOSIX: |
Pavel Labath | 10c41f3 | 2017-06-06 14:06:17 +0000 | [diff] [blame] | 145 | m_string = llvm::sys::StrError(m_code); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 146 | break; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 147 | |
Aaron Smith | c3d447f | 2018-10-19 18:58:24 +0000 | [diff] [blame] | 148 | case eErrorTypeWin32: |
| 149 | #if defined(_WIN32) |
| 150 | m_string = RetrieveWin32ErrorString(m_code); |
| 151 | #endif |
| 152 | break; |
| 153 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 154 | default: |
| 155 | break; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 156 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 157 | } |
| 158 | if (m_string.empty()) { |
| 159 | if (default_error_str) |
| 160 | m_string.assign(default_error_str); |
| 161 | else |
| 162 | return nullptr; // User wanted a nullptr string back... |
| 163 | } |
| 164 | return m_string.c_str(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 165 | } |
| 166 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 167 | // Clear the error and any cached error string that it might contain. |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 168 | void Status::Clear() { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 169 | m_code = 0; |
| 170 | m_type = eErrorTypeInvalid; |
| 171 | m_string.clear(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 172 | } |
| 173 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 174 | // Access the error value. |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 175 | Status::ValueType Status::GetError() const { return m_code; } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 176 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 177 | // Access the error type. |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 178 | ErrorType Status::GetType() const { return m_type; } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 179 | |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 180 | // Returns true if this object contains a value that describes an error or |
| 181 | // otherwise non-success result. |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 182 | bool Status::Fail() const { return m_code != 0; } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 183 | |
Bruce Mitchener | 4ebdee0 | 2018-05-29 09:10:46 +0000 | [diff] [blame] | 184 | // Set accessor for the error value to "err" and the type to |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 185 | // "eErrorTypeMachKernel" |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 186 | void Status::SetMachError(uint32_t err) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 187 | m_code = err; |
| 188 | m_type = eErrorTypeMachKernel; |
| 189 | m_string.clear(); |
| 190 | } |
| 191 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 192 | void Status::SetExpressionError(lldb::ExpressionResults result, |
| 193 | const char *mssg) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 194 | m_code = result; |
| 195 | m_type = eErrorTypeExpression; |
| 196 | m_string = mssg; |
| 197 | } |
| 198 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 199 | int Status::SetExpressionErrorWithFormat(lldb::ExpressionResults result, |
| 200 | const char *format, ...) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 201 | int length = 0; |
| 202 | |
| 203 | if (format != nullptr && format[0]) { |
| 204 | va_list args; |
| 205 | va_start(args, format); |
| 206 | length = SetErrorStringWithVarArg(format, args); |
| 207 | va_end(args); |
| 208 | } else { |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 209 | m_string.clear(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 210 | } |
| 211 | m_code = result; |
| 212 | m_type = eErrorTypeExpression; |
| 213 | return length; |
Jim Ingham | 1624a2d | 2014-05-05 02:26:40 +0000 | [diff] [blame] | 214 | } |
| 215 | |
Bruce Mitchener | 4ebdee0 | 2018-05-29 09:10:46 +0000 | [diff] [blame] | 216 | // Set accessor for the error value and type. |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 217 | void Status::SetError(ValueType err, ErrorType type) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 218 | m_code = err; |
| 219 | m_type = type; |
| 220 | m_string.clear(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 221 | } |
| 222 | |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 223 | // Update the error value to be "errno" and update the type to be "POSIX". |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 224 | void Status::SetErrorToErrno() { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 225 | m_code = errno; |
| 226 | m_type = eErrorTypePOSIX; |
| 227 | m_string.clear(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 228 | } |
| 229 | |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 230 | // Update the error value to be LLDB_GENERIC_ERROR and update the type to be |
| 231 | // "Generic". |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 232 | void Status::SetErrorToGenericError() { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 233 | m_code = LLDB_GENERIC_ERROR; |
| 234 | m_type = eErrorTypeGeneric; |
| 235 | m_string.clear(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 236 | } |
| 237 | |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 238 | // Set accessor for the error string value for a specific error. This allows |
| 239 | // any string to be supplied as an error explanation. The error string value |
| 240 | // will remain until the error value is cleared or a new error value/type is |
| 241 | // assigned. |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 242 | void Status::SetErrorString(llvm::StringRef err_str) { |
Zachary Turner | c156427 | 2016-11-16 21:15:24 +0000 | [diff] [blame] | 243 | if (!err_str.empty()) { |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 244 | // If we have an error string, we should always at least have an error set |
| 245 | // to a generic value. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 246 | if (Success()) |
| 247 | SetErrorToGenericError(); |
Zachary Turner | c156427 | 2016-11-16 21:15:24 +0000 | [diff] [blame] | 248 | } |
Benjamin Kramer | adcd026 | 2020-01-28 20:23:46 +0100 | [diff] [blame] | 249 | m_string = std::string(err_str); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 250 | } |
| 251 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 252 | /// Set the current error string to a formatted error string. |
| 253 | /// |
Adrian Prantl | f05b42e | 2019-03-11 17:09:29 +0000 | [diff] [blame] | 254 | /// \param format |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 255 | /// A printf style format string |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 256 | int Status::SetErrorStringWithFormat(const char *format, ...) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 257 | if (format != nullptr && format[0]) { |
| 258 | va_list args; |
| 259 | va_start(args, format); |
| 260 | int length = SetErrorStringWithVarArg(format, args); |
| 261 | va_end(args); |
| 262 | return length; |
| 263 | } else { |
| 264 | m_string.clear(); |
| 265 | } |
| 266 | return 0; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 267 | } |
| 268 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 269 | int Status::SetErrorStringWithVarArg(const char *format, va_list args) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 270 | if (format != nullptr && format[0]) { |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 271 | // If we have an error string, we should always at least have an error set |
| 272 | // to a generic value. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 273 | if (Success()) |
| 274 | SetErrorToGenericError(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 275 | |
Zachary Turner | 24ae629 | 2017-02-16 19:38:21 +0000 | [diff] [blame] | 276 | llvm::SmallString<1024> buf; |
| 277 | VASprintf(buf, format, args); |
Benjamin Kramer | adcd026 | 2020-01-28 20:23:46 +0100 | [diff] [blame] | 278 | m_string = std::string(buf.str()); |
Zachary Turner | 24ae629 | 2017-02-16 19:38:21 +0000 | [diff] [blame] | 279 | return buf.size(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 280 | } else { |
| 281 | m_string.clear(); |
| 282 | } |
| 283 | return 0; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 284 | } |
| 285 | |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 286 | // Returns true if the error code in this object is considered a successful |
| 287 | // return value. |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 288 | bool Status::Success() const { return m_code == 0; } |
Jim Ingham | 4e5c821 | 2013-06-07 22:09:53 +0000 | [diff] [blame] | 289 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 290 | bool Status::WasInterrupted() const { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 291 | return (m_type == eErrorTypePOSIX && m_code == EINTR); |
Jim Ingham | 4e5c821 | 2013-06-07 22:09:53 +0000 | [diff] [blame] | 292 | } |
Zachary Turner | 33aba3c | 2017-02-06 18:31:44 +0000 | [diff] [blame] | 293 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 294 | void llvm::format_provider<lldb_private::Status>::format( |
| 295 | const lldb_private::Status &error, llvm::raw_ostream &OS, |
Zachary Turner | 33aba3c | 2017-02-06 18:31:44 +0000 | [diff] [blame] | 296 | llvm::StringRef Options) { |
| 297 | llvm::format_provider<llvm::StringRef>::format(error.AsCString(), OS, |
| 298 | Options); |
| 299 | } |