From 30fdc8d841c9d24ac5f3d452b6ece84ee0ac991c Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Tue, 8 Jun 2010 16:52:24 +0000 Subject: Initial checkin of lldb code from internal Apple repo. llvm-svn: 105619 --- .../Process/gdb-remote/ProcessGDBRemoteLog.cpp | 121 +++++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemoteLog.cpp (limited to 'lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemoteLog.cpp') diff --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemoteLog.cpp b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemoteLog.cpp new file mode 100644 index 0000000..051ce8f --- /dev/null +++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemoteLog.cpp @@ -0,0 +1,121 @@ +//===-- 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" + +#include "lldb/Core/Args.h" +#include "lldb/Core/StreamFile.h" + +#include "ProcessGDBRemote.h" + +using namespace lldb; +using namespace lldb_private; + + +static Log* g_log = NULL; // Leak for now as auto_ptr was being cleaned up + // by global constructors before other threads + // were done with it. +Log * +ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (uint32_t mask) +{ + Log *log = g_log; + if (log && mask) + { + uint32_t log_mask = log->GetMask().GetAllFlagBits(); + if ((log_mask & mask) != mask) + return NULL; + } + return log; +} + +void +ProcessGDBRemoteLog::DisableLog () +{ + if (g_log) + { + delete g_log; + g_log = NULL; + } +} + +Log * +ProcessGDBRemoteLog::EnableLog (StreamSP &log_stream_sp, uint32_t log_options, Args &args, Stream *feedback_strm) +{ + DisableLog (); + g_log = new Log (log_stream_sp); + if (g_log) + { + uint32_t flag_bits = 0; + bool got_unknown_category = false; + const size_t argc = args.GetArgumentCount(); + for (size_t i=0; iPrintf("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; + g_log->GetMask().SetAllFlagBits(flag_bits); + g_log->GetOptions().SetAllFlagBits(log_options); + } + return g_log; +} + +void +ProcessGDBRemoteLog::ListLogCategories (Stream *strm) +{ + strm->Printf("Logging categories for '%s':\n" + "\tall - turn on all available logging categories\n" + "\tbreak - log breakpoints\n" + "\tdefault - enable the default set of logging categories for liblldb\n" + "\tpackets - log gdb remote packets\n" + "\tmemory - log memory reads and writes\n" + "\tdata-short - log memory bytes for memory reads and writes for short transactions only\n" + "\tdata-long - log memory bytes for memory reads and writes for all transactions\n" + "\tprocess - log process events and activities\n" + "\tthread - log thread events and activities\n" + "\tstep - log step related activities\n" + "\tverbose - enable verbose loggging\n" + "\twatch - log watchpoint related activities\n", ProcessGDBRemote::GetPluginNameStatic()); +} + + +void +ProcessGDBRemoteLog::LogIf (uint32_t mask, const char *format, ...) +{ + Log *log = ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (mask); + if (log) + { + va_list args; + va_start (args, format); + log->VAPrintf (format, args); + va_end (args); + } +} -- cgit v1.1