22
22
#include " lldb/Utility/StreamString.h"
23
23
#include " lldb/Utility/StructuredData.h"
24
24
25
+ #include " llvm/ADT/SmallVector.h"
25
26
#include " llvm/ADT/StringRef.h"
26
27
#include " llvm/Support/ConvertUTF.h"
27
28
#include " llvm/Support/ManagedStatic.h"
32
33
using namespace lldb ;
33
34
using namespace lldb_private ;
34
35
36
+ using llvm::sys::windows::UTF8ToUTF16;
37
+
35
38
static bool GetTripleForProcess (const FileSpec &executable,
36
39
llvm::Triple &triple) {
37
40
// Open the PE File as a binary file, and parse just enough information to
@@ -325,31 +328,18 @@ class WindowsEventLog {
325
328
326
329
static llvm::ManagedStatic<WindowsEventLog> event_log;
327
330
328
- static std::wstring AnsiToUtf16 (const std::string &ansi) {
329
- if (ansi.empty ())
330
- return {};
331
-
332
- const int unicode_length =
333
- MultiByteToWideChar (CP_ACP, 0 , ansi.c_str (), -1 , nullptr , 0 );
334
- if (unicode_length == 0 )
335
- return {};
336
-
337
- std::wstring unicode (unicode_length, L' \0 ' );
338
- MultiByteToWideChar (CP_ACP, 0 , ansi.c_str (), -1 , &unicode[0 ], unicode_length);
339
- return unicode;
340
- }
341
-
342
331
void Host::SystemLog (Severity severity, llvm::StringRef message) {
332
+ if (message.empty ())
333
+ return ;
334
+
343
335
HANDLE h = event_log->GetHandle ();
344
336
if (!h)
345
337
return ;
346
338
347
- std::wstring wide_message = AnsiToUtf16 (message. str ()) ;
348
- if (wide_message. empty ( ))
339
+ llvm::SmallVector< wchar_t , 1 > argsUTF16 ;
340
+ if (UTF8ToUTF16 (message. str (), argsUTF16 ))
349
341
return ;
350
342
351
- LPCWSTR msg_ptr = wide_message.c_str ();
352
-
353
343
WORD event_type;
354
344
switch (severity) {
355
345
case lldb::eSeverityWarning:
@@ -363,5 +353,7 @@ void Host::SystemLog(Severity severity, llvm::StringRef message) {
363
353
event_type = EVENTLOG_INFORMATION_TYPE;
364
354
}
365
355
366
- ReportEventW (h, event_type, 0 , 0 , nullptr , 1 , 0 , &msg_ptr, nullptr );
356
+ LPCWSTR messages[1 ] = {argsUTF16.data ()};
357
+ ReportEventW (h, event_type, 0 , 0 , nullptr , std::size (messages), 0 , messages,
358
+ nullptr );
367
359
}
0 commit comments