2010-06-09 00:52:24 +08:00
|
|
|
//===-- lldb-log.cpp --------------------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "lldb/lldb-private-log.h"
|
|
|
|
|
|
|
|
// C Includes
|
|
|
|
// C++ Includes
|
|
|
|
// Other libraries and framework includes
|
|
|
|
// Project includes
|
2010-06-16 03:49:27 +08:00
|
|
|
#include "lldb/Interpreter/Args.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Core/Log.h"
|
|
|
|
#include "lldb/Core/StreamFile.h"
|
2010-06-10 12:51:35 +08:00
|
|
|
#include <string.h>
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
|
|
|
|
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 ()
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2013-03-28 07:08:40 +08:00
|
|
|
if (!g_log_enabled)
|
|
|
|
return NULL;
|
|
|
|
return g_log;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
lldb_private::GetLogMask ()
|
|
|
|
{
|
2013-03-28 07:08:40 +08:00
|
|
|
Log *log(GetLog ());
|
2010-06-09 00:52:24 +08:00
|
|
|
if (log)
|
2010-10-27 11:32:59 +08:00
|
|
|
return log->GetMask().Get();
|
2010-06-09 00:52:24 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
lldb_private::IsLogVerbose ()
|
|
|
|
{
|
|
|
|
uint32_t mask = GetLogMask();
|
|
|
|
return (mask & LIBLLDB_LOG_VERBOSE);
|
|
|
|
}
|
|
|
|
|
2013-03-28 07:08:40 +08:00
|
|
|
Log *
|
2010-06-09 00:52:24 +08:00
|
|
|
lldb_private::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;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
lldb_private::LogIfAllCategoriesSet (uint32_t mask, const char *format, ...)
|
|
|
|
{
|
2013-03-28 07:08:40 +08:00
|
|
|
Log *log(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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
lldb_private::LogIfAnyCategoriesSet (uint32_t mask, const char *format, ...)
|
|
|
|
{
|
2013-03-28 07:08:40 +08:00
|
|
|
Log *log(GetLogIfAnyCategoriesSet (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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-28 07:08:40 +08:00
|
|
|
Log *
|
2010-06-09 00:52:24 +08:00
|
|
|
lldb_private::GetLogIfAnyCategoriesSet (uint32_t mask)
|
|
|
|
{
|
2013-03-28 07:08:40 +08:00
|
|
|
Log *log(GetLog ());
|
2010-10-27 11:32:59 +08:00
|
|
|
if (log && mask && (mask & log->GetMask().Get()))
|
2010-06-09 00:52:24 +08:00
|
|
|
return log;
|
2013-03-28 07:08:40 +08:00
|
|
|
return NULL;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-02-21 10:23:08 +08:00
|
|
|
lldb_private::DisableLog (const char **categories, Stream *feedback_strm)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2013-03-28 07:08:40 +08:00
|
|
|
Log *log(GetLog ());
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2010-10-30 05:48:37 +08:00
|
|
|
if (log)
|
|
|
|
{
|
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 (0 == ::strcasecmp(arg, "all")) flag_bits &= ~LIBLLDB_LOG_ALL;
|
|
|
|
else if (0 == ::strcasecmp(arg, "api")) flag_bits &= ~LIBLLDB_LOG_API;
|
|
|
|
else if (0 == ::strncasecmp(arg, "break", 5)) flag_bits &= ~LIBLLDB_LOG_BREAKPOINTS;
|
|
|
|
else if (0 == ::strcasecmp(arg, "commands")) flag_bits &= ~LIBLLDB_LOG_COMMANDS;
|
|
|
|
else if (0 == ::strcasecmp(arg, "default")) flag_bits &= ~LIBLLDB_LOG_DEFAULT;
|
|
|
|
else if (0 == ::strcasecmp(arg, "dyld")) flag_bits &= ~LIBLLDB_LOG_DYNAMIC_LOADER;
|
|
|
|
else if (0 == ::strncasecmp(arg, "event", 5)) flag_bits &= ~LIBLLDB_LOG_EVENTS;
|
|
|
|
else if (0 == ::strncasecmp(arg, "expr", 4)) flag_bits &= ~LIBLLDB_LOG_EXPRESSIONS;
|
|
|
|
else if (0 == ::strncasecmp(arg, "object", 6)) flag_bits &= ~LIBLLDB_LOG_OBJECT;
|
|
|
|
else if (0 == ::strcasecmp(arg, "process")) flag_bits &= ~LIBLLDB_LOG_PROCESS;
|
2013-08-27 07:57:52 +08:00
|
|
|
else if (0 == ::strcasecmp(arg, "platform")) flag_bits &= ~LIBLLDB_LOG_PLATFORM;
|
2011-02-05 02:55:41 +08:00
|
|
|
else if (0 == ::strcasecmp(arg, "script")) flag_bits &= ~LIBLLDB_LOG_SCRIPT;
|
|
|
|
else if (0 == ::strcasecmp(arg, "state")) flag_bits &= ~LIBLLDB_LOG_STATE;
|
|
|
|
else if (0 == ::strcasecmp(arg, "step")) flag_bits &= ~LIBLLDB_LOG_STEP;
|
|
|
|
else if (0 == ::strcasecmp(arg, "thread")) flag_bits &= ~LIBLLDB_LOG_THREAD;
|
2012-12-05 08:25:49 +08:00
|
|
|
else if (0 == ::strcasecmp(arg, "target")) flag_bits &= ~LIBLLDB_LOG_TARGET;
|
2011-02-05 02:55:41 +08:00
|
|
|
else if (0 == ::strcasecmp(arg, "verbose")) flag_bits &= ~LIBLLDB_LOG_VERBOSE;
|
|
|
|
else if (0 == ::strncasecmp(arg, "watch", 5)) flag_bits &= ~LIBLLDB_LOG_WATCHPOINTS;
|
|
|
|
else if (0 == ::strncasecmp(arg, "temp", 4)) flag_bits &= ~LIBLLDB_LOG_TEMPORARY;
|
|
|
|
else if (0 == ::strncasecmp(arg, "comm", 4)) flag_bits &= ~LIBLLDB_LOG_COMMUNICATION;
|
|
|
|
else if (0 == ::strncasecmp(arg, "conn", 4)) flag_bits &= ~LIBLLDB_LOG_CONNECTION;
|
|
|
|
else if (0 == ::strncasecmp(arg, "host", 4)) flag_bits &= ~LIBLLDB_LOG_HOST;
|
|
|
|
else if (0 == ::strncasecmp(arg, "unwind", 6)) flag_bits &= ~LIBLLDB_LOG_UNWIND;
|
2011-07-23 01:03:19 +08:00
|
|
|
else if (0 == ::strncasecmp(arg, "types", 5)) flag_bits &= ~LIBLLDB_LOG_TYPES;
|
2011-09-30 07:41:34 +08:00
|
|
|
else if (0 == ::strncasecmp(arg, "symbol", 6)) flag_bits &= ~LIBLLDB_LOG_SYMBOLS;
|
2012-10-09 06:41:53 +08:00
|
|
|
else if (0 == ::strncasecmp(arg, "module", 6)) flag_bits &= ~LIBLLDB_LOG_MODULES;
|
2013-02-07 01:22:03 +08:00
|
|
|
else if (0 == ::strncasecmp(arg, "mmap", 4)) flag_bits &= ~LIBLLDB_LOG_MMAP;
|
2013-05-23 07:36:10 +08:00
|
|
|
else if (0 == ::strcasecmp(arg, "os")) flag_bits &= ~LIBLLDB_LOG_OS;
|
2010-11-19 07:32:35 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
feedback_strm->Printf ("error: unrecognized log category '%s'\n", arg);
|
|
|
|
ListLogCategories (feedback_strm);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-10-30 05:48:37 +08:00
|
|
|
}
|
|
|
|
}
|
2013-03-28 07:08:40 +08:00
|
|
|
log->GetMask().Reset (flag_bits);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2013-03-28 07:08:40 +08:00
|
|
|
Log *
|
2012-02-21 10:23:08 +08:00
|
|
|
lldb_private::EnableLog (StreamSP &log_stream_sp, uint32_t log_options, const char **categories, Stream *feedback_strm)
|
2010-06-09 00:52:24 +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.
|
|
|
|
uint32_t flag_bits;
|
2013-03-28 07:08:40 +08:00
|
|
|
if (g_log)
|
|
|
|
flag_bits = g_log->GetMask().Get();
|
2010-06-09 00:52:24 +08:00
|
|
|
else
|
|
|
|
flag_bits = 0;
|
|
|
|
|
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
|
|
|
{
|
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 (0 == ::strcasecmp(arg, "all")) flag_bits |= LIBLLDB_LOG_ALL;
|
|
|
|
else if (0 == ::strcasecmp(arg, "api")) flag_bits |= LIBLLDB_LOG_API;
|
|
|
|
else if (0 == ::strncasecmp(arg, "break", 5)) flag_bits |= LIBLLDB_LOG_BREAKPOINTS;
|
|
|
|
else if (0 == ::strcasecmp(arg, "commands")) flag_bits |= LIBLLDB_LOG_COMMANDS;
|
2013-09-12 09:48:59 +08:00
|
|
|
else if (0 == ::strncasecmp(arg, "commu", 5)) flag_bits |= LIBLLDB_LOG_COMMUNICATION;
|
|
|
|
else if (0 == ::strncasecmp(arg, "conn", 4)) flag_bits |= LIBLLDB_LOG_CONNECTION;
|
2011-02-05 02:55:41 +08:00
|
|
|
else if (0 == ::strcasecmp(arg, "default")) flag_bits |= LIBLLDB_LOG_DEFAULT;
|
|
|
|
else if (0 == ::strcasecmp(arg, "dyld")) flag_bits |= LIBLLDB_LOG_DYNAMIC_LOADER;
|
|
|
|
else if (0 == ::strncasecmp(arg, "event", 5)) flag_bits |= LIBLLDB_LOG_EVENTS;
|
|
|
|
else if (0 == ::strncasecmp(arg, "expr", 4)) flag_bits |= LIBLLDB_LOG_EXPRESSIONS;
|
2013-09-12 09:48:59 +08:00
|
|
|
else if (0 == ::strncasecmp(arg, "host", 4)) flag_bits |= LIBLLDB_LOG_HOST;
|
|
|
|
else if (0 == ::strncasecmp(arg, "mmap", 4)) flag_bits |= LIBLLDB_LOG_MMAP;
|
|
|
|
else if (0 == ::strncasecmp(arg, "module", 6)) flag_bits |= LIBLLDB_LOG_MODULES;
|
2011-02-05 02:55:41 +08:00
|
|
|
else if (0 == ::strncasecmp(arg, "object", 6)) flag_bits |= LIBLLDB_LOG_OBJECT;
|
2013-09-12 09:48:59 +08:00
|
|
|
else if (0 == ::strcasecmp(arg, "os")) flag_bits |= LIBLLDB_LOG_OS;
|
2013-08-27 07:57:52 +08:00
|
|
|
else if (0 == ::strcasecmp(arg, "platform")) flag_bits |= LIBLLDB_LOG_PLATFORM;
|
2013-09-12 09:48:59 +08:00
|
|
|
else if (0 == ::strcasecmp(arg, "process")) flag_bits |= LIBLLDB_LOG_PROCESS;
|
2011-02-05 02:55:41 +08:00
|
|
|
else if (0 == ::strcasecmp(arg, "script")) flag_bits |= LIBLLDB_LOG_SCRIPT;
|
|
|
|
else if (0 == ::strcasecmp(arg, "state")) flag_bits |= LIBLLDB_LOG_STATE;
|
|
|
|
else if (0 == ::strcasecmp(arg, "step")) flag_bits |= LIBLLDB_LOG_STEP;
|
2013-09-12 09:48:59 +08:00
|
|
|
else if (0 == ::strncasecmp(arg, "symbol", 6)) flag_bits |= LIBLLDB_LOG_SYMBOLS;
|
2012-12-05 08:25:49 +08:00
|
|
|
else if (0 == ::strcasecmp(arg, "target")) flag_bits |= LIBLLDB_LOG_TARGET;
|
2011-02-05 02:55:41 +08:00
|
|
|
else if (0 == ::strncasecmp(arg, "temp", 4)) flag_bits |= LIBLLDB_LOG_TEMPORARY;
|
2013-09-12 09:48:59 +08:00
|
|
|
else if (0 == ::strcasecmp(arg, "thread")) flag_bits |= LIBLLDB_LOG_THREAD;
|
2011-07-23 01:03:19 +08:00
|
|
|
else if (0 == ::strncasecmp(arg, "types", 5)) flag_bits |= LIBLLDB_LOG_TYPES;
|
2013-09-12 09:48:59 +08:00
|
|
|
else if (0 == ::strncasecmp(arg, "unwind", 6)) flag_bits |= LIBLLDB_LOG_UNWIND;
|
|
|
|
else if (0 == ::strcasecmp(arg, "verbose")) flag_bits |= LIBLLDB_LOG_VERBOSE;
|
|
|
|
else if (0 == ::strncasecmp(arg, "watch", 5)) flag_bits |= LIBLLDB_LOG_WATCHPOINTS;
|
2010-06-09 00:52:24 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
feedback_strm->Printf("error: unrecognized log category '%s'\n", arg);
|
2012-04-27 01:07:53 +08:00
|
|
|
ListLogCategories (feedback_strm);
|
2013-03-28 07:08:40 +08:00
|
|
|
return g_log;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
lldb_private::ListLogCategories (Stream *strm)
|
|
|
|
{
|
|
|
|
strm->Printf("Logging categories for 'lldb':\n"
|
2012-10-09 06:41:53 +08:00
|
|
|
" all - turn on all available logging categories\n"
|
|
|
|
" api - enable logging of API calls and return values\n"
|
|
|
|
" break - log breakpoints\n"
|
2013-04-27 01:44:41 +08:00
|
|
|
" commands - log command argument parsing\n"
|
2013-09-12 09:48:59 +08:00
|
|
|
" communication - log communication activities\n"
|
|
|
|
" connection - log connection details\n"
|
2012-10-09 06:41:53 +08:00
|
|
|
" default - enable the default set of logging categories for liblldb\n"
|
|
|
|
" dyld - log shared library related activities\n"
|
|
|
|
" events - log broadcaster, listener and event queue activities\n"
|
|
|
|
" expr - log expressions\n"
|
2013-09-12 09:48:59 +08:00
|
|
|
" host - log host activities\n"
|
|
|
|
" mmap - log mmap related activities\n"
|
2012-10-09 06:41:53 +08:00
|
|
|
" module - log module activities such as when modules are created, detroyed, replaced, and more\n"
|
2013-09-12 09:48:59 +08:00
|
|
|
" object - log object construction/destruction for important objects\n"
|
|
|
|
" os - log OperatingSystem plugin related activities\n"
|
2013-08-27 07:57:52 +08:00
|
|
|
" platform - log platform events and activities\n"
|
2013-09-12 09:48:59 +08:00
|
|
|
" process - log process events and activities\n"
|
2012-10-09 06:41:53 +08:00
|
|
|
" script - log events about the script interpreter\n"
|
|
|
|
" state - log private and public process state changes\n"
|
|
|
|
" step - log step related activities\n"
|
|
|
|
" symbol - log symbol related issues and warnings\n"
|
2012-12-05 08:25:49 +08:00
|
|
|
" target - log target events and activities\n"
|
2012-10-09 06:41:53 +08:00
|
|
|
" thread - log thread events and activities\n"
|
|
|
|
" types - log type system related activities\n"
|
|
|
|
" unwind - log stack unwind activities\n"
|
|
|
|
" verbose - enable verbose logging\n"
|
|
|
|
" watch - log watchpoint related activities\n");
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|