summaryrefslogtreecommitdiffstats
path: root/lldb/source/Utility/Status.cpp
diff options
context:
space:
mode:
authorAaron Smith <aaron.smith@microsoft.com>2018-10-19 18:58:24 +0000
committerAaron Smith <aaron.smith@microsoft.com>2018-10-19 18:58:24 +0000
commitc3d447fe26f9bf742625f70feadd102c1eed0d99 (patch)
treeabbca6c9e1e8d3665a22254acf4dadcd8b4dc819 /lldb/source/Utility/Status.cpp
parentd294b92dba8faca15d5032f4af860dbf57cc7ce1 (diff)
downloadbcm5719-llvm-c3d447fe26f9bf742625f70feadd102c1eed0d99.tar.gz
bcm5719-llvm-c3d447fe26f9bf742625f70feadd102c1eed0d99.zip
[lldb] Add support in Status::AsCString to retrieve win32 system error strings
Reviewers: rnk, zturner, aleksandr.urakov Subscribers: lldb-commits Differential Revision: https://reviews.llvm.org/D53092 llvm-svn: 344798
Diffstat (limited to 'lldb/source/Utility/Status.cpp')
-rw-r--r--lldb/source/Utility/Status.cpp29
1 files changed, 28 insertions, 1 deletions
diff --git a/lldb/source/Utility/Status.cpp b/lldb/source/Utility/Status.cpp
index f6dc228391b..5caecc69830 100644
--- a/lldb/source/Utility/Status.cpp
+++ b/lldb/source/Utility/Status.cpp
@@ -27,6 +27,9 @@
#include <mach/mach.h>
#endif
+#ifdef _WIN32
+#include <windows.h>
+#endif
#include <stdint.h> // for uint32_t
namespace llvm {
@@ -87,7 +90,8 @@ llvm::Error Status::ToError() const {
if (Success())
return llvm::Error::success();
if (m_type == ErrorType::eErrorTypePOSIX)
- return llvm::errorCodeToError(std::error_code(m_code, std::generic_category()));
+ return llvm::errorCodeToError(
+ std::error_code(m_code, std::generic_category()));
return llvm::make_error<llvm::StringError>(AsCString(),
llvm::inconvertibleErrorCode());
}
@@ -106,6 +110,23 @@ const Status &Status::operator=(const Status &rhs) {
Status::~Status() = default;
+#ifdef _WIN32
+static std::string RetrieveWin32ErrorString(uint32_t error_code) {
+ char *buffer = nullptr;
+ std::string message;
+ // Retrieve win32 system error.
+ if (::FormatMessageA(
+ FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
+ FORMAT_MESSAGE_MAX_WIDTH_MASK,
+ NULL, error_code, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
+ (LPSTR)&buffer, 0, NULL)) {
+ message.assign(buffer);
+ ::LocalFree(buffer);
+ }
+ return message;
+}
+#endif
+
//----------------------------------------------------------------------
// Get the error value as a NULL C string. The error string will be fetched and
// cached on demand. The cached error string value will remain until the error
@@ -128,6 +149,12 @@ const char *Status::AsCString(const char *default_error_str) const {
m_string = llvm::sys::StrError(m_code);
break;
+ case eErrorTypeWin32:
+#if defined(_WIN32)
+ m_string = RetrieveWin32ErrorString(m_code);
+#endif
+ break;
+
default:
break;
}
OpenPOWER on IntegriCloud