1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
|
//===-- ProcessKDPLog.cpp ---------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "ProcessKDPLog.h"
#include "lldb/Interpreter/Args.h"
#include "lldb/Core/StreamFile.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 (::strcasecmp (arg, "verbose") == 0 ) flag_bits &= ~KDP_LOG_VERBOSE;
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 (StreamSP &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 (::strcasecmp (arg, "verbose") == 0 ) flag_bits |= KDP_LOG_VERBOSE;
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;
}
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());
}
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);
}
}
|