Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- GDBServerLog.cpp ----------------------------------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | //---------------------------------------------------------------------- |
| 10 | // |
| 11 | // GDBServerLog.cpp |
| 12 | // liblldb |
| 13 | // |
| 14 | // Created by Greg Clayton on 6/19/09. |
| 15 | // |
| 16 | // |
| 17 | //---------------------------------------------------------------------- |
| 18 | |
| 19 | #include "GDBServerLog.h" |
| 20 | |
| 21 | using namespace lldb; |
| 22 | |
| 23 | static Log * |
| 24 | LogAccessor (bool get, Log *log) |
| 25 | { |
| 26 | static Log* g_log = NULL; // Leak for now as auto_ptr was being cleaned up |
| 27 | // by global constructors before other threads |
| 28 | // were done with it. |
| 29 | if (get) |
| 30 | { |
| 31 | // // Debug code below for enabling logging by default |
| 32 | // if (g_log == NULL) |
| 33 | // { |
| 34 | // g_log = new Log("/dev/stdout", false); |
| 35 | // g_log->GetMask().SetAllFlagBits(GS_LOG_ALL); |
| 36 | // g_log->GetOptions().Set(LLDB_LOG_OPTION_THREADSAFE | LLDB_LOG_OPTION_PREPEND_THREAD_NAME); |
| 37 | // } |
| 38 | } |
| 39 | else |
| 40 | { |
| 41 | if (g_log) |
| 42 | delete g_log; |
| 43 | g_log = log; |
| 44 | } |
| 45 | |
| 46 | return g_log; |
| 47 | } |
| 48 | |
| 49 | Log * |
| 50 | GDBServerLog::GetLogIfAllCategoriesSet (uint32_t mask) |
| 51 | { |
| 52 | Log *log = LogAccessor (true, NULL); |
| 53 | if (log && mask) |
| 54 | { |
| 55 | uint32_t log_mask = log->GetMask().GetAllFlagBits(); |
| 56 | if ((log_mask & mask) != mask) |
| 57 | return NULL; |
| 58 | } |
| 59 | return log; |
| 60 | } |
| 61 | |
| 62 | void |
| 63 | GDBServerLog::SetLog (Log *log) |
| 64 | { |
| 65 | LogAccessor (false, log); |
| 66 | } |
| 67 | |
| 68 | |
| 69 | void |
| 70 | GDBServerLog::LogIf (uint32_t mask, const char *format, ...) |
| 71 | { |
| 72 | Log *log = GDBServerLog::GetLogIfAllCategoriesSet (mask); |
| 73 | if (log) |
| 74 | { |
| 75 | va_list args; |
| 76 | va_start (args, format); |
| 77 | log->VAPrintf (format, args); |
| 78 | va_end (args); |
| 79 | } |
| 80 | } |