diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2017-01-02 19:26:05 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2017-01-02 19:26:05 +0000 |
commit | 14f1b3e8826ce43b978db93a62d1166055db5394 (patch) | |
tree | 0a00ad8d3498783fe0193f3b656bca17c4c8697d /source/Plugins/Process/Windows/Common/ProcessWindowsLog.cpp | |
parent | 4ee8c119c71a06dcad1e0fecc8c675e480e59337 (diff) | |
download | src-vendor/lldb/lldb-trunk-r290819.tar.gz src-vendor/lldb/lldb-trunk-r290819.zip |
Vendor import of lldb trunk r290819:vendor/lldb/lldb-trunk-r290819
Diffstat (limited to 'source/Plugins/Process/Windows/Common/ProcessWindowsLog.cpp')
-rw-r--r-- | source/Plugins/Process/Windows/Common/ProcessWindowsLog.cpp | 260 |
1 files changed, 117 insertions, 143 deletions
diff --git a/source/Plugins/Process/Windows/Common/ProcessWindowsLog.cpp b/source/Plugins/Process/Windows/Common/ProcessWindowsLog.cpp index 47722c5146b2..242c1996bdd4 100644 --- a/source/Plugins/Process/Windows/Common/ProcessWindowsLog.cpp +++ b/source/Plugins/Process/Windows/Common/ProcessWindowsLog.cpp @@ -18,177 +18,151 @@ 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 = nullptr; +static Log *g_log = nullptr; static llvm::ManagedStatic<std::once_flag> g_once_flag; -void -ProcessWindowsLog::Initialize() -{ - static ConstString g_name("windows"); - - std::call_once(*g_once_flag, [](){ - Log::Callbacks log_callbacks = { - DisableLog, - EnableLog, - ListLogCategories - }; - - Log::RegisterLogChannel(g_name, log_callbacks); - RegisterPluginName(g_name); - }); -} +void ProcessWindowsLog::Initialize() { + static ConstString g_name("windows"); -void -ProcessWindowsLog::Terminate() -{ -} + std::call_once(*g_once_flag, []() { + Log::Callbacks log_callbacks = {DisableLog, EnableLog, ListLogCategories}; -Log * -ProcessWindowsLog::GetLog() -{ - return (g_log_enabled) ? g_log : nullptr; + Log::RegisterLogChannel(g_name, log_callbacks); + RegisterPluginName(g_name); + }); } -bool -ProcessWindowsLog::TestLogFlags(uint32_t mask, LogMaskReq req) -{ - Log *log = GetLog(); - if (!log) - return false; +void ProcessWindowsLog::Terminate() {} - uint32_t log_mask = log->GetMask().Get(); - if (req == LogMaskReq::All) - return ((log_mask & mask) == mask); - else - return (log_mask & mask); +Log *ProcessWindowsLog::GetLog() { 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, "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; +static uint32_t GetFlagBits(const char *arg) { + 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; } -void -ProcessWindowsLog::DisableLog(const char **args, Stream *feedback_strm) -{ - Log *log (GetLog()); - if (log) - { - uint32_t flag_bits = 0; - - if (args[0] != nullptr) - { - flag_bits = log->GetMask().Get(); - for (; args[0]; args++) - { - const char *arg = args[0]; - uint32_t bits = GetFlagBits(arg); - - if (bits) - { - flag_bits &= ~bits; - } - else - { - feedback_strm->Printf("error: unrecognized log category '%s'\n", arg); - ListLogCategories(feedback_strm); - } - } - } +void ProcessWindowsLog::DisableLog(const char **args, Stream *feedback_strm) { + Log *log(GetLog()); + if (log) { + uint32_t flag_bits = 0; - log->GetMask().Reset(flag_bits); - if (flag_bits == 0) - { - g_log_enabled = false; - log->SetStream(lldb::StreamSP()); + if (args[0] != nullptr) { + flag_bits = log->GetMask().Get(); + for (; args[0]; args++) { + const char *arg = args[0]; + uint32_t bits = GetFlagBits(arg); + + if (bits) { + flag_bits &= ~bits; + } else { + feedback_strm->Printf("error: unrecognized log category '%s'\n", arg); + ListLogCategories(feedback_strm); } + } } - return; -} - -Log * -ProcessWindowsLog::EnableLog(StreamSP &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. - 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); + log->GetMask().Reset(flag_bits); + if (flag_bits == 0) { + g_log_enabled = false; + log->SetStream(lldb::StreamSP()); } + } + return; +} + +Log *ProcessWindowsLog::EnableLog(StreamSP &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. + 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) - { - bool got_unknown_category = false; - for (; args[0]; args++) - { - const char *arg = args[0]; - uint32_t bits = GetFlagBits(arg); - - if (bits) - { - flag_bits |= bits; - } - else - { - feedback_strm->Printf("error: unrecognized log category '%s'\n", arg); - if (got_unknown_category == false) - { - got_unknown_category = true; - ListLogCategories (feedback_strm); - } - } + g_log->SetStream(log_stream_sp); + else + g_log = new Log(log_stream_sp); + } + + if (g_log) { + bool got_unknown_category = false; + for (; args[0]; args++) { + const char *arg = args[0]; + uint32_t bits = GetFlagBits(arg); + + if (bits) { + flag_bits |= bits; + } 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 = WINDOWS_LOG_ALL; - g_log->GetMask().Reset(flag_bits); - g_log->GetOptions().Reset(log_options); - g_log_enabled = true; + } } - return g_log; + if (flag_bits == 0) + flag_bits = WINDOWS_LOG_ALL; + g_log->GetMask().Reset(flag_bits); + g_log->GetOptions().Reset(log_options); + g_log_enabled = true; + } + return g_log; } -void -ProcessWindowsLog::ListLogCategories(Stream *strm) -{ - 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); +void ProcessWindowsLog::ListLogCategories(Stream *strm) { + 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); } const char *ProcessWindowsLog::m_pluginname = ""; |