Skip to content

Commit bbee0c7

Browse files
committed
[lldb] Adjust LogChannelSwift for upstream logging changes
1 parent 1d6e34e commit bbee0c7

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

lldb/source/Plugins/Language/Swift/LogChannelSwift.cpp

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "LogChannelSwift.h"
10+
#include "lldb/Utility/Log.h"
1011
#include "lldb/Version/Version.h"
1112

1213
using namespace lldb_private;
@@ -25,20 +26,39 @@ template <> Log::Channel &lldb_private::LogChannelFor<SwiftLog>() {
2526
return g_channel;
2627
}
2728

29+
class StringLogHandler : public LogHandler {
30+
public:
31+
StringLogHandler(std::string& str) : m_string(str) {}
32+
33+
void Emit(llvm::StringRef message) override {
34+
std::lock_guard<std::mutex> guard(m_mutex);
35+
m_string += std::string(message);
36+
}
37+
38+
bool isA(const void *ClassID) const override { return ClassID == &ID; }
39+
static bool classof(const LogHandler *obj) { return obj->isA(&ID); }
40+
41+
private:
42+
std::mutex m_mutex;
43+
std::string& m_string;
44+
static char ID;
45+
};
46+
47+
char StringLogHandler::ID;
48+
2849
void LogChannelSwift::Initialize() {
2950
Log::Register("swift", g_channel);
3051

31-
llvm::raw_null_ostream error_stream;
32-
Log::EnableLogChannel(
33-
std::make_shared<llvm::raw_string_ostream>(g_swift_log_buffer),
34-
LLDB_LOG_OPTION_THREADSAFE, "swift", {"health"}, error_stream);
52+
auto log_handler_sp = std::make_shared<StringLogHandler>(g_swift_log_buffer);
53+
Log::EnableLogChannel(log_handler_sp, 0, "swift", {"health"}, llvm::nulls());
3554
if (Log *log = GetSwiftHealthLog())
3655
log->Printf(
3756
"==== LLDB swift-healthcheck log. ===\n"
3857
"This file contains the configuration of LLDB's embedded Swift "
3958
"compiler to help diagnosing module import and search path issues. "
4059
"The swift-healthcheck command is meant to be run *after* an error "
41-
"has occurred.\n%s", lldb_private::GetVersion());
60+
"has occurred.\n%s",
61+
lldb_private::GetVersion());
4262
}
4363

4464
void LogChannelSwift::Terminate() { Log::Unregister("swift"); }

0 commit comments

Comments
 (0)