blob: 9a356e6fce275636d635315bde3e2675aecf19db [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// C++ Includes
Eugene Zelenkoa74f37a2016-03-10 23:57:12 +000012#include <cstdio>
13#include <cstdarg>
14#include <cstdlib>
Chris Lattner30fdc8d2010-06-08 16:52:24 +000015#include <map>
16#include <string>
17
18// Other libraries and framework includes
Eugene Zelenkoa74f37a2016-03-10 23:57:12 +000019#include "llvm/ADT/SmallString.h"
20#include "llvm/Support/raw_ostream.h"
21#include "llvm/Support/Signals.h"
22
Chris Lattner30fdc8d2010-06-08 16:52:24 +000023// Project includes
Chris Lattner30fdc8d2010-06-08 16:52:24 +000024#include "lldb/Core/Log.h"
25#include "lldb/Core/PluginManager.h"
26#include "lldb/Core/StreamFile.h"
27#include "lldb/Core/StreamString.h"
28#include "lldb/Host/Host.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000029#include "lldb/Host/Mutex.h"
Zachary Turner39de3112014-09-09 20:54:56 +000030#include "lldb/Host/ThisThread.h"
31#include "lldb/Host/TimeValue.h"
Caroline Tice20ad3c42010-10-29 21:48:37 +000032#include "lldb/Interpreter/Args.h"
Zachary Turner50232572015-03-18 21:31:45 +000033#include "lldb/Utility/NameMatches.h"
Zachary Turner39de3112014-09-09 20:54:56 +000034
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
Eugene Zelenkoa74f37a2016-03-10 23:57:12 +000052Log::~Log() = default;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000053
54Flags &
55Log::GetOptions()
56{
57 return m_options;
58}
59
60const Flags &
61Log::GetOptions() const
62{
63 return m_options;
64}
65
66Flags &
67Log::GetMask()
68{
69 return m_mask_bits;
70}
71
72const Flags &
73Log::GetMask() const
74{
75 return m_mask_bits;
76}
77
Zachary Turnerc1592652015-04-29 22:55:28 +000078void
79Log::PutCString(const char *cstr)
80{
81 Printf("%s", cstr);
82}
83
84//----------------------------------------------------------------------
85// Simple variable argument logging with flags.
86//----------------------------------------------------------------------
87void
88Log::Printf(const char *format, ...)
89{
90 va_list args;
91 va_start(args, format);
92 VAPrintf(format, args);
93 va_end(args);
94}
Chris Lattner30fdc8d2010-06-08 16:52:24 +000095
96//----------------------------------------------------------------------
97// All logging eventually boils down to this function call. If we have
98// a callback registered, then we call the logging callback. If we have
99// a valid file handle, we also log to the file.
100//----------------------------------------------------------------------
101void
Zachary Turnerc1592652015-04-29 22:55:28 +0000102Log::VAPrintf(const char *format, va_list args)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000103{
Greg Claytone98008c2014-02-13 23:34:38 +0000104 // Make a copy of our stream shared pointer in case someone disables our
105 // log while we are logging and releases the stream
106 StreamSP stream_sp(m_stream_sp);
107 if (stream_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000108 {
109 static uint32_t g_sequence_id = 0;
110 StreamString header;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000111
112 // Add a sequence ID if requested
Greg Clayton73b472d2010-10-27 03:32:59 +0000113 if (m_options.Test (LLDB_LOG_OPTION_PREPEND_SEQUENCE))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000114 header.Printf ("%u ", ++g_sequence_id);
115
116 // Timestamp if requested
Greg Clayton73b472d2010-10-27 03:32:59 +0000117 if (m_options.Test (LLDB_LOG_OPTION_PREPEND_TIMESTAMP))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000118 {
Virgile Bello0a3b1512013-09-04 13:56:11 +0000119 TimeValue now = TimeValue::Now();
Greg Claytondead71a2015-05-27 16:25:01 +0000120 header.Printf ("%9d.%09.9d ", now.seconds(), now.nanoseconds());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000121 }
122
123 // Add the process and thread if requested
Greg Clayton73b472d2010-10-27 03:32:59 +0000124 if (m_options.Test (LLDB_LOG_OPTION_PREPEND_PROC_AND_THREAD))
Daniel Malead01b2952012-11-29 21:49:15 +0000125 header.Printf ("[%4.4x/%4.4" PRIx64 "]: ", getpid(), Host::GetCurrentThreadID());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000126
Ed Mastecc913d142014-05-21 13:46:46 +0000127 // Add the thread name if requested
Greg Clayton73b472d2010-10-27 03:32:59 +0000128 if (m_options.Test (LLDB_LOG_OPTION_PREPEND_THREAD_NAME))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000129 {
Zachary Turner39de3112014-09-09 20:54:56 +0000130 llvm::SmallString<32> thread_name;
131 ThisThread::GetName(thread_name);
Greg Clayton85719632013-02-27 22:51:58 +0000132 if (!thread_name.empty())
133 header.Printf ("%s ", thread_name.c_str());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000134 }
135
136 header.PrintfVarArg (format, args);
Zachary Turnera49c5912015-05-08 18:50:54 +0000137 header.PutCString("\n");
138
Zachary Turnera893d302015-03-06 20:45:43 +0000139 if (m_options.Test(LLDB_LOG_OPTION_BACKTRACE))
140 {
141 std::string back_trace;
142 llvm::raw_string_ostream stream(back_trace);
143 llvm::sys::PrintStackTrace(stream);
Todd Fiala53b13702015-10-10 01:26:47 +0000144 stream.flush();
Zachary Turnera49c5912015-05-08 18:50:54 +0000145 header.PutCString(back_trace.c_str());
Zachary Turnera893d302015-03-06 20:45:43 +0000146 }
Zachary Turnera49c5912015-05-08 18:50:54 +0000147
148 if (m_options.Test(LLDB_LOG_OPTION_THREADSAFE))
149 {
150 static Mutex g_LogThreadedMutex(Mutex::eMutexTypeRecursive);
151 Mutex::Locker locker(g_LogThreadedMutex);
152 stream_sp->PutCString(header.GetString().c_str());
153 stream_sp->Flush();
154 }
155 else
156 {
157 stream_sp->PutCString(header.GetString().c_str());
158 stream_sp->Flush();
159 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000160 }
161}
162
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000163//----------------------------------------------------------------------
164// Print debug strings if and only if the global debug option is set to
165// a non-zero value.
166//----------------------------------------------------------------------
167void
Zachary Turnerc1592652015-04-29 22:55:28 +0000168Log::Debug(const char *format, ...)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000169{
Zachary Turnerc1592652015-04-29 22:55:28 +0000170 if (!GetOptions().Test(LLDB_LOG_OPTION_DEBUG))
171 return;
172
173 va_list args;
174 va_start(args, format);
175 VAPrintf(format, args);
176 va_end(args);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000177}
178
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000179//----------------------------------------------------------------------
180// Print debug strings if and only if the global debug option is set to
181// a non-zero value.
182//----------------------------------------------------------------------
183void
Zachary Turnerc1592652015-04-29 22:55:28 +0000184Log::DebugVerbose(const char *format, ...)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000185{
Zachary Turnerc1592652015-04-29 22:55:28 +0000186 if (!GetOptions().AllSet(LLDB_LOG_OPTION_DEBUG | LLDB_LOG_OPTION_VERBOSE))
187 return;
188
189 va_list args;
190 va_start(args, format);
191 VAPrintf(format, args);
192 va_end(args);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000193}
194
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000195//----------------------------------------------------------------------
196// Log only if all of the bits are set
197//----------------------------------------------------------------------
198void
Zachary Turnerc1592652015-04-29 22:55:28 +0000199Log::LogIf(uint32_t bits, const char *format, ...)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000200{
Zachary Turnerc1592652015-04-29 22:55:28 +0000201 if (!m_options.AllSet(bits))
202 return;
203
204 va_list args;
205 va_start(args, format);
206 VAPrintf(format, args);
207 va_end(args);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000208}
209
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000210//----------------------------------------------------------------------
211// Printing of errors that are not fatal.
212//----------------------------------------------------------------------
213void
Zachary Turnerc1592652015-04-29 22:55:28 +0000214Log::Error(const char *format, ...)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000215{
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000216 va_list args;
Zachary Turnerc1592652015-04-29 22:55:28 +0000217 va_start(args, format);
Zachary Turner610e5292015-05-07 21:39:33 +0000218 VAError(format, args);
Zachary Turnerc1592652015-04-29 22:55:28 +0000219 va_end(args);
Zachary Turner610e5292015-05-07 21:39:33 +0000220}
221
Zachary Turner610e5292015-05-07 21:39:33 +0000222void
223Log::VAError(const char *format, va_list args)
224{
225 char *arg_msg = nullptr;
226 ::vasprintf(&arg_msg, format, args);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000227
Zachary Turnerc1592652015-04-29 22:55:28 +0000228 if (arg_msg == nullptr)
229 return;
230
Pavel Labathd351bcc2015-04-30 10:47:56 +0000231 Printf("error: %s", arg_msg);
Zachary Turnerc1592652015-04-29 22:55:28 +0000232 free(arg_msg);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000233}
234
235//----------------------------------------------------------------------
236// Printing of errors that ARE fatal. Exit with ERR exit code
237// immediately.
238//----------------------------------------------------------------------
239void
Zachary Turnerc1592652015-04-29 22:55:28 +0000240Log::FatalError(int err, const char *format, ...)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000241{
Zachary Turnerc1592652015-04-29 22:55:28 +0000242 char *arg_msg = nullptr;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000243 va_list args;
Zachary Turnerc1592652015-04-29 22:55:28 +0000244 va_start(args, format);
245 ::vasprintf(&arg_msg, format, args);
246 va_end(args);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000247
Zachary Turnerc1592652015-04-29 22:55:28 +0000248 if (arg_msg != nullptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000249 {
Zachary Turnerb74e2792015-04-29 23:24:12 +0000250 Printf("error: %s", arg_msg);
Zachary Turnerc1592652015-04-29 22:55:28 +0000251 ::free(arg_msg);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000252 }
Zachary Turnerc1592652015-04-29 22:55:28 +0000253 ::exit(err);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000254}
255
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000256//----------------------------------------------------------------------
257// Printing of warnings that are not fatal only if verbose mode is
258// enabled.
259//----------------------------------------------------------------------
260void
Zachary Turnerc1592652015-04-29 22:55:28 +0000261Log::Verbose(const char *format, ...)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000262{
Zachary Turnerc1592652015-04-29 22:55:28 +0000263 if (!m_options.Test(LLDB_LOG_OPTION_VERBOSE))
264 return;
265
266 va_list args;
267 va_start(args, format);
268 VAPrintf(format, args);
269 va_end(args);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000270}
271
272//----------------------------------------------------------------------
273// Printing of warnings that are not fatal only if verbose mode is
274// enabled.
275//----------------------------------------------------------------------
276void
Zachary Turnerc1592652015-04-29 22:55:28 +0000277Log::WarningVerbose(const char *format, ...)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000278{
Zachary Turnerc1592652015-04-29 22:55:28 +0000279 if (!m_options.Test(LLDB_LOG_OPTION_VERBOSE))
280 return;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000281
Zachary Turnerc1592652015-04-29 22:55:28 +0000282 char *arg_msg = nullptr;
283 va_list args;
284 va_start(args, format);
285 ::vasprintf(&arg_msg, format, args);
286 va_end(args);
287
288 if (arg_msg == nullptr)
289 return;
290
Zachary Turnerb74e2792015-04-29 23:24:12 +0000291 Printf("warning: %s", arg_msg);
Zachary Turnerc1592652015-04-29 22:55:28 +0000292 free(arg_msg);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000293}
Eugene Zelenkoa74f37a2016-03-10 23:57:12 +0000294
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000295//----------------------------------------------------------------------
296// Printing of warnings that are not fatal.
297//----------------------------------------------------------------------
298void
Zachary Turnerc1592652015-04-29 22:55:28 +0000299Log::Warning(const char *format, ...)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000300{
Zachary Turnerc1592652015-04-29 22:55:28 +0000301 char *arg_msg = nullptr;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000302 va_list args;
Zachary Turnerc1592652015-04-29 22:55:28 +0000303 va_start(args, format);
304 ::vasprintf(&arg_msg, format, args);
305 va_end(args);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000306
Zachary Turnerc1592652015-04-29 22:55:28 +0000307 if (arg_msg == nullptr)
308 return;
309
Zachary Turnerb74e2792015-04-29 23:24:12 +0000310 Printf("warning: %s", arg_msg);
Zachary Turnerc1592652015-04-29 22:55:28 +0000311 free(arg_msg);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000312}
313
Greg Clayton57abc5d2013-05-10 21:47:16 +0000314typedef std::map <ConstString, Log::Callbacks> CallbackMap;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000315typedef CallbackMap::iterator CallbackMapIter;
316
317typedef std::map <ConstString, LogChannelSP> LogChannelMap;
318typedef LogChannelMap::iterator LogChannelMapIter;
319
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000320// Surround our callback map with a singleton function so we don't have any
321// global initializers.
322static CallbackMap &
323GetCallbackMap ()
324{
325 static CallbackMap g_callback_map;
326 return g_callback_map;
327}
328
329static LogChannelMap &
330GetChannelMap ()
331{
332 static LogChannelMap g_channel_map;
333 return g_channel_map;
334}
335
336void
Greg Clayton57abc5d2013-05-10 21:47:16 +0000337Log::RegisterLogChannel (const ConstString &channel, const Log::Callbacks &log_callbacks)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000338{
339 GetCallbackMap().insert(std::make_pair(channel, log_callbacks));
340}
341
342bool
Greg Clayton57abc5d2013-05-10 21:47:16 +0000343Log::UnregisterLogChannel (const ConstString &channel)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000344{
345 return GetCallbackMap().erase(channel) != 0;
346}
347
348bool
Greg Clayton57abc5d2013-05-10 21:47:16 +0000349Log::GetLogChannelCallbacks (const ConstString &channel, Log::Callbacks &log_callbacks)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000350{
351 CallbackMap &callback_map = GetCallbackMap ();
352 CallbackMapIter pos = callback_map.find(channel);
353 if (pos != callback_map.end())
354 {
355 log_callbacks = pos->second;
356 return true;
357 }
Greg Clayton72b77eb2011-02-04 21:13:05 +0000358 ::memset (&log_callbacks, 0, sizeof(log_callbacks));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000359 return false;
360}
361
Tamas Berghammer9c9ecce2015-05-27 13:34:04 +0000362bool
363Log::EnableLogChannel(lldb::StreamSP &log_stream_sp,
364 uint32_t log_options,
365 const char *channel,
366 const char **categories,
367 Stream &error_stream)
368{
369 Log::Callbacks log_callbacks;
370 if (Log::GetLogChannelCallbacks (ConstString(channel), log_callbacks))
371 {
372 log_callbacks.enable (log_stream_sp, log_options, categories, &error_stream);
373 return true;
374 }
375
376 LogChannelSP log_channel_sp (LogChannel::FindPlugin (channel));
377 if (log_channel_sp)
378 {
379 if (log_channel_sp->Enable (log_stream_sp, log_options, &error_stream, categories))
380 {
381 return true;
382 }
383 else
384 {
385 error_stream.Printf ("Invalid log channel '%s'.\n", channel);
386 return false;
387 }
388 }
389 else
390 {
391 error_stream.Printf ("Invalid log channel '%s'.\n", channel);
392 return false;
393 }
394}
395
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000396void
Eugene Zelenkoa74f37a2016-03-10 23:57:12 +0000397Log::EnableAllLogChannels(StreamSP &log_stream_sp,
398 uint32_t log_options,
399 const char **categories,
400 Stream *feedback_strm)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000401{
402 CallbackMap &callback_map = GetCallbackMap ();
403 CallbackMapIter pos, end = callback_map.end();
404
405 for (pos = callback_map.begin(); pos != end; ++pos)
Jim Ingham228063c2012-02-21 02:23:08 +0000406 pos->second.enable (log_stream_sp, log_options, categories, feedback_strm);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000407
408 LogChannelMap &channel_map = GetChannelMap ();
409 LogChannelMapIter channel_pos, channel_end = channel_map.end();
410 for (channel_pos = channel_map.begin(); channel_pos != channel_end; ++channel_pos)
411 {
Jim Ingham228063c2012-02-21 02:23:08 +0000412 channel_pos->second->Enable (log_stream_sp, log_options, feedback_strm, categories);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000413 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000414}
415
416void
Greg Claytonab65b342011-04-13 22:47:15 +0000417Log::AutoCompleteChannelName (const char *channel_name, StringList &matches)
418{
419 LogChannelMap &map = GetChannelMap ();
420 LogChannelMapIter pos, end = map.end();
421 for (pos = map.begin(); pos != end; ++pos)
422 {
423 const char *pos_channel_name = pos->first.GetCString();
424 if (channel_name && channel_name[0])
425 {
426 if (NameMatches (channel_name, eNameMatchStartsWith, pos_channel_name))
427 {
428 matches.AppendString(pos_channel_name);
429 }
430 }
431 else
432 matches.AppendString(pos_channel_name);
Greg Claytonab65b342011-04-13 22:47:15 +0000433 }
434}
435
436void
Caroline Tice20ad3c42010-10-29 21:48:37 +0000437Log::DisableAllLogChannels (Stream *feedback_strm)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000438{
439 CallbackMap &callback_map = GetCallbackMap ();
440 CallbackMapIter pos, end = callback_map.end();
Pavel Labathd2c4c9b2015-08-18 08:23:35 +0000441 const char *categories[] = {"all", nullptr};
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000442
443 for (pos = callback_map.begin(); pos != end; ++pos)
Jim Ingham228063c2012-02-21 02:23:08 +0000444 pos->second.disable (categories, feedback_strm);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000445
446 LogChannelMap &channel_map = GetChannelMap ();
447 LogChannelMapIter channel_pos, channel_end = channel_map.end();
448 for (channel_pos = channel_map.begin(); channel_pos != channel_end; ++channel_pos)
Jim Ingham228063c2012-02-21 02:23:08 +0000449 channel_pos->second->Disable (categories, feedback_strm);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000450}
451
452void
Greg Clayton99d0faf2010-11-18 23:32:35 +0000453Log::Initialize()
454{
455 Log::Callbacks log_callbacks = { DisableLog, EnableLog, ListLogCategories };
Greg Clayton57abc5d2013-05-10 21:47:16 +0000456 Log::RegisterLogChannel (ConstString("lldb"), log_callbacks);
Greg Clayton99d0faf2010-11-18 23:32:35 +0000457}
458
459void
460Log::Terminate ()
461{
Eugene Zelenkoa74f37a2016-03-10 23:57:12 +0000462 DisableAllLogChannels(nullptr);
Greg Clayton99d0faf2010-11-18 23:32:35 +0000463}
464
465void
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000466Log::ListAllLogChannels (Stream *strm)
467{
468 CallbackMap &callback_map = GetCallbackMap ();
469 LogChannelMap &channel_map = GetChannelMap ();
470
471 if (callback_map.empty() && channel_map.empty())
472 {
473 strm->PutCString ("No logging channels are currently registered.\n");
474 return;
475 }
476
477 CallbackMapIter pos, end = callback_map.end();
478 for (pos = callback_map.begin(); pos != end; ++pos)
479 pos->second.list_categories (strm);
480
481 uint32_t idx = 0;
482 const char *name;
Eugene Zelenkoa74f37a2016-03-10 23:57:12 +0000483 for (idx = 0; (name = PluginManager::GetLogChannelCreateNameAtIndex (idx)) != nullptr; ++idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000484 {
485 LogChannelSP log_channel_sp(LogChannel::FindPlugin (name));
486 if (log_channel_sp)
487 log_channel_sp->ListCategories (strm);
488 }
489}
490
491bool
492Log::GetVerbose() const
493{
Jim Inghamd8d148e2011-01-22 01:24:30 +0000494 // FIXME: This has to be centralized between the stream and the log...
495 if (m_options.Test(LLDB_LOG_OPTION_VERBOSE))
496 return true;
497
Greg Claytone98008c2014-02-13 23:34:38 +0000498 // Make a copy of our stream shared pointer in case someone disables our
499 // log while we are logging and releases the stream
500 StreamSP stream_sp(m_stream_sp);
501 if (stream_sp)
502 return stream_sp->GetVerbose();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000503 return false;
504}
505
506//------------------------------------------------------------------
507// Returns true if the debug flag bit is set in this stream.
508//------------------------------------------------------------------
509bool
510Log::GetDebug() const
511{
Greg Claytone98008c2014-02-13 23:34:38 +0000512 // Make a copy of our stream shared pointer in case someone disables our
513 // log while we are logging and releases the stream
514 StreamSP stream_sp(m_stream_sp);
515 if (stream_sp)
516 return stream_sp->GetDebug();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000517 return false;
518}
519
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000520LogChannelSP
521LogChannel::FindPlugin (const char *plugin_name)
522{
523 LogChannelSP log_channel_sp;
524 LogChannelMap &channel_map = GetChannelMap ();
525 ConstString log_channel_name (plugin_name);
526 LogChannelMapIter pos = channel_map.find (log_channel_name);
527 if (pos == channel_map.end())
528 {
Greg Clayton57abc5d2013-05-10 21:47:16 +0000529 ConstString const_plugin_name (plugin_name);
530 LogChannelCreateInstance create_callback = PluginManager::GetLogChannelCreateCallbackForPluginName (const_plugin_name);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000531 if (create_callback)
532 {
533 log_channel_sp.reset(create_callback());
534 if (log_channel_sp)
535 {
536 // Cache the one and only loaded instance of each log channel
537 // plug-in after it has been loaded once.
538 channel_map[log_channel_name] = log_channel_sp;
539 }
540 }
541 }
542 else
543 {
544 // We have already loaded an instance of this log channel class,
545 // so just return the cached instance.
546 log_channel_sp = pos->second;
547 }
548 return log_channel_sp;
549}
550
551LogChannel::LogChannel () :
Greg Clayton5160ce52013-03-27 23:08:40 +0000552 m_log_ap ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000553{
554}
555
Eugene Zelenkoa74f37a2016-03-10 23:57:12 +0000556LogChannel::~LogChannel() = default;