From 610e52912d31341d989ac21ff3d7380c513e0897 Mon Sep 17 00:00:00 2001 From: Zachary Turner Date: Thu, 7 May 2015 21:39:33 +0000 Subject: Add logging to ProcessWindows. llvm-svn: 236776 --- .../Plugins/Process/Windows/ProcessWindowsLog.cpp | 106 +++++++++------------ 1 file changed, 46 insertions(+), 60 deletions(-) (limited to 'lldb/source/Plugins/Process/Windows/ProcessWindowsLog.cpp') diff --git a/lldb/source/Plugins/Process/Windows/ProcessWindowsLog.cpp b/lldb/source/Plugins/Process/Windows/ProcessWindowsLog.cpp index ae03937fbd1..d641979b0b0 100644 --- a/lldb/source/Plugins/Process/Windows/ProcessWindowsLog.cpp +++ b/lldb/source/Plugins/Process/Windows/ProcessWindowsLog.cpp @@ -11,8 +11,8 @@ #include -#include "lldb/Interpreter/Args.h" #include "lldb/Core/StreamFile.h" +#include "lldb/Interpreter/Args.h" #include "llvm/Support/ManagedStatic.h" #include "ProcessWindows.h" @@ -26,14 +26,7 @@ using namespace lldb_private; // 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; -} +static Log * g_log = nullptr; static llvm::ManagedStatic g_once_flag; @@ -54,34 +47,44 @@ ProcessWindowsLog::Initialize() }); } +void +ProcessWindowsLog::Terminate() +{ +} + Log * -ProcessWindowsLog::GetLogIfAllCategoriesSet(uint32_t mask) +ProcessWindowsLog::GetLog() { - Log *log(GetLog()); - if (log && mask) - { - uint32_t log_mask = log->GetMask().Get(); - if ((log_mask & mask) != mask) - return NULL; - } - return log; + return (g_log_enabled) ? g_log : nullptr; +} + +bool +ProcessWindowsLog::TestLogFlags(uint32_t mask, LogMaskReq req) +{ + Log *log = GetLog(); + if (!log) + return false; + + uint32_t log_mask = log->GetMask().Get(); + if (req == LogMaskReq::All) + return ((log_mask & mask) == mask); + else + return (log_mask & mask); } static uint32_t GetFlagBits(const char *arg) { - if (::strcasecmp (arg, "all") == 0 ) return WINDOWS_LOG_ALL; - else if (::strcasecmp (arg, "async") == 0 ) return WINDOWS_LOG_ASYNC; - else if (::strncasecmp (arg, "break", 5) == 0 ) return WINDOWS_LOG_BREAKPOINTS; - else if (::strcasecmp (arg, "default") == 0 ) return WINDOWS_LOG_DEFAULT; - else if (::strcasecmp (arg, "memory") == 0 ) return WINDOWS_LOG_MEMORY; - else if (::strcasecmp (arg, "data-short") == 0 ) return WINDOWS_LOG_MEMORY_DATA_SHORT; - else if (::strcasecmp (arg, "data-long") == 0 ) return WINDOWS_LOG_MEMORY_DATA_LONG; - else if (::strcasecmp (arg, "process") == 0 ) return WINDOWS_LOG_PROCESS; - else if (::strcasecmp (arg, "registers") == 0 ) return WINDOWS_LOG_REGISTERS; - else if (::strcasecmp (arg, "step") == 0 ) return WINDOWS_LOG_STEP; - else if (::strcasecmp (arg, "thread") == 0 ) return WINDOWS_LOG_THREAD; - else if (::strcasecmp (arg, "verbose") == 0 ) return WINDOWS_LOG_VERBOSE; + if (::strcasecmp(arg, "all") == 0 ) return WINDOWS_LOG_ALL; + else if (::strcasecmp(arg, "break") == 0 ) return WINDOWS_LOG_BREAKPOINTS; + else if (::strcasecmp(arg, "event") == 0 ) return WINDOWS_LOG_EVENT; + else if (::strcasecmp(arg, "exception") == 0 ) return WINDOWS_LOG_EXCEPTION; + else if (::strcasecmp(arg, "memory") == 0 ) return WINDOWS_LOG_MEMORY; + else if (::strcasecmp(arg, "process") == 0 ) return WINDOWS_LOG_PROCESS; + else if (::strcasecmp(arg, "registers") == 0 ) return WINDOWS_LOG_REGISTERS; + else if (::strcasecmp(arg, "step") == 0 ) return WINDOWS_LOG_STEP; + else if (::strcasecmp(arg, "thread") == 0 ) return WINDOWS_LOG_THREAD; + else if (::strcasecmp(arg, "verbose") == 0 ) return WINDOWS_LOG_VERBOSE; return 0; } @@ -159,7 +162,7 @@ ProcessWindowsLog::EnableLog(StreamSP &log_stream_sp, uint32_t log_options, cons } } if (flag_bits == 0) - flag_bits = WINDOWS_LOG_DEFAULT; + flag_bits = WINDOWS_LOG_ALL; g_log->GetMask().Reset(flag_bits); g_log->GetOptions().Reset(log_options); g_log_enabled = true; @@ -170,35 +173,18 @@ ProcessWindowsLog::EnableLog(StreamSP &log_stream_sp, uint32_t log_options, cons void ProcessWindowsLog::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" - " default - enable the default set of logging categories for liblldb\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" - " registers - log register read/writes\n" - " thread - log thread events and activities\n" - " step - log step related activities\n" - " verbose - enable verbose logging\n", - ProcessWindowsLog::m_pluginname); -} - - -void -ProcessWindowsLog::LogIf(uint32_t mask, const char *format, ...) -{ - Log *log = GetLogIfAllCategoriesSet(mask); - if (log) - { - va_list args; - va_start(args, format); - log->VAPrintf(format, args); - va_end(args); - } + strm->Printf("Logging categories for '%s':\n" + " all - turn on all available logging categories\n" + " break - log breakpoints\n" + " event - log low level debugger events\n" + " exception - log exception information\n" + " memory - log memory reads and writes\n" + " process - log process events and activities\n" + " registers - log register read/writes\n" + " thread - log thread events and activities\n" + " step - log step related activities\n" + " verbose - enable verbose logging\n", + ProcessWindowsLog::m_pluginname); } -int ProcessWindowsLog::m_nestinglevel = 0; const char *ProcessWindowsLog::m_pluginname = ""; -- cgit v1.2.3