blob: 946c8f9310c16a6716b880905d8632bc92074ced [file] [log] [blame]
Chris Lattner24943d22010-06-08 16:52:24 +00001//===-- DynamicLoaderMacOSXDYLDLog.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#include "DynamicLoaderMacOSXDYLDLog.h"
11#include "lldb/Core/Log.h"
12
13using namespace lldb_private;
14
15static Log *
16LogAccessor (bool get, Log *log)
17{
18 static Log* g_log = NULL; // Leak for now as auto_ptr was being cleaned up
19 // by global constructors before other threads
20 // were done with it.
21 if (get)
22 {
23// // Debug code below for enabling logging by default
24// if (g_log == NULL)
25// {
26// g_log = new Log("/dev/stdout", false);
27// g_log->GetMask().SetAllFlagBits(0xffffffffu);
28// g_log->GetOptions().Set(LLDB_LOG_OPTION_THREADSAFE | LLDB_LOG_OPTION_PREPEND_THREAD_NAME);
29// }
30 }
31 else
32 {
33 if (g_log)
34 delete g_log;
35 g_log = log;
36 }
37
38 return g_log;
39}
40
41Log *
42DynamicLoaderMacOSXDYLDLog::GetLogIfAllCategoriesSet (uint32_t mask)
43{
44 Log *log = LogAccessor (true, NULL);
45 if (log && mask)
46 {
47 uint32_t log_mask = log->GetMask().GetAllFlagBits();
48 if ((log_mask & mask) != mask)
49 return NULL;
50 }
51 return log;
52}
53
54void
55DynamicLoaderMacOSXDYLDLog::SetLog (Log *log)
56{
57 LogAccessor (false, log);
58}
59
60
61void
62DynamicLoaderMacOSXDYLDLog::LogIf (uint32_t mask, const char *format, ...)
63{
64 Log *log = DynamicLoaderMacOSXDYLDLog::GetLogIfAllCategoriesSet (mask);
65 if (log)
66 {
67 va_list args;
68 va_start (args, format);
69 log->VAPrintf (format, args);
70 va_end (args);
71 }
72}