From 5fb8af40df212612ee7845420669119213857811 Mon Sep 17 00:00:00 2001 From: Pavel Labath Date: Wed, 15 Feb 2017 16:11:59 +0000 Subject: Refactor log channel registration mechanism Summary: We currently have two log channel registration mechanisms. One uses a set of function pointers and the other one is based on the PluginManager. The PluginManager dependency is unfortunate, as logging is also used in lldb-server, and the PluginManager pulls in a lot of classes which are not used in lldb-server. Both approach have the problem that they leave too much to do for the user, and so the individual log channels end up reimplementing command line argument parsing, category listing, etc. Here, I replace the PluginManager-based approach with a one. The new API is more declarative, so the user only needs to specify the list of list of channels, their descriptions, etc., and all the common tasks like enabling/disabling categories are hadled by common code. I migrate the LogChannelDWARF (only user of the PluginManager method) to the new API. In the follow-up commits I'll replace the other channels with something similar. Reviewers: clayborg, zturner, beanz Subscribers: aprantl, lldb-commits Differential Revision: https://reviews.llvm.org/D29895 llvm-svn: 295190 --- lldb/source/Commands/CommandObjectLog.cpp | 44 +++++++------------------------ 1 file changed, 10 insertions(+), 34 deletions(-) (limited to 'lldb/source/Commands/CommandObjectLog.cpp') diff --git a/lldb/source/Commands/CommandObjectLog.cpp b/lldb/source/Commands/CommandObjectLog.cpp index 6fbab08ac63..c10f868dea4 100644 --- a/lldb/source/Commands/CommandObjectLog.cpp +++ b/lldb/source/Commands/CommandObjectLog.cpp @@ -227,25 +227,15 @@ protected: return false; } - Log::Callbacks log_callbacks; - const std::string channel = args[0].ref; args.Shift(); // Shift off the channel - if (Log::GetLogChannelCallbacks(ConstString(channel), log_callbacks)) { - log_callbacks.disable(args.GetConstArgumentVector(), - &result.GetErrorStream()); - result.SetStatus(eReturnStatusSuccessFinishNoResult); - } else if (channel == "all") { + if (channel == "all") { Log::DisableAllLogChannels(&result.GetErrorStream()); + result.SetStatus(eReturnStatusSuccessFinishNoResult); } else { - LogChannelSP log_channel_sp(LogChannel::FindPlugin(channel.data())); - if (log_channel_sp) { - log_channel_sp->Disable(args.GetConstArgumentVector(), - &result.GetErrorStream()); + if (Log::DisableLogChannel(channel, args.GetConstArgumentVector(), + result.GetErrorStream())) result.SetStatus(eReturnStatusSuccessFinishNoResult); - } else - result.AppendErrorWithFormat("Invalid log channel '%s'.\n", - channel.data()); } return result.Succeeded(); } @@ -284,26 +274,12 @@ protected: Log::ListAllLogChannels(&result.GetOutputStream()); result.SetStatus(eReturnStatusSuccessFinishResult); } else { - for (auto &entry : args.entries()) { - Log::Callbacks log_callbacks; - - if (Log::GetLogChannelCallbacks(ConstString(entry.ref), - log_callbacks)) { - log_callbacks.list_categories(&result.GetOutputStream()); - result.SetStatus(eReturnStatusSuccessFinishResult); - } else if (entry.ref == "all") { - Log::ListAllLogChannels(&result.GetOutputStream()); - result.SetStatus(eReturnStatusSuccessFinishResult); - } else { - LogChannelSP log_channel_sp(LogChannel::FindPlugin(entry.c_str())); - if (log_channel_sp) { - log_channel_sp->ListCategories(&result.GetOutputStream()); - result.SetStatus(eReturnStatusSuccessFinishNoResult); - } else - result.AppendErrorWithFormat("Invalid log channel '%s'.\n", - entry.c_str()); - } - } + bool success = true; + for (const auto &entry : args.entries()) + success = success && Log::ListChannelCategories( + entry.ref, result.GetOutputStream()); + if (success) + result.SetStatus(eReturnStatusSuccessFinishResult); } return result.Succeeded(); } -- cgit v1.2.3