blob: 805b8fd100ab16e76e312b98d59ca4f865853b09 [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- Log.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// C Includes
Chris Lattner30fdc8d2010-06-08 16:52:24 +000011#include <stdio.h>
12#include <stdarg.h>
13#include <stdlib.h>
Chris Lattner30fdc8d2010-06-08 16:52:24 +000014
15// C++ Includes
16#include <map>
17#include <string>
18
19// Other libraries and framework includes
20// Project includes
Chris Lattner30fdc8d2010-06-08 16:52:24 +000021#include "lldb/Core/Log.h"
22#include "lldb/Core/PluginManager.h"
23#include "lldb/Core/StreamFile.h"
24#include "lldb/Core/StreamString.h"
25#include "lldb/Host/Host.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000026#include "lldb/Host/Mutex.h"
Zachary Turner39de3112014-09-09 20:54:56 +000027#include "lldb/Host/ThisThread.h"
28#include "lldb/Host/TimeValue.h"
Caroline Tice20ad3c42010-10-29 21:48:37 +000029#include "lldb/Interpreter/Args.h"
Zachary Turner50232572015-03-18 21:31:45 +000030#include "lldb/Utility/NameMatches.h"
Zachary Turner39de3112014-09-09 20:54:56 +000031
32#include "llvm/ADT/SmallString.h"
Zachary Turnera893d302015-03-06 20:45:43 +000033#include "llvm/Support/raw_ostream.h"
34#include "llvm/Support/Signals.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000035using namespace lldb;
36using namespace lldb_private;
37
Chris Lattner30fdc8d2010-06-08 16:52:24 +000038Log::Log () :
39 m_stream_sp(),
40 m_options(0),
41 m_mask_bits(0)
42{
43}
44
Greg Clayton5160ce52013-03-27 23:08:40 +000045Log::Log (const StreamSP &stream_sp) :
Chris Lattner30fdc8d2010-06-08 16:52:24 +000046 m_stream_sp(stream_sp),
47 m_options(0),
48 m_mask_bits(0)
49{
50}
51
52Log::~Log ()
53{
54}
55
56Flags &
57Log::GetOptions()
58{
59 return m_options;
60}
61
62const Flags &
63Log::GetOptions() const
64{
65 return m_options;
66}
67
68Flags &
69Log::GetMask()
70{
71 return m_mask_bits;
72}
73
74const Flags &
75Log::GetMask() const
76{
77 return m_mask_bits;
78}
79
Zachary Turnerc1592652015-04-29 22:55:28 +000080void
81Log::PutCString(const char *cstr)
82{
83 Printf("%s", cstr);
84}
85
86//----------------------------------------------------------------------
87// Simple variable argument logging with flags.
88//----------------------------------------------------------------------
89void
90Log::Printf(const char *format, ...)
91{
92 va_list args;
93 va_start(args, format);
94 VAPrintf(format, args);
95 va_end(args);
96}
Chris Lattner30fdc8d2010-06-08 16:52:24 +000097
98//----------------------------------------------------------------------
99// All logging eventually boils down to this function call. If we have
100// a callback registered, then we call the logging callback. If we have
101// a valid file handle, we also log to the file.
102//----------------------------------------------------------------------
103void
Zachary Turnerc1592652015-04-29 22:55:28 +0000104Log::VAPrintf(const char *format, va_list args)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000105{
Greg Claytone98008c2014-02-13 23:34:38 +0000106 // Make a copy of our stream shared pointer in case someone disables our
107 // log while we are logging and releases the stream
108 StreamSP stream_sp(m_stream_sp);
109 if (stream_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000110 {
111 static uint32_t g_sequence_id = 0;
112 StreamString header;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000113
114 // Add a sequence ID if requested
Greg Clayton73b472d2010-10-27 03:32:59 +0000115 if (m_options.Test (LLDB_LOG_OPTION_PREPEND_SEQUENCE))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000116 header.Printf ("%u ", ++g_sequence_id);
117
118 // Timestamp if requested
Greg Clayton73b472d2010-10-27 03:32:59 +0000119 if (m_options.Test (LLDB_LOG_OPTION_PREPEND_TIMESTAMP))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000120 {
Virgile Bello0a3b1512013-09-04 13:56:11 +0000121 TimeValue now = TimeValue::Now();
Jason Molenda3c2daca2013-09-11 21:00:37 +0000122 header.Printf ("%9d.%6.6d ", now.seconds(), now.nanoseconds());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000123 }
124
125 // Add the process and thread if requested
Greg Clayton73b472d2010-10-27 03:32:59 +0000126 if (m_options.Test (LLDB_LOG_OPTION_PREPEND_PROC_AND_THREAD))
Daniel Malead01b2952012-11-29 21:49:15 +0000127 header.Printf ("[%4.4x/%4.4" PRIx64 "]: ", getpid(), Host::GetCurrentThreadID());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000128
Ed Mastecc913d142014-05-21 13:46:46 +0000129 // Add the thread name if requested
Greg Clayton73b472d2010-10-27 03:32:59 +0000130 if (m_options.Test (LLDB_LOG_OPTION_PREPEND_THREAD_NAME))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000131 {
Zachary Turner39de3112014-09-09 20:54:56 +0000132 llvm::SmallString<32> thread_name;
133 ThisThread::GetName(thread_name);
Greg Clayton85719632013-02-27 22:51:58 +0000134 if (!thread_name.empty())
135 header.Printf ("%s ", thread_name.c_str());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000136 }
137
138 header.PrintfVarArg (format, args);
Zachary Turnera49c5912015-05-08 18:50:54 +0000139 header.PutCString("\n");
140
Zachary Turnera893d302015-03-06 20:45:43 +0000141 if (m_options.Test(LLDB_LOG_OPTION_BACKTRACE))
142 {
143 std::string back_trace;
144 llvm::raw_string_ostream stream(back_trace);
145 llvm::sys::PrintStackTrace(stream);
Zachary Turnera49c5912015-05-08 18:50:54 +0000146 header.PutCString(back_trace.c_str());
Zachary Turnera893d302015-03-06 20:45:43 +0000147 }
Zachary Turnera49c5912015-05-08 18:50:54 +0000148
149 if (m_options.Test(LLDB_LOG_OPTION_THREADSAFE))
150 {
151 static Mutex g_LogThreadedMutex(Mutex::eMutexTypeRecursive);
152 Mutex::Locker locker(g_LogThreadedMutex);
153 stream_sp->PutCString(header.GetString().c_str());
154 stream_sp->Flush();
155 }
156 else
157 {
158 stream_sp->PutCString(header.GetString().c_str());
159 stream_sp->Flush();
160 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000161 }
162}
163
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000164//----------------------------------------------------------------------
165// Print debug strings if and only if the global debug option is set to
166// a non-zero value.
167//----------------------------------------------------------------------
168void
Zachary Turnerc1592652015-04-29 22:55:28 +0000169Log::Debug(const char *format, ...)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000170{
Zachary Turnerc1592652015-04-29 22:55:28 +0000171 if (!GetOptions().Test(LLDB_LOG_OPTION_DEBUG))
172 return;
173
174 va_list args;
175 va_start(args, format);
176 VAPrintf(format, args);
177 va_end(args);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000178}
179
180
181//----------------------------------------------------------------------
182// Print debug strings if and only if the global debug option is set to
183// a non-zero value.
184//----------------------------------------------------------------------
185void
Zachary Turnerc1592652015-04-29 22:55:28 +0000186Log::DebugVerbose(const char *format, ...)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000187{
Zachary Turnerc1592652015-04-29 22:55:28 +0000188 if (!GetOptions().AllSet(LLDB_LOG_OPTION_DEBUG | LLDB_LOG_OPTION_VERBOSE))
189 return;
190
191 va_list args;
192 va_start(args, format);
193 VAPrintf(format, args);
194 va_end(args);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000195}
196
197
198//----------------------------------------------------------------------
199// Log only if all of the bits are set
200//----------------------------------------------------------------------
201void
Zachary Turnerc1592652015-04-29 22:55:28 +0000202Log::LogIf(uint32_t bits, const char *format, ...)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000203{
Zachary Turnerc1592652015-04-29 22:55:28 +0000204 if (!m_options.AllSet(bits))
205 return;
206
207 va_list args;
208 va_start(args, format);
209 VAPrintf(format, args);
210 va_end(args);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000211}
212
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000213//----------------------------------------------------------------------
214// Printing of errors that are not fatal.
215//----------------------------------------------------------------------
216void
Zachary Turnerc1592652015-04-29 22:55:28 +0000217Log::Error(const char *format, ...)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000218{
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000219 va_list args;
Zachary Turnerc1592652015-04-29 22:55:28 +0000220 va_start(args, format);
Zachary Turner610e5292015-05-07 21:39:33 +0000221 VAError(format, args);
Zachary Turnerc1592652015-04-29 22:55:28 +0000222 va_end(args);
Zachary Turner610e5292015-05-07 21:39:33 +0000223}
224
225
226void
227Log::VAError(const char *format, va_list args)
228{
229 char *arg_msg = nullptr;
230 ::vasprintf(&arg_msg, format, args);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000231
Zachary Turnerc1592652015-04-29 22:55:28 +0000232 if (arg_msg == nullptr)
233 return;
234
Pavel Labathd351bcc2015-04-30 10:47:56 +0000235 Printf("error: %s", arg_msg);
Zachary Turnerc1592652015-04-29 22:55:28 +0000236 free(arg_msg);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000237}
238
Zachary Turner610e5292015-05-07 21:39:33 +0000239
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000240//----------------------------------------------------------------------
241// Printing of errors that ARE fatal. Exit with ERR exit code
242// immediately.
243//----------------------------------------------------------------------
244void
Zachary Turnerc1592652015-04-29 22:55:28 +0000245Log::FatalError(int err, const char *format, ...)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000246{
Zachary Turnerc1592652015-04-29 22:55:28 +0000247 char *arg_msg = nullptr;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000248 va_list args;
Zachary Turnerc1592652015-04-29 22:55:28 +0000249 va_start(args, format);
250 ::vasprintf(&arg_msg, format, args);
251 va_end(args);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000252
Zachary Turnerc1592652015-04-29 22:55:28 +0000253 if (arg_msg != nullptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000254 {
Zachary Turnerb74e2792015-04-29 23:24:12 +0000255 Printf("error: %s", arg_msg);
Zachary Turnerc1592652015-04-29 22:55:28 +0000256 ::free(arg_msg);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000257 }
Zachary Turnerc1592652015-04-29 22:55:28 +0000258 ::exit(err);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000259}
260
261
262//----------------------------------------------------------------------
263// Printing of warnings that are not fatal only if verbose mode is
264// enabled.
265//----------------------------------------------------------------------
266void
Zachary Turnerc1592652015-04-29 22:55:28 +0000267Log::Verbose(const char *format, ...)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000268{
Zachary Turnerc1592652015-04-29 22:55:28 +0000269 if (!m_options.Test(LLDB_LOG_OPTION_VERBOSE))
270 return;
271
272 va_list args;
273 va_start(args, format);
274 VAPrintf(format, args);
275 va_end(args);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000276}
277
278//----------------------------------------------------------------------
279// Printing of warnings that are not fatal only if verbose mode is
280// enabled.
281//----------------------------------------------------------------------
282void
Zachary Turnerc1592652015-04-29 22:55:28 +0000283Log::WarningVerbose(const char *format, ...)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000284{
Zachary Turnerc1592652015-04-29 22:55:28 +0000285 if (!m_options.Test(LLDB_LOG_OPTION_VERBOSE))
286 return;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000287
Zachary Turnerc1592652015-04-29 22:55:28 +0000288 char *arg_msg = nullptr;
289 va_list args;
290 va_start(args, format);
291 ::vasprintf(&arg_msg, format, args);
292 va_end(args);
293
294 if (arg_msg == nullptr)
295 return;
296
Zachary Turnerb74e2792015-04-29 23:24:12 +0000297 Printf("warning: %s", arg_msg);
Zachary Turnerc1592652015-04-29 22:55:28 +0000298 free(arg_msg);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000299}
300//----------------------------------------------------------------------
301// Printing of warnings that are not fatal.
302//----------------------------------------------------------------------
303void
Zachary Turnerc1592652015-04-29 22:55:28 +0000304Log::Warning(const char *format, ...)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000305{
Zachary Turnerc1592652015-04-29 22:55:28 +0000306 char *arg_msg = nullptr;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000307 va_list args;
Zachary Turnerc1592652015-04-29 22:55:28 +0000308 va_start(args, format);
309 ::vasprintf(&arg_msg, format, args);
310 va_end(args);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000311
Zachary Turnerc1592652015-04-29 22:55:28 +0000312 if (arg_msg == nullptr)
313 return;
314
Zachary Turnerb74e2792015-04-29 23:24:12 +0000315 Printf("warning: %s", arg_msg);
Zachary Turnerc1592652015-04-29 22:55:28 +0000316 free(arg_msg);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000317}
318
Greg Clayton57abc5d2013-05-10 21:47:16 +0000319typedef std::map <ConstString, Log::Callbacks> CallbackMap;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000320typedef CallbackMap::iterator CallbackMapIter;
321
322typedef std::map <ConstString, LogChannelSP> LogChannelMap;
323typedef LogChannelMap::iterator LogChannelMapIter;
324
325
326// Surround our callback map with a singleton function so we don't have any
327// global initializers.
328static CallbackMap &
329GetCallbackMap ()
330{
331 static CallbackMap g_callback_map;
332 return g_callback_map;
333}
334
335static LogChannelMap &
336GetChannelMap ()
337{
338 static LogChannelMap g_channel_map;
339 return g_channel_map;
340}
341
342void
Greg Clayton57abc5d2013-05-10 21:47:16 +0000343Log::RegisterLogChannel (const ConstString &channel, const Log::Callbacks &log_callbacks)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000344{
345 GetCallbackMap().insert(std::make_pair(channel, log_callbacks));
346}
347
348bool
Greg Clayton57abc5d2013-05-10 21:47:16 +0000349Log::UnregisterLogChannel (const ConstString &channel)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000350{
351 return GetCallbackMap().erase(channel) != 0;
352}
353
354bool
Greg Clayton57abc5d2013-05-10 21:47:16 +0000355Log::GetLogChannelCallbacks (const ConstString &channel, Log::Callbacks &log_callbacks)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000356{
357 CallbackMap &callback_map = GetCallbackMap ();
358 CallbackMapIter pos = callback_map.find(channel);
359 if (pos != callback_map.end())
360 {
361 log_callbacks = pos->second;
362 return true;
363 }
Greg Clayton72b77eb2011-02-04 21:13:05 +0000364 ::memset (&log_callbacks, 0, sizeof(log_callbacks));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000365 return false;
366}
367
Tamas Berghammer9c9ecce2015-05-27 13:34:04 +0000368bool
369Log::EnableLogChannel(lldb::StreamSP &log_stream_sp,
370 uint32_t log_options,
371 const char *channel,
372 const char **categories,
373 Stream &error_stream)
374{
375 Log::Callbacks log_callbacks;
376 if (Log::GetLogChannelCallbacks (ConstString(channel), log_callbacks))
377 {
378 log_callbacks.enable (log_stream_sp, log_options, categories, &error_stream);
379 return true;
380 }
381
382 LogChannelSP log_channel_sp (LogChannel::FindPlugin (channel));
383 if (log_channel_sp)
384 {
385 if (log_channel_sp->Enable (log_stream_sp, log_options, &error_stream, categories))
386 {
387 return true;
388 }
389 else
390 {
391 error_stream.Printf ("Invalid log channel '%s'.\n", channel);
392 return false;
393 }
394 }
395 else
396 {
397 error_stream.Printf ("Invalid log channel '%s'.\n", channel);
398 return false;
399 }
400}
401
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000402void
403Log::EnableAllLogChannels
404(
405 StreamSP &log_stream_sp,
406 uint32_t log_options,
Jim Ingham228063c2012-02-21 02:23:08 +0000407 const char **categories,
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000408 Stream *feedback_strm
409)
410{
411 CallbackMap &callback_map = GetCallbackMap ();
412 CallbackMapIter pos, end = callback_map.end();
413
414 for (pos = callback_map.begin(); pos != end; ++pos)
Jim Ingham228063c2012-02-21 02:23:08 +0000415 pos->second.enable (log_stream_sp, log_options, categories, feedback_strm);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000416
417 LogChannelMap &channel_map = GetChannelMap ();
418 LogChannelMapIter channel_pos, channel_end = channel_map.end();
419 for (channel_pos = channel_map.begin(); channel_pos != channel_end; ++channel_pos)
420 {
Jim Ingham228063c2012-02-21 02:23:08 +0000421 channel_pos->second->Enable (log_stream_sp, log_options, feedback_strm, categories);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000422 }
423
424}
425
426void
Greg Claytonab65b342011-04-13 22:47:15 +0000427Log::AutoCompleteChannelName (const char *channel_name, StringList &matches)
428{
429 LogChannelMap &map = GetChannelMap ();
430 LogChannelMapIter pos, end = map.end();
431 for (pos = map.begin(); pos != end; ++pos)
432 {
433 const char *pos_channel_name = pos->first.GetCString();
434 if (channel_name && channel_name[0])
435 {
436 if (NameMatches (channel_name, eNameMatchStartsWith, pos_channel_name))
437 {
438 matches.AppendString(pos_channel_name);
439 }
440 }
441 else
442 matches.AppendString(pos_channel_name);
443
444 }
445}
446
447void
Caroline Tice20ad3c42010-10-29 21:48:37 +0000448Log::DisableAllLogChannels (Stream *feedback_strm)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000449{
450 CallbackMap &callback_map = GetCallbackMap ();
451 CallbackMapIter pos, end = callback_map.end();
Jim Ingham228063c2012-02-21 02:23:08 +0000452 const char *categories[1] = {NULL};
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000453
454 for (pos = callback_map.begin(); pos != end; ++pos)
Jim Ingham228063c2012-02-21 02:23:08 +0000455 pos->second.disable (categories, feedback_strm);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000456
457 LogChannelMap &channel_map = GetChannelMap ();
458 LogChannelMapIter channel_pos, channel_end = channel_map.end();
459 for (channel_pos = channel_map.begin(); channel_pos != channel_end; ++channel_pos)
Jim Ingham228063c2012-02-21 02:23:08 +0000460 channel_pos->second->Disable (categories, feedback_strm);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000461}
462
463void
Greg Clayton99d0faf2010-11-18 23:32:35 +0000464Log::Initialize()
465{
466 Log::Callbacks log_callbacks = { DisableLog, EnableLog, ListLogCategories };
Greg Clayton57abc5d2013-05-10 21:47:16 +0000467 Log::RegisterLogChannel (ConstString("lldb"), log_callbacks);
Greg Clayton99d0faf2010-11-18 23:32:35 +0000468}
469
470void
471Log::Terminate ()
472{
473 DisableAllLogChannels (NULL);
474}
475
476void
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000477Log::ListAllLogChannels (Stream *strm)
478{
479 CallbackMap &callback_map = GetCallbackMap ();
480 LogChannelMap &channel_map = GetChannelMap ();
481
482 if (callback_map.empty() && channel_map.empty())
483 {
484 strm->PutCString ("No logging channels are currently registered.\n");
485 return;
486 }
487
488 CallbackMapIter pos, end = callback_map.end();
489 for (pos = callback_map.begin(); pos != end; ++pos)
490 pos->second.list_categories (strm);
491
492 uint32_t idx = 0;
493 const char *name;
494 for (idx = 0; (name = PluginManager::GetLogChannelCreateNameAtIndex (idx)) != NULL; ++idx)
495 {
496 LogChannelSP log_channel_sp(LogChannel::FindPlugin (name));
497 if (log_channel_sp)
498 log_channel_sp->ListCategories (strm);
499 }
500}
501
502bool
503Log::GetVerbose() const
504{
Jim Inghamd8d148e2011-01-22 01:24:30 +0000505 // FIXME: This has to be centralized between the stream and the log...
506 if (m_options.Test(LLDB_LOG_OPTION_VERBOSE))
507 return true;
508
Greg Claytone98008c2014-02-13 23:34:38 +0000509 // Make a copy of our stream shared pointer in case someone disables our
510 // log while we are logging and releases the stream
511 StreamSP stream_sp(m_stream_sp);
512 if (stream_sp)
513 return stream_sp->GetVerbose();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000514 return false;
515}
516
517//------------------------------------------------------------------
518// Returns true if the debug flag bit is set in this stream.
519//------------------------------------------------------------------
520bool
521Log::GetDebug() const
522{
Greg Claytone98008c2014-02-13 23:34:38 +0000523 // Make a copy of our stream shared pointer in case someone disables our
524 // log while we are logging and releases the stream
525 StreamSP stream_sp(m_stream_sp);
526 if (stream_sp)
527 return stream_sp->GetDebug();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000528 return false;
529}
530
531
532LogChannelSP
533LogChannel::FindPlugin (const char *plugin_name)
534{
535 LogChannelSP log_channel_sp;
536 LogChannelMap &channel_map = GetChannelMap ();
537 ConstString log_channel_name (plugin_name);
538 LogChannelMapIter pos = channel_map.find (log_channel_name);
539 if (pos == channel_map.end())
540 {
Greg Clayton57abc5d2013-05-10 21:47:16 +0000541 ConstString const_plugin_name (plugin_name);
542 LogChannelCreateInstance create_callback = PluginManager::GetLogChannelCreateCallbackForPluginName (const_plugin_name);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000543 if (create_callback)
544 {
545 log_channel_sp.reset(create_callback());
546 if (log_channel_sp)
547 {
548 // Cache the one and only loaded instance of each log channel
549 // plug-in after it has been loaded once.
550 channel_map[log_channel_name] = log_channel_sp;
551 }
552 }
553 }
554 else
555 {
556 // We have already loaded an instance of this log channel class,
557 // so just return the cached instance.
558 log_channel_sp = pos->second;
559 }
560 return log_channel_sp;
561}
562
563LogChannel::LogChannel () :
Greg Clayton5160ce52013-03-27 23:08:40 +0000564 m_log_ap ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000565{
566}
567
568LogChannel::~LogChannel ()
569{
570}
571
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000572