summaryrefslogtreecommitdiffstats
path: root/lldb/source
diff options
context:
space:
mode:
authorPavel Labath <labath@google.com>2017-02-10 11:49:21 +0000
committerPavel Labath <labath@google.com>2017-02-10 11:49:21 +0000
commit5fae71c51cc8c3d51e86cd597ce91a254e9175f4 (patch)
tree07566b6e6ea25ad4cd1fe0138e69b3b15650d072 /lldb/source
parent30a02088c0dcf07dcb38bc9fd2f8221154cff449 (diff)
downloadbcm5719-llvm-5fae71c51cc8c3d51e86cd597ce91a254e9175f4.tar.gz
bcm5719-llvm-5fae71c51cc8c3d51e86cd597ce91a254e9175f4.zip
Convert Log class to llvm streams
Summary: This converts LLDB's logging to use llvm streams instead of lldb_private::Stream and friends. The changes are mostly straight-forward and amount to s/lldb_private::Stream/llvm::raw_ostream. The part worth calling out is the rewrite of the StreamCallback class. Previously this class contained a per-thread buffer of data written. I assume this had something to do with it trying to make sure each log line is delivered as a single event, instead of multiple (possibly interleaved) events. However, this is no longer relevant as the Log class already writes things to a temporary buffer and then delivers the message as a single "write", so I have just removed the code in question. Reviewers: zturner, clayborg Subscribers: emaste, lldb-commits, mgorny Differential Revision: https://reviews.llvm.org/D29615 llvm-svn: 294736
Diffstat (limited to 'lldb/source')
-rw-r--r--lldb/source/Core/Debugger.cpp28
-rw-r--r--lldb/source/Core/Log.cpp24
-rw-r--r--lldb/source/Core/Logging.cpp7
-rw-r--r--lldb/source/Core/StreamCallback.cpp37
-rw-r--r--lldb/source/Plugins/Process/POSIX/ProcessPOSIXLog.cpp5
-rw-r--r--lldb/source/Plugins/Process/POSIX/ProcessPOSIXLog.h7
-rw-r--r--lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemoteLog.cpp7
-rw-r--r--lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemoteLog.h5
-rw-r--r--lldb/source/Plugins/SymbolFile/DWARF/LogChannelDWARF.cpp3
-rw-r--r--lldb/source/Plugins/SymbolFile/DWARF/LogChannelDWARF.h3
10 files changed, 57 insertions, 69 deletions
diff --git a/lldb/source/Core/Debugger.cpp b/lldb/source/Core/Debugger.cpp
index bbcbc8ee723..451c2e5513f 100644
--- a/lldb/source/Core/Debugger.cpp
+++ b/lldb/source/Core/Debugger.cpp
@@ -17,6 +17,7 @@
// Other libraries and framework includes
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/DynamicLibrary.h"
+#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Threading.h"
// Project includes
@@ -1241,25 +1242,34 @@ void Debugger::SetLoggingCallback(lldb::LogOutputCallback log_callback,
bool Debugger::EnableLog(const char *channel, const char **categories,
const char *log_file, uint32_t log_options,
Stream &error_stream) {
- StreamSP log_stream_sp;
+ const bool should_close = true;
+ const bool unbuffered = true;
+
+ std::shared_ptr<llvm::raw_ostream> log_stream_sp;
if (m_log_callback_stream_sp) {
log_stream_sp = m_log_callback_stream_sp;
// For now when using the callback mode you always get thread & timestamp.
log_options |=
LLDB_LOG_OPTION_PREPEND_TIMESTAMP | LLDB_LOG_OPTION_PREPEND_THREAD_NAME;
} else if (log_file == nullptr || *log_file == '\0') {
- log_stream_sp = GetOutputFile();
+ log_stream_sp = std::make_shared<llvm::raw_fd_ostream>(
+ GetOutputFile()->GetFile().GetDescriptor(), !should_close, unbuffered);
} else {
- LogStreamMap::iterator pos = m_log_streams.find(log_file);
+ auto pos = m_log_streams.find(log_file);
if (pos != m_log_streams.end())
log_stream_sp = pos->second.lock();
if (!log_stream_sp) {
- uint32_t options = File::eOpenOptionWrite | File::eOpenOptionCanCreate |
- File::eOpenOptionCloseOnExec | File::eOpenOptionAppend;
- if (!(log_options & LLDB_LOG_OPTION_APPEND))
- options |= File::eOpenOptionTruncate;
-
- log_stream_sp.reset(new StreamFile(log_file, options));
+ llvm::sys::fs::OpenFlags flags = llvm::sys::fs::F_Text;
+ if (log_options & LLDB_LOG_OPTION_APPEND)
+ flags |= llvm::sys::fs::F_Append;
+ int FD;
+ if (std::error_code ec =
+ llvm::sys::fs::openFileForWrite(log_file, FD, flags)) {
+ error_stream.Format("Unable to open log file: {0}", ec.message());
+ return false;
+ }
+ log_stream_sp.reset(
+ new llvm::raw_fd_ostream(FD, should_close, unbuffered));
m_log_streams[log_file] = log_stream_sp;
}
}
diff --git a/lldb/source/Core/Log.cpp b/lldb/source/Core/Log.cpp
index a2ff2f2b711..14b237826ff 100644
--- a/lldb/source/Core/Log.cpp
+++ b/lldb/source/Core/Log.cpp
@@ -38,7 +38,7 @@ using namespace lldb_private;
Log::Log() : m_stream_sp(), m_options(0), m_mask_bits(0) {}
-Log::Log(const StreamSP &stream_sp)
+Log::Log(const std::shared_ptr<llvm::raw_ostream> &stream_sp)
: m_stream_sp(stream_sp), m_options(0), m_mask_bits(0) {}
Log::~Log() = default;
@@ -202,9 +202,10 @@ bool Log::GetLogChannelCallbacks(const ConstString &channel,
return false;
}
-bool Log::EnableLogChannel(lldb::StreamSP &log_stream_sp, uint32_t log_options,
- const char *channel, const char **categories,
- Stream &error_stream) {
+bool Log::EnableLogChannel(
+ const std::shared_ptr<llvm::raw_ostream> &log_stream_sp,
+ uint32_t log_options, const char *channel, const char **categories,
+ Stream &error_stream) {
Log::Callbacks log_callbacks;
if (Log::GetLogChannelCallbacks(ConstString(channel), log_callbacks)) {
log_callbacks.enable(log_stream_sp, log_options, categories, &error_stream);
@@ -226,8 +227,9 @@ bool Log::EnableLogChannel(lldb::StreamSP &log_stream_sp, uint32_t log_options,
}
}
-void Log::EnableAllLogChannels(StreamSP &log_stream_sp, uint32_t log_options,
- const char **categories, Stream *feedback_strm) {
+void Log::EnableAllLogChannels(
+ const std::shared_ptr<llvm::raw_ostream> &log_stream_sp,
+ uint32_t log_options, const char **categories, Stream *feedback_strm) {
CallbackMap &callback_map = GetCallbackMap();
CallbackMapIter pos, end = callback_map.end();
@@ -355,18 +357,18 @@ void Log::WriteHeader(llvm::raw_ostream &OS, llvm::StringRef file,
void Log::WriteMessage(const std::string &message) {
// Make a copy of our stream shared pointer in case someone disables our
// log while we are logging and releases the stream
- StreamSP stream_sp(m_stream_sp);
+ auto stream_sp = m_stream_sp;
if (!stream_sp)
return;
if (m_options.Test(LLDB_LOG_OPTION_THREADSAFE)) {
static std::recursive_mutex g_LogThreadedMutex;
std::lock_guard<std::recursive_mutex> guard(g_LogThreadedMutex);
- stream_sp->PutCString(message.c_str());
- stream_sp->Flush();
+ *stream_sp << message;
+ stream_sp->flush();
} else {
- stream_sp->PutCString(message.c_str());
- stream_sp->Flush();
+ *stream_sp << message;
+ stream_sp->flush();
}
}
diff --git a/lldb/source/Core/Logging.cpp b/lldb/source/Core/Logging.cpp
index 1d42df111a4..49e22c4b0c8 100644
--- a/lldb/source/Core/Logging.cpp
+++ b/lldb/source/Core/Logging.cpp
@@ -167,14 +167,15 @@ void lldb_private::DisableLog(const char **categories, Stream *feedback_strm) {
}
log->GetMask().Reset(flag_bits);
if (flag_bits == 0) {
- log->SetStream(lldb::StreamSP());
+ log->SetStream(nullptr);
g_log_enabled = false;
}
}
}
-Log *lldb_private::EnableLog(StreamSP &log_stream_sp, uint32_t log_options,
- const char **categories, Stream *feedback_strm) {
+Log *lldb_private::EnableLog(
+ const std::shared_ptr<llvm::raw_ostream> &log_stream_sp,
+ uint32_t log_options, const char **categories, Stream *feedback_strm) {
// Try see if there already is a log - that way we can reuse its settings.
// We could reuse the log in toto, but we don't know that the stream is the
// same.
diff --git a/lldb/source/Core/StreamCallback.cpp b/lldb/source/Core/StreamCallback.cpp
index de784101e96..95f4293891a 100644
--- a/lldb/source/Core/StreamCallback.cpp
+++ b/lldb/source/Core/StreamCallback.cpp
@@ -7,44 +7,15 @@
//
//===----------------------------------------------------------------------===//
-#include <stdio.h>
-
-#include "lldb/Core/Broadcaster.h"
-#include "lldb/Core/Event.h"
#include "lldb/Core/StreamCallback.h"
-#include "lldb/Host/Host.h"
-#include "lldb/lldb-private.h"
-using namespace lldb;
using namespace lldb_private;
StreamCallback::StreamCallback(lldb::LogOutputCallback callback, void *baton)
- : Stream(0, 4, eByteOrderBig), m_callback(callback), m_baton(baton),
- m_accumulated_data(), m_collection_mutex() {}
-
-StreamCallback::~StreamCallback() {}
+ : llvm::raw_ostream(true), m_callback(callback), m_baton(baton) {}
-StreamString &StreamCallback::FindStreamForThread(lldb::tid_t cur_tid) {
- std::lock_guard<std::mutex> guard(m_collection_mutex);
- collection::iterator iter = m_accumulated_data.find(cur_tid);
- if (iter == m_accumulated_data.end()) {
- std::pair<collection::iterator, bool> ret;
- ret = m_accumulated_data.insert(
- std::pair<lldb::tid_t, StreamString>(cur_tid, StreamString()));
- iter = ret.first;
- }
- return (*iter).second;
+void StreamCallback::write_impl(const char *Ptr, size_t Size) {
+ m_callback(std::string(Ptr, Size).c_str(), m_baton);
}
-void StreamCallback::Flush() {
- lldb::tid_t cur_tid = Host::GetCurrentThreadID();
- StreamString &out_stream = FindStreamForThread(cur_tid);
- m_callback(out_stream.GetData(), m_baton);
- out_stream.Clear();
-}
-
-size_t StreamCallback::Write(const void *s, size_t length) {
- lldb::tid_t cur_tid = Host::GetCurrentThreadID();
- FindStreamForThread(cur_tid).Write(s, length);
- return length;
-}
+uint64_t StreamCallback::current_pos() const { return 0; }
diff --git a/lldb/source/Plugins/Process/POSIX/ProcessPOSIXLog.cpp b/lldb/source/Plugins/Process/POSIX/ProcessPOSIXLog.cpp
index f2d4e38033e..a148b5f9157 100644
--- a/lldb/source/Plugins/Process/POSIX/ProcessPOSIXLog.cpp
+++ b/lldb/source/Plugins/Process/POSIX/ProcessPOSIXLog.cpp
@@ -115,8 +115,9 @@ void ProcessPOSIXLog::DisableLog(const char **args, Stream *feedback_strm) {
return;
}
-Log *ProcessPOSIXLog::EnableLog(StreamSP &log_stream_sp, uint32_t log_options,
- const char **args, Stream *feedback_strm) {
+Log *ProcessPOSIXLog::EnableLog(
+ const std::shared_ptr<llvm::raw_ostream> &log_stream_sp,
+ uint32_t log_options, const char **args, Stream *feedback_strm) {
// Try see if there already is a log - that way we can reuse its settings.
// We could reuse the log in toto, but we don't know that the stream is the
// same.
diff --git a/lldb/source/Plugins/Process/POSIX/ProcessPOSIXLog.h b/lldb/source/Plugins/Process/POSIX/ProcessPOSIXLog.h
index 00af3dd5081..b277349b8d8 100644
--- a/lldb/source/Plugins/Process/POSIX/ProcessPOSIXLog.h
+++ b/lldb/source/Plugins/Process/POSIX/ProcessPOSIXLog.h
@@ -62,9 +62,10 @@ public:
static void DisableLog(const char **args,
lldb_private::Stream *feedback_strm);
- static lldb_private::Log *EnableLog(lldb::StreamSP &log_stream_sp,
- uint32_t log_options, const char **args,
- lldb_private::Stream *feedback_strm);
+ static lldb_private::Log *
+ EnableLog(const std::shared_ptr<llvm::raw_ostream> &log_stream_sp,
+ uint32_t log_options, const char **args,
+ lldb_private::Stream *feedback_strm);
static void ListLogCategories(lldb_private::Stream *strm);
diff --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemoteLog.cpp b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemoteLog.cpp
index f84ac7996ab..c94017a21ea 100644
--- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemoteLog.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemoteLog.cpp
@@ -115,10 +115,9 @@ void ProcessGDBRemoteLog::DisableLog(const char **categories,
return;
}
-Log *ProcessGDBRemoteLog::EnableLog(StreamSP &log_stream_sp,
- uint32_t log_options,
- const char **categories,
- Stream *feedback_strm) {
+Log *ProcessGDBRemoteLog::EnableLog(
+ const std::shared_ptr<llvm::raw_ostream> &log_stream_sp,
+ uint32_t log_options, const char **categories, Stream *feedback_strm) {
// Try see if there already is a log - that way we can reuse its settings.
// We could reuse the log in toto, but we don't know that the stream is the
// same.
diff --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemoteLog.h b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemoteLog.h
index ec0d4b035ff..d22a6c6b516 100644
--- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemoteLog.h
+++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemoteLog.h
@@ -45,8 +45,9 @@ public:
static void DisableLog(const char **categories, Stream *feedback_strm);
- static Log *EnableLog(lldb::StreamSP &log_stream_sp, uint32_t log_options,
- const char **categories, Stream *feedback_strm);
+ static Log *EnableLog(const std::shared_ptr<llvm::raw_ostream> &log_stream_sp,
+ uint32_t log_options, const char **categories,
+ Stream *feedback_strm);
static void ListLogCategories(Stream *strm);
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/LogChannelDWARF.cpp b/lldb/source/Plugins/SymbolFile/DWARF/LogChannelDWARF.cpp
index a6888580927..4c33e255bea 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/LogChannelDWARF.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/LogChannelDWARF.cpp
@@ -95,7 +95,8 @@ void LogChannelDWARF::Disable(const char **categories, Stream *feedback_strm) {
}
bool LogChannelDWARF::Enable(
- StreamSP &log_stream_sp, uint32_t log_options,
+ const std::shared_ptr<llvm::raw_ostream> &log_stream_sp,
+ uint32_t log_options,
Stream *feedback_strm, // Feedback stream for argument errors etc
const char **categories // The categories to enable within this logging
// stream, if empty, enable default set
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/LogChannelDWARF.h b/lldb/source/Plugins/SymbolFile/DWARF/LogChannelDWARF.h
index 393d52bb3b8..8e4963258a8 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/LogChannelDWARF.h
+++ b/lldb/source/Plugins/SymbolFile/DWARF/LogChannelDWARF.h
@@ -52,7 +52,8 @@ public:
void Delete();
- bool Enable(lldb::StreamSP &log_stream_sp, uint32_t log_options,
+ bool Enable(const std::shared_ptr<llvm::raw_ostream> &log_stream_sp,
+ uint32_t log_options,
lldb_private::Stream
*feedback_strm, // Feedback stream for argument errors etc
const char **categories) override; // The categories to enable
OpenPOWER on IntegriCloud