Author: labath Date: Fri Feb 17 09:08:08 2017 New Revision: 295450 URL: http://llvm.org/viewvc/llvm-project?rev=295450&view=rev Log: Switch ProcessKDPLog to the new channel registration mechanism
Modified: lldb/trunk/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp lldb/trunk/source/Plugins/Process/MacOSX-Kernel/ProcessKDPLog.cpp lldb/trunk/source/Plugins/Process/MacOSX-Kernel/ProcessKDPLog.h lldb/trunk/source/Plugins/Process/MacOSX-Kernel/ThreadKDP.cpp Modified: lldb/trunk/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp?rev=295450&r1=295449&r2=295450&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp (original) +++ lldb/trunk/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp Fri Feb 17 09:08:08 2017 @@ -726,11 +726,7 @@ void ProcessKDP::Initialize() { GetPluginDescriptionStatic(), CreateInstance, DebuggerInitialize); - Log::Callbacks log_callbacks = {ProcessKDPLog::DisableLog, - ProcessKDPLog::EnableLog, - ProcessKDPLog::ListLogCategories}; - - Log::RegisterLogChannel(ProcessKDP::GetPluginNameStatic(), log_callbacks); + ProcessKDPLog::Initialize(); }); } Modified: lldb/trunk/source/Plugins/Process/MacOSX-Kernel/ProcessKDPLog.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/MacOSX-Kernel/ProcessKDPLog.cpp?rev=295450&r1=295449&r2=295450&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Process/MacOSX-Kernel/ProcessKDPLog.cpp (original) +++ lldb/trunk/source/Plugins/Process/MacOSX-Kernel/ProcessKDPLog.cpp Fri Feb 17 09:08:08 2017 @@ -9,181 +9,28 @@ #include "ProcessKDPLog.h" -#include "lldb/Core/StreamFile.h" -#include "lldb/Interpreter/Args.h" - -#include "ProcessKDP.h" - using namespace lldb; using namespace lldb_private; -// We want to avoid global constructors where code needs to be run so here we -// control access to our static g_log_sp by hiding it in a singleton function -// that will construct the static g_log_sp the first time this function is -// called. -static bool g_log_enabled = false; -static Log *g_log = NULL; -static Log *GetLog() { - if (!g_log_enabled) - return NULL; - return g_log; -} - -Log *ProcessKDPLog::GetLogIfAllCategoriesSet(uint32_t mask) { - Log *log(GetLog()); - if (log && mask) { - uint32_t log_mask = log->GetMask().Get(); - if ((log_mask & mask) != mask) - return NULL; - } - return log; -} - -void ProcessKDPLog::DisableLog(const char **categories, Stream *feedback_strm) { - Log *log(GetLog()); - if (log) { - uint32_t flag_bits = 0; - - if (categories[0] != NULL) { - flag_bits = log->GetMask().Get(); - for (size_t i = 0; categories[i] != NULL; ++i) { - const char *arg = categories[i]; - - if (::strcasecmp(arg, "all") == 0) - flag_bits &= ~KDP_LOG_ALL; - else if (::strcasecmp(arg, "async") == 0) - flag_bits &= ~KDP_LOG_ASYNC; - else if (::strncasecmp(arg, "break", 5) == 0) - flag_bits &= ~KDP_LOG_BREAKPOINTS; - else if (::strncasecmp(arg, "comm", 4) == 0) - flag_bits &= ~KDP_LOG_COMM; - else if (::strcasecmp(arg, "default") == 0) - flag_bits &= ~KDP_LOG_DEFAULT; - else if (::strcasecmp(arg, "packets") == 0) - flag_bits &= ~KDP_LOG_PACKETS; - else if (::strcasecmp(arg, "memory") == 0) - flag_bits &= ~KDP_LOG_MEMORY; - else if (::strcasecmp(arg, "data-short") == 0) - flag_bits &= ~KDP_LOG_MEMORY_DATA_SHORT; - else if (::strcasecmp(arg, "data-long") == 0) - flag_bits &= ~KDP_LOG_MEMORY_DATA_LONG; - else if (::strcasecmp(arg, "process") == 0) - flag_bits &= ~KDP_LOG_PROCESS; - else if (::strcasecmp(arg, "step") == 0) - flag_bits &= ~KDP_LOG_STEP; - else if (::strcasecmp(arg, "thread") == 0) - flag_bits &= ~KDP_LOG_THREAD; - else if (::strncasecmp(arg, "watch", 5) == 0) - flag_bits &= ~KDP_LOG_WATCHPOINTS; - else { - feedback_strm->Printf("error: unrecognized log category '%s'\n", arg); - ListLogCategories(feedback_strm); - } - } - } - - log->GetMask().Reset(flag_bits); - if (flag_bits == 0) - g_log_enabled = false; - } - - return; -} - -Log *ProcessKDPLog::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. - uint32_t flag_bits = 0; - if (g_log) - flag_bits = g_log->GetMask().Get(); - - // Now make a new log with this stream if one was provided - if (log_stream_sp) { - if (g_log) - g_log->SetStream(log_stream_sp); - else - g_log = new Log(log_stream_sp); - } - - if (g_log) { - bool got_unknown_category = false; - for (size_t i = 0; categories[i] != NULL; ++i) { - const char *arg = categories[i]; - - if (::strcasecmp(arg, "all") == 0) - flag_bits |= KDP_LOG_ALL; - else if (::strcasecmp(arg, "async") == 0) - flag_bits |= KDP_LOG_ASYNC; - else if (::strncasecmp(arg, "break", 5) == 0) - flag_bits |= KDP_LOG_BREAKPOINTS; - else if (::strncasecmp(arg, "comm", 4) == 0) - flag_bits |= KDP_LOG_COMM; - else if (::strcasecmp(arg, "default") == 0) - flag_bits |= KDP_LOG_DEFAULT; - else if (::strcasecmp(arg, "packets") == 0) - flag_bits |= KDP_LOG_PACKETS; - else if (::strcasecmp(arg, "memory") == 0) - flag_bits |= KDP_LOG_MEMORY; - else if (::strcasecmp(arg, "data-short") == 0) - flag_bits |= KDP_LOG_MEMORY_DATA_SHORT; - else if (::strcasecmp(arg, "data-long") == 0) - flag_bits |= KDP_LOG_MEMORY_DATA_LONG; - else if (::strcasecmp(arg, "process") == 0) - flag_bits |= KDP_LOG_PROCESS; - else if (::strcasecmp(arg, "step") == 0) - flag_bits |= KDP_LOG_STEP; - else if (::strcasecmp(arg, "thread") == 0) - flag_bits |= KDP_LOG_THREAD; - else if (::strncasecmp(arg, "watch", 5) == 0) - flag_bits |= KDP_LOG_WATCHPOINTS; - else { - feedback_strm->Printf("error: unrecognized log category '%s'\n", arg); - if (got_unknown_category == false) { - got_unknown_category = true; - ListLogCategories(feedback_strm); - } - } - } - if (flag_bits == 0) - flag_bits = KDP_LOG_DEFAULT; - g_log->GetMask().Reset(flag_bits); - g_log->GetOptions().Reset(log_options); - } - g_log_enabled = true; - return g_log; -} +static constexpr Log::Category g_categories[] = { + {{"async"}, {"log asynchronous activity"}, KDP_LOG_ASYNC}, + {{"break"}, {"log breakpoints"}, KDP_LOG_BREAKPOINTS}, + {{"comm"}, {"log communication activity"}, KDP_LOG_COMM}, + {{"data-long"}, + {"log memory bytes for memory reads and writes for all transactions"}, + KDP_LOG_MEMORY_DATA_LONG}, + {{"data-short"}, + {"log memory bytes for memory reads and writes for short transactions " + "only"}, + KDP_LOG_MEMORY_DATA_SHORT}, + {{"memory"}, {"log memory reads and writes"}, KDP_LOG_MEMORY}, + {{"packets"}, {"log gdb remote packets"}, KDP_LOG_PACKETS}, + {{"process"}, {"log process events and activities"}, KDP_LOG_PROCESS}, + {{"step"}, {"log step related activities"}, KDP_LOG_STEP}, + {{"thread"}, {"log thread events and activities"}, KDP_LOG_THREAD}, + {{"watch"}, {"log watchpoint related activities"}, KDP_LOG_WATCHPOINTS}, +}; -void ProcessKDPLog::ListLogCategories(Stream *strm) { - strm->Printf( - "Logging categories for '%s':\n" - " all - turn on all available logging categories\n" - " async - log asynchronous activity\n" - " break - log breakpoints\n" - " communication - log communication activity\n" - " default - enable the default set of logging categories for liblldb\n" - " packets - log gdb remote packets\n" - " memory - log memory reads and writes\n" - " data-short - log memory bytes for memory reads and writes for short " - "transactions only\n" - " data-long - log memory bytes for memory reads and writes for all " - "transactions\n" - " process - log process events and activities\n" - " thread - log thread events and activities\n" - " step - log step related activities\n" - " verbose - enable verbose logging\n" - " watch - log watchpoint related activities\n", - ProcessKDP::GetPluginNameStatic().GetCString()); -} +Log::Channel ProcessKDPLog::g_channel(g_categories, KDP_LOG_DEFAULT); -void ProcessKDPLog::LogIf(uint32_t mask, const char *format, ...) { - Log *log(ProcessKDPLog::GetLogIfAllCategoriesSet(mask)); - if (log) { - va_list args; - va_start(args, format); - log->VAPrintf(format, args); - va_end(args); - } -} +void ProcessKDPLog::Initialize() { Log::Register("kdp-remote", g_channel); } Modified: lldb/trunk/source/Plugins/Process/MacOSX-Kernel/ProcessKDPLog.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/MacOSX-Kernel/ProcessKDPLog.h?rev=295450&r1=295449&r2=295450&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Process/MacOSX-Kernel/ProcessKDPLog.h (original) +++ lldb/trunk/source/Plugins/Process/MacOSX-Kernel/ProcessKDPLog.h Fri Feb 17 09:08:08 2017 @@ -10,11 +10,6 @@ #ifndef liblldb_ProcessKDPLog_h_ #define liblldb_ProcessKDPLog_h_ -// C Includes -// C++ Includes -// Other libraries and framework includes - -// Project includes #include "lldb/Core/Log.h" #define KDP_LOG_PROCESS (1u << 1) @@ -32,21 +27,17 @@ #define KDP_LOG_ALL (UINT32_MAX) #define KDP_LOG_DEFAULT KDP_LOG_PACKETS +namespace lldb_private { class ProcessKDPLog { -public: - static lldb_private::Log *GetLogIfAllCategoriesSet(uint32_t mask = 0); - - static void DisableLog(const char **categories, - lldb_private::Stream *feedback_strm); + static Log::Channel g_channel; - static lldb_private::Log * - EnableLog(const std::shared_ptr<llvm::raw_ostream> &log_stream_sp, - uint32_t log_options, const char **categories, - lldb_private::Stream *feedback_strm); - - static void ListLogCategories(lldb_private::Stream *strm); +public: + static void Initialize(); - static void LogIf(uint32_t mask, const char *format, ...); + static Log *GetLogIfAllCategoriesSet(uint32_t mask) { + return g_channel.GetLogIfAll(mask); + } }; +} #endif // liblldb_ProcessKDPLog_h_ Modified: lldb/trunk/source/Plugins/Process/MacOSX-Kernel/ThreadKDP.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/MacOSX-Kernel/ThreadKDP.cpp?rev=295450&r1=295449&r2=295450&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Process/MacOSX-Kernel/ThreadKDP.cpp (original) +++ lldb/trunk/source/Plugins/Process/MacOSX-Kernel/ThreadKDP.cpp Fri Feb 17 09:08:08 2017 @@ -40,15 +40,13 @@ using namespace lldb_private; ThreadKDP::ThreadKDP(Process &process, lldb::tid_t tid) : Thread(process, tid), m_thread_name(), m_dispatch_queue_name(), m_thread_dispatch_qaddr(LLDB_INVALID_ADDRESS) { - ProcessKDPLog::LogIf(KDP_LOG_THREAD, - "%p: ThreadKDP::ThreadKDP (tid = 0x%4.4x)", this, - GetID()); + Log *log = ProcessKDPLog::GetLogIfAllCategoriesSet(KDP_LOG_THREAD); + LLDB_LOG(log, "this = {0}, tid = {1:x}", this, GetID()); } ThreadKDP::~ThreadKDP() { - ProcessKDPLog::LogIf(KDP_LOG_THREAD, - "%p: ThreadKDP::~ThreadKDP (tid = 0x%4.4x)", this, - GetID()); + Log *log = ProcessKDPLog::GetLogIfAllCategoriesSet(KDP_LOG_THREAD); + LLDB_LOG(log, "this = {0}, tid = {1:x}", this, GetID()); DestroyThread(); } _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits