Switch "posix" to the new log channel registration mechanism
Summary: This also removes magic rename code, which caused the channel to be called "linux" when built on a linux machine, and "freebsd" when built on a freebsd one, which seems unnecessary - registering a new channel is sufficiently simple now that if we wish to log something extremely os-specific, we can just create a new channel. None of the current categories seem very specific to one OS or another. Reviewers: emaste, krytarowski Subscribers: lldb-commits Differential Revision: https://reviews.llvm.org/D30250 llvm-svn: 295954
This commit is contained in:
parent
d8d32bb3d1
commit
c29f7ff334
|
@ -18,6 +18,7 @@ from lldbsuite.test import lldbutil
|
|||
class RegisterCommandsTestCase(TestBase):
|
||||
|
||||
mydir = TestBase.compute_mydir(__file__)
|
||||
NO_DEBUG_INFO_TESTCASE = True
|
||||
|
||||
def setUp(self):
|
||||
TestBase.setUp(self)
|
||||
|
@ -139,17 +140,10 @@ class RegisterCommandsTestCase(TestBase):
|
|||
# This intentionally checks the host platform rather than the target
|
||||
# platform as logging is host side.
|
||||
self.platform = ""
|
||||
if sys.platform.startswith("darwin"):
|
||||
self.platform = "" # TODO: add support for "log enable darwin registers"
|
||||
|
||||
if sys.platform.startswith("freebsd"):
|
||||
self.platform = "freebsd"
|
||||
|
||||
if sys.platform.startswith("linux"):
|
||||
self.platform = "linux"
|
||||
|
||||
if sys.platform.startswith("netbsd"):
|
||||
self.platform = "netbsd"
|
||||
if (sys.platform.startswith("freebsd") or
|
||||
sys.platform.startswith("linux") or
|
||||
sys.platform.startswith("netbsd")):
|
||||
self.platform = "posix"
|
||||
|
||||
if self.platform != "":
|
||||
self.log_file = os.path.join(os.getcwd(), 'TestRegisters.log')
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
#include "Plugins/ObjectFile/Mach-O/ObjectFileMachO.h"
|
||||
#endif
|
||||
|
||||
#if defined(__linux__)
|
||||
#if defined(__linux__) || defined(__FreeBSD__)
|
||||
#include "Plugins/Process/POSIX/ProcessPOSIXLog.h"
|
||||
#endif
|
||||
|
||||
|
@ -93,9 +93,8 @@ void SystemInitializerCommon::Initialize() {
|
|||
#if defined(__APPLE__)
|
||||
ObjectFileMachO::Initialize();
|
||||
#endif
|
||||
#if defined(__linux__)
|
||||
static ConstString g_linux_log_name("linux");
|
||||
ProcessPOSIXLog::Initialize(g_linux_log_name);
|
||||
#if defined(__linux__) || defined(__FreeBSD__)
|
||||
ProcessPOSIXLog::Initialize();
|
||||
#endif
|
||||
#if defined(_MSC_VER)
|
||||
ProcessWindowsLog::Initialize();
|
||||
|
|
|
@ -78,7 +78,6 @@ void ProcessFreeBSD::Initialize() {
|
|||
llvm::call_once(g_once_flag, []() {
|
||||
PluginManager::RegisterPlugin(GetPluginNameStatic(),
|
||||
GetPluginDescriptionStatic(), CreateInstance);
|
||||
ProcessPOSIXLog::Initialize(GetPluginNameStatic());
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -10,178 +10,24 @@
|
|||
|
||||
#include "ProcessPOSIXLog.h"
|
||||
|
||||
#include <mutex>
|
||||
|
||||
#include "lldb/Core/StreamFile.h"
|
||||
#include "lldb/Interpreter/Args.h"
|
||||
|
||||
#include "llvm/Support/Threading.h"
|
||||
|
||||
#include "ProcessPOSIXLog.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;
|
||||
}
|
||||
static constexpr Log::Category g_categories[] = {
|
||||
{{"break"}, {"log breakpoints"}, POSIX_LOG_BREAKPOINTS},
|
||||
{{"memory"}, {"log memory reads and writes"}, POSIX_LOG_MEMORY},
|
||||
{{"process"}, {"log process events and activities"}, POSIX_LOG_PROCESS},
|
||||
{{"ptrace"}, {"log all calls to ptrace"}, POSIX_LOG_PTRACE},
|
||||
{{"registers"}, {"log register read/writes"}, POSIX_LOG_REGISTERS},
|
||||
{{"thread"}, {"log thread events and activities"}, POSIX_LOG_THREAD},
|
||||
{{"watch"}, {"log watchpoint related activities"}, POSIX_LOG_WATCHPOINTS},
|
||||
};
|
||||
|
||||
void ProcessPOSIXLog::Initialize(ConstString name) {
|
||||
Log::Channel ProcessPOSIXLog::g_channel(g_categories, POSIX_LOG_DEFAULT);
|
||||
|
||||
void ProcessPOSIXLog::Initialize() {
|
||||
static llvm::once_flag g_once_flag;
|
||||
|
||||
llvm::call_once(g_once_flag, [name]() {
|
||||
Log::Callbacks log_callbacks = {DisableLog, EnableLog, ListLogCategories};
|
||||
|
||||
Log::RegisterLogChannel(name, log_callbacks);
|
||||
RegisterPluginName(name);
|
||||
});
|
||||
llvm::call_once(g_once_flag, []() { Log::Register("posix", g_channel); });
|
||||
}
|
||||
|
||||
Log *ProcessPOSIXLog::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;
|
||||
}
|
||||
|
||||
static uint32_t GetFlagBits(const char *arg) {
|
||||
if (::strcasecmp(arg, "all") == 0)
|
||||
return POSIX_LOG_ALL;
|
||||
else if (::strcasecmp(arg, "async") == 0)
|
||||
return POSIX_LOG_ASYNC;
|
||||
else if (::strncasecmp(arg, "break", 5) == 0)
|
||||
return POSIX_LOG_BREAKPOINTS;
|
||||
else if (::strncasecmp(arg, "comm", 4) == 0)
|
||||
return POSIX_LOG_COMM;
|
||||
else if (::strcasecmp(arg, "default") == 0)
|
||||
return POSIX_LOG_DEFAULT;
|
||||
else if (::strcasecmp(arg, "packets") == 0)
|
||||
return POSIX_LOG_PACKETS;
|
||||
else if (::strcasecmp(arg, "memory") == 0)
|
||||
return POSIX_LOG_MEMORY;
|
||||
else if (::strcasecmp(arg, "data-short") == 0)
|
||||
return POSIX_LOG_MEMORY_DATA_SHORT;
|
||||
else if (::strcasecmp(arg, "data-long") == 0)
|
||||
return POSIX_LOG_MEMORY_DATA_LONG;
|
||||
else if (::strcasecmp(arg, "process") == 0)
|
||||
return POSIX_LOG_PROCESS;
|
||||
else if (::strcasecmp(arg, "ptrace") == 0)
|
||||
return POSIX_LOG_PTRACE;
|
||||
else if (::strcasecmp(arg, "registers") == 0)
|
||||
return POSIX_LOG_REGISTERS;
|
||||
else if (::strcasecmp(arg, "step") == 0)
|
||||
return POSIX_LOG_STEP;
|
||||
else if (::strcasecmp(arg, "thread") == 0)
|
||||
return POSIX_LOG_THREAD;
|
||||
else if (::strncasecmp(arg, "watch", 5) == 0)
|
||||
return POSIX_LOG_WATCHPOINTS;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ProcessPOSIXLog::DisableLog(const char **args, Stream *feedback_strm) {
|
||||
Log *log(GetLog());
|
||||
if (log) {
|
||||
uint32_t flag_bits = 0;
|
||||
|
||||
flag_bits = log->GetMask().Get();
|
||||
for (; args && 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);
|
||||
}
|
||||
}
|
||||
|
||||
log->GetMask().Reset(flag_bits);
|
||||
if (flag_bits == 0)
|
||||
g_log_enabled = false;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Log *ProcessPOSIXLog::EnableLog(
|
||||
const std::shared_ptr<llvm::raw_ostream> &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);
|
||||
}
|
||||
|
||||
if (g_log) {
|
||||
bool got_unknown_category = false;
|
||||
for (; args && 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 = POSIX_LOG_DEFAULT;
|
||||
g_log->GetMask().Reset(flag_bits);
|
||||
g_log->GetOptions().Reset(log_options);
|
||||
g_log_enabled = true;
|
||||
}
|
||||
return g_log;
|
||||
}
|
||||
|
||||
void ProcessPOSIXLog::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"
|
||||
#ifndef LLDB_CONFIGURATION_BUILDANDINTEGRATION
|
||||
" ptrace - log all calls to ptrace\n"
|
||||
#endif
|
||||
" registers - log register read/writes\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",
|
||||
ProcessPOSIXLog::m_pluginname);
|
||||
}
|
||||
|
||||
const char *ProcessPOSIXLog::m_pluginname = "";
|
||||
|
|
|
@ -20,53 +20,25 @@
|
|||
|
||||
#define POSIX_LOG_PROCESS (1u << 1)
|
||||
#define POSIX_LOG_THREAD (1u << 2)
|
||||
#define POSIX_LOG_PACKETS (1u << 3)
|
||||
#define POSIX_LOG_MEMORY (1u << 4) // Log memory reads/writes calls
|
||||
#define POSIX_LOG_MEMORY_DATA_SHORT \
|
||||
(1u << 5) // Log short memory reads/writes bytes
|
||||
#define POSIX_LOG_MEMORY_DATA_LONG \
|
||||
(1u << 6) // Log all memory reads/writes bytes
|
||||
#define POSIX_LOG_PTRACE (1u << 5)
|
||||
#define POSIX_LOG_REGISTERS (1u << 6)
|
||||
#define POSIX_LOG_BREAKPOINTS (1u << 7)
|
||||
#define POSIX_LOG_WATCHPOINTS (1u << 8)
|
||||
#define POSIX_LOG_STEP (1u << 9)
|
||||
#define POSIX_LOG_COMM (1u << 10)
|
||||
#define POSIX_LOG_ASYNC (1u << 11)
|
||||
#define POSIX_LOG_PTRACE (1u << 12)
|
||||
#define POSIX_LOG_REGISTERS (1u << 13)
|
||||
#define POSIX_LOG_ALL (UINT32_MAX)
|
||||
#define POSIX_LOG_DEFAULT POSIX_LOG_PACKETS
|
||||
|
||||
// The size which determines "short memory reads/writes".
|
||||
#define POSIX_LOG_MEMORY_SHORT_BYTES (4 * sizeof(ptrdiff_t))
|
||||
#define POSIX_LOG_DEFAULT POSIX_LOG_PROCESS
|
||||
|
||||
namespace lldb_private {
|
||||
class ProcessPOSIXLog {
|
||||
static const char *m_pluginname;
|
||||
static Log::Channel g_channel;
|
||||
|
||||
public:
|
||||
// ---------------------------------------------------------------------
|
||||
// Public Static Methods
|
||||
// ---------------------------------------------------------------------
|
||||
static void Initialize(lldb_private::ConstString name);
|
||||
static void Initialize();
|
||||
|
||||
static void RegisterPluginName(const char *pluginName) {
|
||||
m_pluginname = pluginName;
|
||||
static Log *GetLogIfAllCategoriesSet(uint32_t mask) {
|
||||
return g_channel.GetLogIfAll(mask);
|
||||
}
|
||||
|
||||
static void RegisterPluginName(lldb_private::ConstString pluginName) {
|
||||
m_pluginname = pluginName.GetCString();
|
||||
}
|
||||
|
||||
static lldb_private::Log *GetLogIfAllCategoriesSet(uint32_t mask = 0);
|
||||
|
||||
static void DisableLog(const char **args,
|
||||
lldb_private::Stream *feedback_strm);
|
||||
|
||||
static lldb_private::Log *
|
||||
EnableLog(const std::shared_ptr<llvm::raw_ostream> &log_stream_sp,
|
||||
uint32_t log_options, const char **args,
|
||||
lldb_private::Stream *feedback_strm);
|
||||
|
||||
static void ListLogCategories(lldb_private::Stream *strm);
|
||||
};
|
||||
}
|
||||
|
||||
#endif // liblldb_ProcessPOSIXLog_h_
|
||||
|
|
Loading…
Reference in New Issue