[Lldb-commits] [lldb] bdad3ec - [LLDB] On Windows, force error message formatting to English

Alexandre Ganea via lldb-commits lldb-commits at lists.llvm.org
Thu Nov 28 11:15:34 PST 2019


Author: Alexandre Ganea
Date: 2019-11-28T14:15:13-05:00
New Revision: bdad3ec75ab35ade2433b1278689d483dcf9abc4

URL: https://github.com/llvm/llvm-project/commit/bdad3ec75ab35ade2433b1278689d483dcf9abc4
DIFF: https://github.com/llvm/llvm-project/commit/bdad3ec75ab35ade2433b1278689d483dcf9abc4.diff

LOG: [LLDB] On Windows, force error message formatting to English

This fixes the Utility/StatusTest.ErrorWin32 unit test on non-English locales.

Differential Revision: https://reviews.llvm.org/D70442

Added: 
    

Modified: 
    lldb/source/Utility/Status.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/source/Utility/Status.cpp b/lldb/source/Utility/Status.cpp
index 3b5094d64b75..b74db72773dd 100644
--- a/lldb/source/Utility/Status.cpp
+++ b/lldb/source/Utility/Status.cpp
@@ -100,14 +100,23 @@ static std::string RetrieveWin32ErrorString(uint32_t error_code) {
   char *buffer = nullptr;
   std::string message;
   // Retrieve win32 system error.
+  // First, attempt to load a en-US message
   if (::FormatMessageA(
           FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
               FORMAT_MESSAGE_MAX_WIDTH_MASK,
-          NULL, error_code, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
+          NULL, error_code, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US),
           (LPSTR)&buffer, 0, NULL)) {
     message.assign(buffer);
     ::LocalFree(buffer);
   }
+  // If the previous didn't work, use the default OS language
+  else if (::FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER |
+                                FORMAT_MESSAGE_FROM_SYSTEM |
+                                FORMAT_MESSAGE_MAX_WIDTH_MASK,
+                            NULL, error_code, 0, (LPSTR)&buffer, 0, NULL)) {
+    message.assign(buffer);
+    ::LocalFree(buffer);
+  }
   return message;
 }
 #endif


        


More information about the lldb-commits mailing list