2010-06-09 00:52:24 +08:00
|
|
|
//===-- LogChannelDWARF.cpp ------------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "LogChannelDWARF.h"
|
|
|
|
|
2010-06-16 03:49:27 +08:00
|
|
|
#include "lldb/Interpreter/Args.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Core/PluginManager.h"
|
|
|
|
#include "lldb/Core/StreamFile.h"
|
|
|
|
#include "SymbolFileDWARF.h"
|
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
|
|
|
|
2014-07-09 02:05:41 +08:00
|
|
|
// when the one and only logging channel is enabled, then this will be non NULL.
|
2010-06-09 00:52:24 +08:00
|
|
|
static LogChannelDWARF* g_log_channel = NULL;
|
|
|
|
|
|
|
|
LogChannelDWARF::LogChannelDWARF () :
|
|
|
|
LogChannel ()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
LogChannelDWARF::~LogChannelDWARF ()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
LogChannelDWARF::Initialize()
|
|
|
|
{
|
|
|
|
PluginManager::RegisterPlugin (GetPluginNameStatic(),
|
|
|
|
GetPluginDescriptionStatic(),
|
|
|
|
LogChannelDWARF::CreateInstance);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
LogChannelDWARF::Terminate()
|
|
|
|
{
|
|
|
|
PluginManager::UnregisterPlugin (LogChannelDWARF::CreateInstance);
|
|
|
|
}
|
|
|
|
|
|
|
|
LogChannel*
|
|
|
|
LogChannelDWARF::CreateInstance ()
|
|
|
|
{
|
|
|
|
return new LogChannelDWARF ();
|
|
|
|
}
|
|
|
|
|
2013-05-11 05:47:16 +08:00
|
|
|
lldb_private::ConstString
|
2010-06-09 00:52:24 +08:00
|
|
|
LogChannelDWARF::GetPluginNameStatic()
|
|
|
|
{
|
2011-04-14 06:47:15 +08:00
|
|
|
return SymbolFileDWARF::GetPluginNameStatic();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
|
|
|
LogChannelDWARF::GetPluginDescriptionStatic()
|
|
|
|
{
|
|
|
|
return "DWARF log channel for debugging plug-in issues.";
|
|
|
|
}
|
|
|
|
|
2013-05-11 05:47:16 +08:00
|
|
|
lldb_private::ConstString
|
2010-06-09 00:52:24 +08:00
|
|
|
LogChannelDWARF::GetPluginName()
|
|
|
|
{
|
|
|
|
return GetPluginNameStatic();
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
LogChannelDWARF::GetPluginVersion()
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2010-10-30 05:48:37 +08:00
|
|
|
LogChannelDWARF::Delete ()
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
g_log_channel = NULL;
|
|
|
|
}
|
|
|
|
|
2010-10-30 05:48:37 +08:00
|
|
|
|
|
|
|
void
|
2012-02-21 10:23:08 +08:00
|
|
|
LogChannelDWARF::Disable (const char **categories, Stream *feedback_strm)
|
2010-10-30 05:48:37 +08:00
|
|
|
{
|
2013-03-28 07:08:40 +08:00
|
|
|
if (m_log_ap.get() == NULL)
|
2010-12-15 07:43:15 +08:00
|
|
|
return;
|
|
|
|
|
2013-03-28 07:08:40 +08:00
|
|
|
uint32_t flag_bits = m_log_ap->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-10-30 05:48:37 +08:00
|
|
|
|
2012-03-31 07:50:54 +08:00
|
|
|
if (::strcasecmp (arg, "all") == 0) flag_bits &= ~DWARF_LOG_ALL;
|
|
|
|
else if (::strcasecmp (arg, "info") == 0) flag_bits &= ~DWARF_LOG_DEBUG_INFO;
|
|
|
|
else if (::strcasecmp (arg, "line") == 0) flag_bits &= ~DWARF_LOG_DEBUG_LINE;
|
|
|
|
else if (::strcasecmp (arg, "pubnames") == 0) flag_bits &= ~DWARF_LOG_DEBUG_PUBNAMES;
|
|
|
|
else if (::strcasecmp (arg, "pubtypes") == 0) flag_bits &= ~DWARF_LOG_DEBUG_PUBTYPES;
|
|
|
|
else if (::strcasecmp (arg, "aranges") == 0) flag_bits &= ~DWARF_LOG_DEBUG_ARANGES;
|
|
|
|
else if (::strcasecmp (arg, "lookups") == 0) flag_bits &= ~DWARF_LOG_LOOKUPS;
|
2012-04-13 08:10:03 +08:00
|
|
|
else if (::strcasecmp (arg, "map") == 0) flag_bits &= ~DWARF_LOG_DEBUG_MAP;
|
2012-03-31 07:50:54 +08:00
|
|
|
else if (::strcasecmp (arg, "default") == 0) flag_bits &= ~DWARF_LOG_DEFAULT;
|
2014-03-13 01:58:29 +08:00
|
|
|
else if (::strcasecmp (arg, "verbose") == 0) flag_bits &= ~DWARF_LOG_VERBOSE;
|
2012-03-31 07:50:54 +08:00
|
|
|
else if (::strncasecmp(arg, "comp", 4) == 0) flag_bits &= ~DWARF_LOG_TYPE_COMPLETION;
|
2010-10-30 05:48:37 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
feedback_strm->Printf("error: unrecognized log category '%s'\n", arg);
|
|
|
|
ListCategories (feedback_strm);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flag_bits == 0)
|
|
|
|
Delete ();
|
|
|
|
else
|
2013-03-28 07:08:40 +08:00
|
|
|
m_log_ap->GetMask().Reset (flag_bits);
|
2010-10-30 05:48:37 +08:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
bool
|
|
|
|
LogChannelDWARF::Enable
|
|
|
|
(
|
|
|
|
StreamSP &log_stream_sp,
|
|
|
|
uint32_t log_options,
|
|
|
|
Stream *feedback_strm, // Feedback stream for argument errors etc
|
2012-02-21 10:23:08 +08:00
|
|
|
const char **categories // The categories to enable within this logging stream, if empty, enable default set
|
2010-06-09 00:52:24 +08:00
|
|
|
)
|
|
|
|
{
|
2010-10-30 05:48:37 +08:00
|
|
|
Delete ();
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2013-03-28 07:08:40 +08:00
|
|
|
if (m_log_ap)
|
|
|
|
m_log_ap->SetStream(log_stream_sp);
|
|
|
|
else
|
|
|
|
m_log_ap.reset(new Log (log_stream_sp));
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
g_log_channel = this;
|
|
|
|
uint32_t flag_bits = 0;
|
|
|
|
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
|
|
|
|
2012-03-31 07:50:54 +08:00
|
|
|
if (::strcasecmp (arg, "all") == 0) flag_bits |= DWARF_LOG_ALL;
|
|
|
|
else if (::strcasecmp (arg, "info") == 0) flag_bits |= DWARF_LOG_DEBUG_INFO;
|
|
|
|
else if (::strcasecmp (arg, "line") == 0) flag_bits |= DWARF_LOG_DEBUG_LINE;
|
|
|
|
else if (::strcasecmp (arg, "pubnames") == 0) flag_bits |= DWARF_LOG_DEBUG_PUBNAMES;
|
|
|
|
else if (::strcasecmp (arg, "pubtypes") == 0) flag_bits |= DWARF_LOG_DEBUG_PUBTYPES;
|
|
|
|
else if (::strcasecmp (arg, "aranges") == 0) flag_bits |= DWARF_LOG_DEBUG_ARANGES;
|
|
|
|
else if (::strcasecmp (arg, "lookups") == 0) flag_bits |= DWARF_LOG_LOOKUPS;
|
2012-04-13 08:10:03 +08:00
|
|
|
else if (::strcasecmp (arg, "map") == 0) flag_bits |= DWARF_LOG_DEBUG_MAP;
|
2012-03-31 07:50:54 +08:00
|
|
|
else if (::strcasecmp (arg, "default") == 0) flag_bits |= DWARF_LOG_DEFAULT;
|
2014-03-13 01:58:29 +08:00
|
|
|
else if (::strcasecmp (arg, "verbose") == 0) flag_bits |= DWARF_LOG_VERBOSE;
|
2012-03-31 07:50:54 +08:00
|
|
|
else if (::strncasecmp(arg, "comp", 4) == 0) flag_bits |= DWARF_LOG_TYPE_COMPLETION;
|
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;
|
|
|
|
ListCategories (feedback_strm);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (flag_bits == 0)
|
|
|
|
flag_bits = DWARF_LOG_DEFAULT;
|
2013-03-28 07:08:40 +08:00
|
|
|
m_log_ap->GetMask().Reset(flag_bits);
|
|
|
|
m_log_ap->GetOptions().Reset(log_options);
|
|
|
|
return m_log_ap.get() != NULL;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
LogChannelDWARF::ListCategories (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"
|
2013-09-10 07:17:40 +08:00
|
|
|
" info - log the parsing of .debug_info\n"
|
|
|
|
" line - log the parsing of .debug_line\n"
|
|
|
|
" pubnames - log the parsing of .debug_pubnames\n"
|
|
|
|
" pubtypes - log the parsing of .debug_pubtypes\n"
|
|
|
|
" aranges - log the parsing of .debug_aranges\n"
|
2013-03-05 05:46:16 +08:00
|
|
|
" lookups - log any lookups that happen by name, regex, or address\n"
|
|
|
|
" completion - log struct/unions/class type completions\n"
|
|
|
|
" map - log insertions of object files into DWARF debug maps\n",
|
2013-05-11 05:47:16 +08:00
|
|
|
SymbolFileDWARF::GetPluginNameStatic().GetCString());
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2013-03-28 07:08:40 +08:00
|
|
|
Log *
|
2010-06-09 00:52:24 +08:00
|
|
|
LogChannelDWARF::GetLog ()
|
|
|
|
{
|
|
|
|
if (g_log_channel)
|
2013-03-28 07:08:40 +08:00
|
|
|
return g_log_channel->m_log_ap.get();
|
2011-10-06 08:09:08 +08:00
|
|
|
|
2013-03-28 07:08:40 +08:00
|
|
|
return NULL;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2013-03-28 07:08:40 +08:00
|
|
|
Log *
|
2010-06-09 00:52:24 +08:00
|
|
|
LogChannelDWARF::GetLogIfAll (uint32_t mask)
|
|
|
|
{
|
2013-03-28 07:08:40 +08:00
|
|
|
if (g_log_channel && g_log_channel->m_log_ap.get())
|
2010-10-27 11:32:59 +08:00
|
|
|
{
|
2013-03-28 07:08:40 +08:00
|
|
|
if (g_log_channel->m_log_ap->GetMask().AllSet(mask))
|
|
|
|
return g_log_channel->m_log_ap.get();
|
2010-10-27 11:32:59 +08:00
|
|
|
}
|
2013-03-28 07:08:40 +08:00
|
|
|
return NULL;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2013-03-28 07:08:40 +08:00
|
|
|
Log *
|
2012-01-06 08:17:16 +08:00
|
|
|
LogChannelDWARF::GetLogIfAny (uint32_t mask)
|
|
|
|
{
|
2013-03-28 07:08:40 +08:00
|
|
|
if (g_log_channel && g_log_channel->m_log_ap.get())
|
2012-01-06 08:17:16 +08:00
|
|
|
{
|
2013-03-28 07:08:40 +08:00
|
|
|
if (g_log_channel->m_log_ap->GetMask().AnySet(mask))
|
|
|
|
return g_log_channel->m_log_ap.get();
|
2012-01-06 08:17:16 +08:00
|
|
|
}
|
2013-03-28 07:08:40 +08:00
|
|
|
return NULL;
|
2012-01-06 08:17:16 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
void
|
|
|
|
LogChannelDWARF::LogIf (uint32_t mask, const char *format, ...)
|
|
|
|
{
|
|
|
|
if (g_log_channel)
|
|
|
|
{
|
2013-03-28 07:08:40 +08:00
|
|
|
Log *log = g_log_channel->m_log_ap.get();
|
|
|
|
if (log && log->GetMask().AnySet(mask))
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
va_start (args, format);
|
|
|
|
log->VAPrintf (format, args);
|
|
|
|
va_end (args);
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
}
|