Remove the callback-based log channel registration mechanism

All the existing channels have beens switched to the new mechanism and
this code is now unused.

llvm-svn: 296333
This commit is contained in:
Pavel Labath 2017-02-27 12:21:16 +00:00
parent c43b20a43b
commit 3474ebc4c5
3 changed files with 2 additions and 88 deletions

View File

@ -12,7 +12,6 @@
// Project includes // Project includes
#include "lldb/Core/Logging.h" #include "lldb/Core/Logging.h"
#include "lldb/Utility/ConstString.h"
#include "lldb/Utility/Flags.h" #include "lldb/Utility/Flags.h"
#include "lldb/lldb-private.h" #include "lldb/lldb-private.h"
@ -92,36 +91,12 @@ public:
void Disable(uint32_t flags); void Disable(uint32_t flags);
}; };
//------------------------------------------------------------------
// Callback definitions for abstracted plug-in log access.
//------------------------------------------------------------------
typedef void (*DisableCallback)(const char **categories,
Stream *feedback_strm);
typedef Log *(*EnableCallback)(
const std::shared_ptr<llvm::raw_ostream> &log_stream_sp,
uint32_t log_options, const char **categories, Stream *feedback_strm);
typedef void (*ListCategoriesCallback)(Stream *strm);
struct Callbacks {
DisableCallback disable;
EnableCallback enable;
ListCategoriesCallback list_categories;
};
//------------------------------------------------------------------ //------------------------------------------------------------------
// Static accessors for logging channels // Static accessors for logging channels
//------------------------------------------------------------------ //------------------------------------------------------------------
static void Register(llvm::StringRef name, Channel &channel); static void Register(llvm::StringRef name, Channel &channel);
static void Unregister(llvm::StringRef name); static void Unregister(llvm::StringRef name);
static void RegisterLogChannel(const ConstString &channel,
const Log::Callbacks &log_callbacks);
static bool UnregisterLogChannel(const ConstString &channel);
static bool GetLogChannelCallbacks(const ConstString &channel,
Log::Callbacks &log_callbacks);
static bool static bool
EnableLogChannel(const std::shared_ptr<llvm::raw_ostream> &log_stream_sp, EnableLogChannel(const std::shared_ptr<llvm::raw_ostream> &log_stream_sp,
uint32_t log_options, llvm::StringRef channel, uint32_t log_options, llvm::StringRef channel,

View File

@ -17,6 +17,7 @@
#include "lldb/Core/Log.h" #include "lldb/Core/Log.h"
#include "lldb/Interpreter/CommandReturnObject.h" #include "lldb/Interpreter/CommandReturnObject.h"
#include "lldb/Utility/ConstString.h"
#include "lldb/Utility/Error.h" #include "lldb/Utility/Error.h"
using namespace lldb; using namespace lldb;

View File

@ -222,16 +222,6 @@ void Log::Warning(const char *format, ...) {
free(arg_msg); free(arg_msg);
} }
typedef std::map<ConstString, Log::Callbacks> CallbackMap;
typedef CallbackMap::iterator CallbackMapIter;
// Surround our callback map with a singleton function so we don't have any
// global initializers.
static CallbackMap &GetCallbackMap() {
static CallbackMap g_callback_map;
return g_callback_map;
}
void Log::Register(llvm::StringRef name, Channel &channel) { void Log::Register(llvm::StringRef name, Channel &channel) {
auto iter = g_channel_map->try_emplace(name, channel); auto iter = g_channel_map->try_emplace(name, channel);
assert(iter.second == true); assert(iter.second == true);
@ -245,37 +235,10 @@ void Log::Unregister(llvm::StringRef name) {
g_channel_map->erase(iter); g_channel_map->erase(iter);
} }
void Log::RegisterLogChannel(const ConstString &channel,
const Log::Callbacks &log_callbacks) {
GetCallbackMap().insert(std::make_pair(channel, log_callbacks));
}
bool Log::UnregisterLogChannel(const ConstString &channel) {
return GetCallbackMap().erase(channel) != 0;
}
bool Log::GetLogChannelCallbacks(const ConstString &channel,
Log::Callbacks &log_callbacks) {
CallbackMap &callback_map = GetCallbackMap();
CallbackMapIter pos = callback_map.find(channel);
if (pos != callback_map.end()) {
log_callbacks = pos->second;
return true;
}
::memset(&log_callbacks, 0, sizeof(log_callbacks));
return false;
}
bool Log::EnableLogChannel( bool Log::EnableLogChannel(
const std::shared_ptr<llvm::raw_ostream> &log_stream_sp, const std::shared_ptr<llvm::raw_ostream> &log_stream_sp,
uint32_t log_options, llvm::StringRef channel, const char **categories, uint32_t log_options, llvm::StringRef channel, const char **categories,
Stream &error_stream) { 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);
return true;
}
auto iter = g_channel_map->find(channel); auto iter = g_channel_map->find(channel);
if (iter == g_channel_map->end()) { if (iter == g_channel_map->end()) {
error_stream.Format("Invalid log channel '{0}'.\n", channel); error_stream.Format("Invalid log channel '{0}'.\n", channel);
@ -291,12 +254,6 @@ bool Log::EnableLogChannel(
bool Log::DisableLogChannel(llvm::StringRef channel, const char **categories, bool Log::DisableLogChannel(llvm::StringRef channel, const char **categories,
Stream &error_stream) { Stream &error_stream) {
Log::Callbacks log_callbacks;
if (Log::GetLogChannelCallbacks(ConstString(channel), log_callbacks)) {
log_callbacks.disable(categories, &error_stream);
return true;
}
auto iter = g_channel_map->find(channel); auto iter = g_channel_map->find(channel);
if (iter == g_channel_map->end()) { if (iter == g_channel_map->end()) {
error_stream.Format("Invalid log channel '{0}'.\n", channel); error_stream.Format("Invalid log channel '{0}'.\n", channel);
@ -310,12 +267,6 @@ bool Log::DisableLogChannel(llvm::StringRef channel, const char **categories,
} }
bool Log::ListChannelCategories(llvm::StringRef channel, Stream &stream) { bool Log::ListChannelCategories(llvm::StringRef channel, Stream &stream) {
Log::Callbacks log_callbacks;
if (Log::GetLogChannelCallbacks(ConstString(channel), log_callbacks)) {
log_callbacks.list_categories(&stream);
return true;
}
auto ch = g_channel_map->find(channel); auto ch = g_channel_map->find(channel);
if (ch == g_channel_map->end()) { if (ch == g_channel_map->end()) {
stream.Format("Invalid log channel '{0}'.\n", channel); stream.Format("Invalid log channel '{0}'.\n", channel);
@ -326,29 +277,16 @@ bool Log::ListChannelCategories(llvm::StringRef channel, Stream &stream) {
} }
void Log::DisableAllLogChannels(Stream *feedback_strm) { void Log::DisableAllLogChannels(Stream *feedback_strm) {
CallbackMap &callback_map = GetCallbackMap();
CallbackMapIter pos, end = callback_map.end();
const char *categories[] = {"all", nullptr};
for (pos = callback_map.begin(); pos != end; ++pos)
pos->second.disable(categories, feedback_strm);
for (auto &entry : *g_channel_map) for (auto &entry : *g_channel_map)
entry.second.channel.Disable(UINT32_MAX); entry.second.channel.Disable(UINT32_MAX);
} }
void Log::ListAllLogChannels(Stream *strm) { void Log::ListAllLogChannels(Stream *strm) {
CallbackMap &callback_map = GetCallbackMap(); if (g_channel_map->empty()) {
if (callback_map.empty() && g_channel_map->empty()) {
strm->PutCString("No logging channels are currently registered.\n"); strm->PutCString("No logging channels are currently registered.\n");
return; return;
} }
CallbackMapIter pos, end = callback_map.end();
for (pos = callback_map.begin(); pos != end; ++pos)
pos->second.list_categories(strm);
for (const auto &channel : *g_channel_map) for (const auto &channel : *g_channel_map)
ListCategories(*strm, channel); ListCategories(*strm, channel);
} }