[Lldb-commits] [lldb] r141712 - in /lldb/trunk/source/Plugins/Process/Linux: ProcessLinux.cpp ProcessLinuxLog.cpp ProcessLinuxLog.h
Johnny Chen
johnny.chen at apple.com
Tue Oct 11 14:21:57 PDT 2011
Author: johnny
Date: Tue Oct 11 16:21:57 2011
New Revision: 141712
URL: http://llvm.org/viewvc/llvm-project?rev=141712&view=rev
Log:
Patch by Dawn to add the logging capabilities to ProcessLinux.cpp.
Added:
lldb/trunk/source/Plugins/Process/Linux/ProcessLinuxLog.cpp
lldb/trunk/source/Plugins/Process/Linux/ProcessLinuxLog.h
Modified:
lldb/trunk/source/Plugins/Process/Linux/ProcessLinux.cpp
Modified: lldb/trunk/source/Plugins/Process/Linux/ProcessLinux.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Linux/ProcessLinux.cpp?rev=141712&r1=141711&r2=141712&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Linux/ProcessLinux.cpp (original)
+++ lldb/trunk/source/Plugins/Process/Linux/ProcessLinux.cpp Tue Oct 11 16:21:57 2011
@@ -20,6 +20,7 @@
#include "lldb/Target/Target.h"
#include "ProcessLinux.h"
+#include "ProcessLinuxLog.h"
#include "Plugins/Process/Utility/InferiorCallPOSIX.h"
#include "ProcessMonitor.h"
#include "LinuxThread.h"
@@ -43,10 +44,18 @@
if (!g_initialized)
{
+ g_initialized = true;
PluginManager::RegisterPlugin(GetPluginNameStatic(),
GetPluginDescriptionStatic(),
CreateInstance);
- g_initialized = true;
+
+ Log::Callbacks log_callbacks = {
+ ProcessLinuxLog::DisableLog,
+ ProcessLinuxLog::EnableLog,
+ ProcessLinuxLog::ListLogCategories
+ };
+
+ Log::RegisterLogChannel (ProcessLinux::GetPluginNameStatic(), log_callbacks);
}
}
@@ -108,6 +117,10 @@
Error error;
assert(m_monitor == NULL);
+ LogSP log (ProcessLinuxLog::GetLogIfAllCategoriesSet (LINUX_LOG_PROCESS));
+ if (log && log->GetMask().Test(LINUX_LOG_VERBOSE))
+ log->Printf ("ProcessLinux::%s (pid = %i)", __FUNCTION__, GetID());
+
m_monitor = new ProcessMonitor(this, pid, error);
if (!error.Success())
@@ -441,6 +454,10 @@
ProcessLinux::UpdateThreadList(ThreadList &old_thread_list, ThreadList &new_thread_list)
{
// FIXME: Should this be implemented?
+ LogSP log (ProcessLinuxLog::GetLogIfAllCategoriesSet (LINUX_LOG_THREAD));
+ if (log && log->GetMask().Test(LINUX_LOG_VERBOSE))
+ log->Printf ("ProcessLinux::%s (pid = %i)", __FUNCTION__, GetID());
+
return 0;
}
Added: lldb/trunk/source/Plugins/Process/Linux/ProcessLinuxLog.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Linux/ProcessLinuxLog.cpp?rev=141712&view=auto
==============================================================================
--- lldb/trunk/source/Plugins/Process/Linux/ProcessLinuxLog.cpp (added)
+++ lldb/trunk/source/Plugins/Process/Linux/ProcessLinuxLog.cpp Tue Oct 11 16:21:57 2011
@@ -0,0 +1,183 @@
+//===-- ProcessLinuxLog.cpp ---------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "ProcessLinuxLog.h"
+
+#include "lldb/Interpreter/Args.h"
+#include "lldb/Core/StreamFile.h"
+
+#include "ProcessLinux.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_lob_sp the first time this function is
+// called.
+static LogSP &
+GetLog ()
+{
+ static LogSP g_log_sp;
+ return g_log_sp;
+}
+
+LogSP
+ProcessLinuxLog::GetLogIfAllCategoriesSet (uint32_t mask)
+{
+ LogSP log(GetLog ());
+ if (log && mask)
+ {
+ uint32_t log_mask = log->GetMask().Get();
+ if ((log_mask & mask) != mask)
+ return LogSP();
+ }
+ return log;
+}
+
+void
+ProcessLinuxLog::DisableLog (Args &args, Stream *feedback_strm)
+{
+ LogSP log (GetLog ());
+ if (log)
+ {
+ uint32_t flag_bits = 0;
+
+ const size_t argc = args.GetArgumentCount ();
+ if (argc > 0)
+ {
+ flag_bits = log->GetMask().Get();
+ for (size_t i = 0; i < argc; ++i)
+ {
+ const char *arg = args.GetArgumentAtIndex (i);
+
+
+ if (::strcasecmp (arg, "all") == 0 ) flag_bits &= ~LINUX_LOG_ALL;
+ else if (::strcasecmp (arg, "async") == 0 ) flag_bits &= ~LINUX_LOG_ASYNC;
+ else if (::strncasecmp (arg, "break", 5) == 0 ) flag_bits &= ~LINUX_LOG_BREAKPOINTS;
+ else if (::strncasecmp (arg, "comm", 4) == 0 ) flag_bits &= ~LINUX_LOG_COMM;
+ else if (::strcasecmp (arg, "default") == 0 ) flag_bits &= ~LINUX_LOG_DEFAULT;
+ else if (::strcasecmp (arg, "packets") == 0 ) flag_bits &= ~LINUX_LOG_PACKETS;
+ else if (::strcasecmp (arg, "memory") == 0 ) flag_bits &= ~LINUX_LOG_MEMORY;
+ else if (::strcasecmp (arg, "data-short") == 0 ) flag_bits &= ~LINUX_LOG_MEMORY_DATA_SHORT;
+ else if (::strcasecmp (arg, "data-long") == 0 ) flag_bits &= ~LINUX_LOG_MEMORY_DATA_LONG;
+ else if (::strcasecmp (arg, "process") == 0 ) flag_bits &= ~LINUX_LOG_PROCESS;
+ else if (::strcasecmp (arg, "step") == 0 ) flag_bits &= ~LINUX_LOG_STEP;
+ else if (::strcasecmp (arg, "thread") == 0 ) flag_bits &= ~LINUX_LOG_THREAD;
+ else if (::strcasecmp (arg, "verbose") == 0 ) flag_bits &= ~LINUX_LOG_VERBOSE;
+ else if (::strncasecmp (arg, "watch", 5) == 0 ) flag_bits &= ~LINUX_LOG_WATCHPOINTS;
+ else
+ {
+ feedback_strm->Printf("error: unrecognized log category '%s'\n", arg);
+ ListLogCategories (feedback_strm);
+ }
+
+ }
+ }
+
+ if (flag_bits == 0)
+ GetLog ().reset();
+ else
+ log->GetMask().Reset (flag_bits);
+ }
+
+ return;
+}
+
+LogSP
+ProcessLinuxLog::EnableLog (StreamSP &log_stream_sp, uint32_t log_options, Args &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;
+ LogSP log(GetLog ());
+ if (log)
+ flag_bits = log->GetMask().Get();
+
+ // Now make a new log with this stream if one was provided
+ if (log_stream_sp)
+ {
+ log = make_shared<Log>(log_stream_sp);
+ GetLog () = log;
+ }
+
+ if (log)
+ {
+ bool got_unknown_category = false;
+ const size_t argc = args.GetArgumentCount();
+ for (size_t i=0; i<argc; ++i)
+ {
+ const char *arg = args.GetArgumentAtIndex(i);
+
+ if (::strcasecmp (arg, "all") == 0 ) flag_bits |= LINUX_LOG_ALL;
+ else if (::strcasecmp (arg, "async") == 0 ) flag_bits |= LINUX_LOG_ASYNC;
+ else if (::strncasecmp (arg, "break", 5) == 0 ) flag_bits |= LINUX_LOG_BREAKPOINTS;
+ else if (::strncasecmp (arg, "comm", 4) == 0 ) flag_bits |= LINUX_LOG_COMM;
+ else if (::strcasecmp (arg, "default") == 0 ) flag_bits |= LINUX_LOG_DEFAULT;
+ else if (::strcasecmp (arg, "packets") == 0 ) flag_bits |= LINUX_LOG_PACKETS;
+ else if (::strcasecmp (arg, "memory") == 0 ) flag_bits |= LINUX_LOG_MEMORY;
+ else if (::strcasecmp (arg, "data-short") == 0 ) flag_bits |= LINUX_LOG_MEMORY_DATA_SHORT;
+ else if (::strcasecmp (arg, "data-long") == 0 ) flag_bits |= LINUX_LOG_MEMORY_DATA_LONG;
+ else if (::strcasecmp (arg, "process") == 0 ) flag_bits |= LINUX_LOG_PROCESS;
+ else if (::strcasecmp (arg, "step") == 0 ) flag_bits |= LINUX_LOG_STEP;
+ else if (::strcasecmp (arg, "thread") == 0 ) flag_bits |= LINUX_LOG_THREAD;
+ else if (::strcasecmp (arg, "verbose") == 0 ) flag_bits |= LINUX_LOG_VERBOSE;
+ else if (::strncasecmp (arg, "watch", 5) == 0 ) flag_bits |= LINUX_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 = LINUX_LOG_DEFAULT;
+ log->GetMask().Reset(flag_bits);
+ log->GetOptions().Reset(log_options);
+ }
+ return log;
+}
+
+void
+ProcessLinuxLog::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", ProcessLinux::GetPluginNameStatic());
+}
+
+
+void
+ProcessLinuxLog::LogIf (uint32_t mask, const char *format, ...)
+{
+ LogSP log (ProcessLinuxLog::GetLogIfAllCategoriesSet (mask));
+ if (log)
+ {
+ va_list args;
+ va_start (args, format);
+ log->VAPrintf (format, args);
+ va_end (args);
+ }
+}
Added: lldb/trunk/source/Plugins/Process/Linux/ProcessLinuxLog.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Linux/ProcessLinuxLog.h?rev=141712&view=auto
==============================================================================
--- lldb/trunk/source/Plugins/Process/Linux/ProcessLinuxLog.h (added)
+++ lldb/trunk/source/Plugins/Process/Linux/ProcessLinuxLog.h Tue Oct 11 16:21:57 2011
@@ -0,0 +1,54 @@
+//===-- ProcessLinuxLog.h -----------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef liblldb_ProcessLinuxLog_h_
+#define liblldb_ProcessLinuxLog_h_
+
+// C Includes
+// C++ Includes
+// Other libraries and framework includes
+
+// Project includes
+#include "lldb/Core/Log.h"
+
+#define LINUX_LOG_VERBOSE (1u << 0)
+#define LINUX_LOG_PROCESS (1u << 1)
+#define LINUX_LOG_THREAD (1u << 2)
+#define LINUX_LOG_PACKETS (1u << 3)
+#define LINUX_LOG_MEMORY (1u << 4) // Log memory reads/writes calls
+#define LINUX_LOG_MEMORY_DATA_SHORT (1u << 5) // Log short memory reads/writes bytes
+#define LINUX_LOG_MEMORY_DATA_LONG (1u << 6) // Log all memory reads/writes bytes
+#define LINUX_LOG_BREAKPOINTS (1u << 7)
+#define LINUX_LOG_WATCHPOINTS (1u << 8)
+#define LINUX_LOG_STEP (1u << 9)
+#define LINUX_LOG_COMM (1u << 10)
+#define LINUX_LOG_ASYNC (1u << 11)
+#define LINUX_LOG_ALL (UINT32_MAX)
+#define LINUX_LOG_DEFAULT LINUX_LOG_PACKETS
+
+class ProcessLinuxLog
+{
+public:
+ static lldb::LogSP
+ GetLogIfAllCategoriesSet(uint32_t mask = 0);
+
+ static void
+ DisableLog (lldb_private::Args &args, lldb_private::Stream *feedback_strm);
+
+ static lldb::LogSP
+ EnableLog (lldb::StreamSP &log_stream_sp, uint32_t log_options, lldb_private::Args &args, lldb_private::Stream *feedback_strm);
+
+ static void
+ ListLogCategories (lldb_private::Stream *strm);
+
+ static void
+ LogIf (uint32_t mask, const char *format, ...);
+};
+
+#endif // liblldb_ProcessLinuxLog_h_
More information about the lldb-commits
mailing list