2010-06-09 00:52:24 +08:00
|
|
|
//===-- ProcessGDBRemoteLog.cpp ---------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "ProcessGDBRemoteLog.h"
|
|
|
|
|
2015-03-12 05:14:22 +08:00
|
|
|
#include <mutex>
|
|
|
|
|
2010-06-16 03:49:27 +08:00
|
|
|
#include "lldb/Interpreter/Args.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Core/StreamFile.h"
|
|
|
|
|
|
|
|
#include "ProcessGDBRemote.h"
|
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
2015-03-31 17:52:22 +08:00
|
|
|
using namespace lldb_private::process_gdb_remote;
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
|
2010-11-06 09:53:30 +08:00
|
|
|
// 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_lob_sp the first time this function is
|
|
|
|
// called.
|
2013-03-28 07:08:40 +08:00
|
|
|
static bool g_log_enabled = false;
|
|
|
|
static Log * g_log = NULL;
|
|
|
|
static Log *
|
2010-11-06 09:53:30 +08:00
|
|
|
GetLog ()
|
|
|
|
{
|
2013-03-28 07:08:40 +08:00
|
|
|
if (!g_log_enabled)
|
|
|
|
return NULL;
|
|
|
|
return g_log;
|
2010-11-06 09:53:30 +08:00
|
|
|
}
|
|
|
|
|
2015-03-12 05:14:22 +08:00
|
|
|
void
|
|
|
|
ProcessGDBRemoteLog::Initialize()
|
|
|
|
{
|
|
|
|
static ConstString g_name("gdb-remote");
|
|
|
|
static std::once_flag g_once_flag;
|
|
|
|
|
|
|
|
std::call_once(g_once_flag, [](){
|
|
|
|
Log::Callbacks log_callbacks = {
|
|
|
|
DisableLog,
|
|
|
|
EnableLog,
|
|
|
|
ListLogCategories
|
|
|
|
};
|
|
|
|
|
|
|
|
Log::RegisterLogChannel (g_name, log_callbacks);
|
|
|
|
});
|
|
|
|
}
|
2013-03-28 07:08:40 +08:00
|
|
|
|
|
|
|
Log *
|
2010-06-09 00:52:24 +08:00
|
|
|
ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (uint32_t mask)
|
|
|
|
{
|
2013-03-28 07:08:40 +08:00
|
|
|
Log *log(GetLog ());
|
2010-06-09 00:52:24 +08:00
|
|
|
if (log && mask)
|
|
|
|
{
|
2010-10-27 11:32:59 +08:00
|
|
|
uint32_t log_mask = log->GetMask().Get();
|
2010-06-09 00:52:24 +08:00
|
|
|
if ((log_mask & mask) != mask)
|
2013-03-28 07:08:40 +08:00
|
|
|
return NULL;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
return log;
|
|
|
|
}
|
|
|
|
|
2013-03-28 07:08:40 +08:00
|
|
|
Log *
|
2012-03-29 09:55:41 +08:00
|
|
|
ProcessGDBRemoteLog::GetLogIfAnyCategoryIsSet (uint32_t mask)
|
|
|
|
{
|
2013-03-28 07:08:40 +08:00
|
|
|
Log *log(GetLog ());
|
2012-03-29 09:55:41 +08:00
|
|
|
if (log && log->GetMask().Get() & mask)
|
|
|
|
return log;
|
2013-03-28 07:08:40 +08:00
|
|
|
return NULL;
|
2012-03-29 09:55:41 +08:00
|
|
|
}
|
|
|
|
|
2010-10-30 05:48:37 +08:00
|
|
|
void
|
2012-02-21 10:23:08 +08:00
|
|
|
ProcessGDBRemoteLog::DisableLog (const char **categories, Stream *feedback_strm)
|
2010-10-30 05:48:37 +08:00
|
|
|
{
|
2013-03-28 07:08:40 +08:00
|
|
|
Log *log (GetLog ());
|
2010-11-06 09:53:30 +08:00
|
|
|
if (log)
|
2010-10-30 05:48:37 +08:00
|
|
|
{
|
2010-11-19 07:32:35 +08:00
|
|
|
uint32_t flag_bits = 0;
|
|
|
|
|
2012-02-21 10:23:08 +08:00
|
|
|
if (categories[0] != NULL)
|
2010-10-30 05:48:37 +08:00
|
|
|
{
|
2010-11-19 07:32:35 +08:00
|
|
|
flag_bits = log->GetMask().Get();
|
2012-02-21 10:23:08 +08:00
|
|
|
for (size_t i = 0; categories[i] != NULL; ++i)
|
2010-10-30 05:48:37 +08:00
|
|
|
{
|
2012-02-21 10:23:08 +08:00
|
|
|
const char *arg = categories[i];
|
2010-11-19 07:32:35 +08:00
|
|
|
|
|
|
|
|
2011-02-05 02:55:41 +08:00
|
|
|
if (::strcasecmp (arg, "all") == 0 ) flag_bits &= ~GDBR_LOG_ALL;
|
|
|
|
else if (::strcasecmp (arg, "async") == 0 ) flag_bits &= ~GDBR_LOG_ASYNC;
|
|
|
|
else if (::strncasecmp (arg, "break", 5) == 0 ) flag_bits &= ~GDBR_LOG_BREAKPOINTS;
|
|
|
|
else if (::strncasecmp (arg, "comm", 4) == 0 ) flag_bits &= ~GDBR_LOG_COMM;
|
|
|
|
else if (::strcasecmp (arg, "default") == 0 ) flag_bits &= ~GDBR_LOG_DEFAULT;
|
|
|
|
else if (::strcasecmp (arg, "packets") == 0 ) flag_bits &= ~GDBR_LOG_PACKETS;
|
|
|
|
else if (::strcasecmp (arg, "memory") == 0 ) flag_bits &= ~GDBR_LOG_MEMORY;
|
|
|
|
else if (::strcasecmp (arg, "data-short") == 0 ) flag_bits &= ~GDBR_LOG_MEMORY_DATA_SHORT;
|
|
|
|
else if (::strcasecmp (arg, "data-long") == 0 ) flag_bits &= ~GDBR_LOG_MEMORY_DATA_LONG;
|
|
|
|
else if (::strcasecmp (arg, "process") == 0 ) flag_bits &= ~GDBR_LOG_PROCESS;
|
|
|
|
else if (::strcasecmp (arg, "step") == 0 ) flag_bits &= ~GDBR_LOG_STEP;
|
|
|
|
else if (::strcasecmp (arg, "thread") == 0 ) flag_bits &= ~GDBR_LOG_THREAD;
|
|
|
|
else if (::strcasecmp (arg, "verbose") == 0 ) flag_bits &= ~GDBR_LOG_VERBOSE;
|
|
|
|
else if (::strncasecmp (arg, "watch", 5) == 0 ) flag_bits &= ~GDBR_LOG_WATCHPOINTS;
|
2010-11-19 07:32:35 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
feedback_strm->Printf("error: unrecognized log category '%s'\n", arg);
|
|
|
|
ListLogCategories (feedback_strm);
|
|
|
|
}
|
|
|
|
|
2010-10-30 05:48:37 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flag_bits == 0)
|
2013-03-28 07:08:40 +08:00
|
|
|
g_log_enabled = false;
|
2010-10-30 05:48:37 +08:00
|
|
|
else
|
2010-11-06 09:53:30 +08:00
|
|
|
log->GetMask().Reset (flag_bits);
|
2010-10-30 05:48:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-03-28 07:08:40 +08:00
|
|
|
Log *
|
2012-02-21 10:23:08 +08:00
|
|
|
ProcessGDBRemoteLog::EnableLog (StreamSP &log_stream_sp, uint32_t log_options, const char **categories, Stream *feedback_strm)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2010-11-06 09:53:30 +08:00
|
|
|
// 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.
|
2011-01-26 07:55:37 +08:00
|
|
|
uint32_t flag_bits = 0;
|
2013-03-28 07:08:40 +08:00
|
|
|
if (g_log)
|
|
|
|
flag_bits = g_log->GetMask().Get();
|
2010-11-06 09:53:30 +08:00
|
|
|
|
|
|
|
// Now make a new log with this stream if one was provided
|
|
|
|
if (log_stream_sp)
|
|
|
|
{
|
2013-03-28 07:08:40 +08:00
|
|
|
if (g_log)
|
|
|
|
g_log->SetStream(log_stream_sp);
|
|
|
|
else
|
|
|
|
g_log = new Log(log_stream_sp);
|
2010-11-06 09:53:30 +08:00
|
|
|
}
|
|
|
|
|
2013-03-28 07:08:40 +08:00
|
|
|
if (g_log)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
bool got_unknown_category = false;
|
2012-02-21 10:23:08 +08:00
|
|
|
for (size_t i=0; categories[i] != NULL; ++i)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2012-02-21 10:23:08 +08:00
|
|
|
const char *arg = categories[i];
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2011-02-05 02:55:41 +08:00
|
|
|
if (::strcasecmp (arg, "all") == 0 ) flag_bits |= GDBR_LOG_ALL;
|
|
|
|
else if (::strcasecmp (arg, "async") == 0 ) flag_bits |= GDBR_LOG_ASYNC;
|
|
|
|
else if (::strncasecmp (arg, "break", 5) == 0 ) flag_bits |= GDBR_LOG_BREAKPOINTS;
|
|
|
|
else if (::strncasecmp (arg, "comm", 4) == 0 ) flag_bits |= GDBR_LOG_COMM;
|
|
|
|
else if (::strcasecmp (arg, "default") == 0 ) flag_bits |= GDBR_LOG_DEFAULT;
|
|
|
|
else if (::strcasecmp (arg, "packets") == 0 ) flag_bits |= GDBR_LOG_PACKETS;
|
|
|
|
else if (::strcasecmp (arg, "memory") == 0 ) flag_bits |= GDBR_LOG_MEMORY;
|
|
|
|
else if (::strcasecmp (arg, "data-short") == 0 ) flag_bits |= GDBR_LOG_MEMORY_DATA_SHORT;
|
|
|
|
else if (::strcasecmp (arg, "data-long") == 0 ) flag_bits |= GDBR_LOG_MEMORY_DATA_LONG;
|
|
|
|
else if (::strcasecmp (arg, "process") == 0 ) flag_bits |= GDBR_LOG_PROCESS;
|
|
|
|
else if (::strcasecmp (arg, "step") == 0 ) flag_bits |= GDBR_LOG_STEP;
|
|
|
|
else if (::strcasecmp (arg, "thread") == 0 ) flag_bits |= GDBR_LOG_THREAD;
|
|
|
|
else if (::strcasecmp (arg, "verbose") == 0 ) flag_bits |= GDBR_LOG_VERBOSE;
|
|
|
|
else if (::strncasecmp (arg, "watch", 5) == 0 ) flag_bits |= GDBR_LOG_WATCHPOINTS;
|
2010-06-09 00:52:24 +08:00
|
|
|
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 = GDBR_LOG_DEFAULT;
|
2013-03-28 07:08:40 +08:00
|
|
|
g_log->GetMask().Reset(flag_bits);
|
|
|
|
g_log->GetOptions().Reset(log_options);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2013-03-28 07:08:40 +08:00
|
|
|
g_log_enabled = true;
|
|
|
|
return g_log;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ProcessGDBRemoteLog::ListLogCategories (Stream *strm)
|
|
|
|
{
|
2011-09-12 12:05:41 +08:00
|
|
|
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"
|
2013-05-11 05:47:16 +08:00
|
|
|
" watch - log watchpoint related activities\n", ProcessGDBRemote::GetPluginNameStatic().GetCString());
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
ProcessGDBRemoteLog::LogIf (uint32_t mask, const char *format, ...)
|
|
|
|
{
|
2013-03-28 07:08:40 +08:00
|
|
|
Log *log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (mask));
|
2010-06-09 00:52:24 +08:00
|
|
|
if (log)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
va_start (args, format);
|
|
|
|
log->VAPrintf (format, args);
|
|
|
|
va_end (args);
|
|
|
|
}
|
|
|
|
}
|