Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- 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 | |
Daniel Malea | d891f9b | 2012-12-05 00:20:57 +0000 | [diff] [blame] | 10 | #include "lldb/lldb-python.h" |
| 11 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 12 | // C Includes |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 13 | #include <pthread.h> |
| 14 | #include <stdio.h> |
| 15 | #include <stdarg.h> |
| 16 | #include <stdlib.h> |
| 17 | #include <unistd.h> |
| 18 | |
| 19 | // C++ Includes |
| 20 | #include <map> |
| 21 | #include <string> |
| 22 | |
| 23 | // Other libraries and framework includes |
| 24 | // Project includes |
| 25 | #include "lldb/Core/Debugger.h" |
| 26 | #include "lldb/Core/Log.h" |
| 27 | #include "lldb/Core/PluginManager.h" |
| 28 | #include "lldb/Core/StreamFile.h" |
| 29 | #include "lldb/Core/StreamString.h" |
| 30 | #include "lldb/Host/Host.h" |
| 31 | #include "lldb/Host/TimeValue.h" |
| 32 | #include "lldb/Host/Mutex.h" |
Caroline Tice | 926060e | 2010-10-29 21:48:37 +0000 | [diff] [blame] | 33 | #include "lldb/Interpreter/Args.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 34 | using namespace lldb; |
| 35 | using namespace lldb_private; |
| 36 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 37 | Log::Log () : |
| 38 | m_stream_sp(), |
| 39 | m_options(0), |
| 40 | m_mask_bits(0) |
| 41 | { |
| 42 | } |
| 43 | |
| 44 | Log::Log (StreamSP &stream_sp) : |
| 45 | m_stream_sp(stream_sp), |
| 46 | m_options(0), |
| 47 | m_mask_bits(0) |
| 48 | { |
| 49 | } |
| 50 | |
| 51 | Log::~Log () |
| 52 | { |
| 53 | } |
| 54 | |
| 55 | Flags & |
| 56 | Log::GetOptions() |
| 57 | { |
| 58 | return m_options; |
| 59 | } |
| 60 | |
| 61 | const Flags & |
| 62 | Log::GetOptions() const |
| 63 | { |
| 64 | return m_options; |
| 65 | } |
| 66 | |
| 67 | Flags & |
| 68 | Log::GetMask() |
| 69 | { |
| 70 | return m_mask_bits; |
| 71 | } |
| 72 | |
| 73 | const Flags & |
| 74 | Log::GetMask() const |
| 75 | { |
| 76 | return m_mask_bits; |
| 77 | } |
| 78 | |
| 79 | |
| 80 | //---------------------------------------------------------------------- |
| 81 | // All logging eventually boils down to this function call. If we have |
| 82 | // a callback registered, then we call the logging callback. If we have |
| 83 | // a valid file handle, we also log to the file. |
| 84 | //---------------------------------------------------------------------- |
| 85 | void |
| 86 | Log::PrintfWithFlagsVarArg (uint32_t flags, const char *format, va_list args) |
| 87 | { |
| 88 | if (m_stream_sp) |
| 89 | { |
| 90 | static uint32_t g_sequence_id = 0; |
| 91 | StreamString header; |
Greg Clayton | 940b103 | 2011-02-23 00:35:02 +0000 | [diff] [blame] | 92 | // Enabling the thread safe logging actually deadlocks right now. |
| 93 | // Need to fix this at some point. |
| 94 | // static Mutex g_LogThreadedMutex(Mutex::eMutexTypeRecursive); |
| 95 | // Mutex::Locker locker (g_LogThreadedMutex); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 96 | |
| 97 | // Add a sequence ID if requested |
Greg Clayton | f3d0b0c | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 98 | if (m_options.Test (LLDB_LOG_OPTION_PREPEND_SEQUENCE)) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 99 | header.Printf ("%u ", ++g_sequence_id); |
| 100 | |
| 101 | // Timestamp if requested |
Greg Clayton | f3d0b0c | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 102 | if (m_options.Test (LLDB_LOG_OPTION_PREPEND_TIMESTAMP)) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 103 | { |
| 104 | struct timeval tv = TimeValue::Now().GetAsTimeVal(); |
Daniel Malea | b9db9d5 | 2012-12-07 22:21:08 +0000 | [diff] [blame] | 105 | header.Printf ("%9ld.%6.6d ", tv.tv_sec, (int32_t)tv.tv_usec); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | // Add the process and thread if requested |
Greg Clayton | f3d0b0c | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 109 | if (m_options.Test (LLDB_LOG_OPTION_PREPEND_PROC_AND_THREAD)) |
Daniel Malea | 5f35a4b | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 110 | header.Printf ("[%4.4x/%4.4" PRIx64 "]: ", getpid(), Host::GetCurrentThreadID()); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 111 | |
| 112 | // Add the process and thread if requested |
Greg Clayton | f3d0b0c | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 113 | if (m_options.Test (LLDB_LOG_OPTION_PREPEND_THREAD_NAME)) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 114 | { |
Eli Friedman | 18cba0c | 2010-06-11 04:29:29 +0000 | [diff] [blame] | 115 | const char *thread_name_str = Host::GetThreadName (getpid(), Host::GetCurrentThreadID()); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 116 | if (thread_name_str) |
| 117 | header.Printf ("%s ", thread_name_str); |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 118 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | header.PrintfVarArg (format, args); |
| 122 | m_stream_sp->Printf("%s\n", header.GetData()); |
Greg Clayton | f737d37 | 2012-10-08 22:41:53 +0000 | [diff] [blame] | 123 | |
| 124 | if (m_options.Test (LLDB_LOG_OPTION_BACKTRACE)) |
| 125 | Host::Backtrace (*m_stream_sp, 1024); |
Jim Ingham | 6c530f2 | 2012-02-21 02:23:08 +0000 | [diff] [blame] | 126 | m_stream_sp->Flush(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 127 | } |
| 128 | } |
| 129 | |
| 130 | |
| 131 | void |
| 132 | Log::PutCString (const char *cstr) |
| 133 | { |
| 134 | Printf ("%s", cstr); |
| 135 | } |
| 136 | |
| 137 | |
| 138 | //---------------------------------------------------------------------- |
| 139 | // Simple variable argument logging with flags. |
| 140 | //---------------------------------------------------------------------- |
| 141 | void |
| 142 | Log::Printf(const char *format, ...) |
| 143 | { |
| 144 | va_list args; |
| 145 | va_start (args, format); |
| 146 | PrintfWithFlagsVarArg (0, format, args); |
| 147 | va_end (args); |
| 148 | } |
| 149 | |
| 150 | void |
| 151 | Log::VAPrintf (const char *format, va_list args) |
| 152 | { |
| 153 | PrintfWithFlagsVarArg (0, format, args); |
| 154 | } |
| 155 | |
| 156 | |
| 157 | //---------------------------------------------------------------------- |
| 158 | // Simple variable argument logging with flags. |
| 159 | //---------------------------------------------------------------------- |
| 160 | void |
| 161 | Log::PrintfWithFlags (uint32_t flags, const char *format, ...) |
| 162 | { |
| 163 | va_list args; |
| 164 | va_start (args, format); |
| 165 | PrintfWithFlagsVarArg (flags, format, args); |
| 166 | va_end (args); |
| 167 | } |
| 168 | |
| 169 | //---------------------------------------------------------------------- |
| 170 | // Print debug strings if and only if the global debug option is set to |
| 171 | // a non-zero value. |
| 172 | //---------------------------------------------------------------------- |
| 173 | void |
| 174 | Log::Debug (const char *format, ...) |
| 175 | { |
Greg Clayton | f3d0b0c | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 176 | if (GetOptions().Test(LLDB_LOG_OPTION_DEBUG)) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 177 | { |
| 178 | va_list args; |
| 179 | va_start (args, format); |
| 180 | PrintfWithFlagsVarArg (LLDB_LOG_FLAG_DEBUG, format, args); |
| 181 | va_end (args); |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | |
| 186 | //---------------------------------------------------------------------- |
| 187 | // Print debug strings if and only if the global debug option is set to |
| 188 | // a non-zero value. |
| 189 | //---------------------------------------------------------------------- |
| 190 | void |
| 191 | Log::DebugVerbose (const char *format, ...) |
| 192 | { |
Greg Clayton | f3d0b0c | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 193 | if (GetOptions().AllSet (LLDB_LOG_OPTION_DEBUG | LLDB_LOG_OPTION_VERBOSE)) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 194 | { |
| 195 | va_list args; |
| 196 | va_start (args, format); |
| 197 | PrintfWithFlagsVarArg (LLDB_LOG_FLAG_DEBUG | LLDB_LOG_FLAG_VERBOSE, format, args); |
| 198 | va_end (args); |
| 199 | } |
| 200 | } |
| 201 | |
| 202 | |
| 203 | //---------------------------------------------------------------------- |
| 204 | // Log only if all of the bits are set |
| 205 | //---------------------------------------------------------------------- |
| 206 | void |
| 207 | Log::LogIf (uint32_t bits, const char *format, ...) |
| 208 | { |
Greg Clayton | f3d0b0c | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 209 | if (m_options.AllSet (bits)) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 210 | { |
| 211 | va_list args; |
| 212 | va_start (args, format); |
| 213 | PrintfWithFlagsVarArg (0, format, args); |
| 214 | va_end (args); |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | |
| 219 | //---------------------------------------------------------------------- |
| 220 | // Printing of errors that are not fatal. |
| 221 | //---------------------------------------------------------------------- |
| 222 | void |
| 223 | Log::Error (const char *format, ...) |
| 224 | { |
| 225 | char *arg_msg = NULL; |
| 226 | va_list args; |
| 227 | va_start (args, format); |
| 228 | ::vasprintf (&arg_msg, format, args); |
| 229 | va_end (args); |
| 230 | |
| 231 | if (arg_msg != NULL) |
| 232 | { |
| 233 | PrintfWithFlags (LLDB_LOG_FLAG_ERROR, "error: %s", arg_msg); |
| 234 | free (arg_msg); |
| 235 | } |
| 236 | } |
| 237 | |
| 238 | //---------------------------------------------------------------------- |
| 239 | // Printing of errors that ARE fatal. Exit with ERR exit code |
| 240 | // immediately. |
| 241 | //---------------------------------------------------------------------- |
| 242 | void |
| 243 | Log::FatalError (int err, const char *format, ...) |
| 244 | { |
| 245 | char *arg_msg = NULL; |
| 246 | va_list args; |
| 247 | va_start (args, format); |
| 248 | ::vasprintf (&arg_msg, format, args); |
| 249 | va_end (args); |
| 250 | |
| 251 | if (arg_msg != NULL) |
| 252 | { |
| 253 | PrintfWithFlags (LLDB_LOG_FLAG_ERROR | LLDB_LOG_FLAG_FATAL, "error: %s", arg_msg); |
| 254 | ::free (arg_msg); |
| 255 | } |
| 256 | ::exit (err); |
| 257 | } |
| 258 | |
| 259 | |
| 260 | //---------------------------------------------------------------------- |
| 261 | // Printing of warnings that are not fatal only if verbose mode is |
| 262 | // enabled. |
| 263 | //---------------------------------------------------------------------- |
| 264 | void |
| 265 | Log::Verbose (const char *format, ...) |
| 266 | { |
Greg Clayton | f3d0b0c | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 267 | if (m_options.Test(LLDB_LOG_OPTION_VERBOSE)) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 268 | { |
| 269 | va_list args; |
| 270 | va_start (args, format); |
| 271 | PrintfWithFlagsVarArg (LLDB_LOG_FLAG_VERBOSE, format, args); |
| 272 | va_end (args); |
| 273 | } |
| 274 | } |
| 275 | |
| 276 | //---------------------------------------------------------------------- |
| 277 | // Printing of warnings that are not fatal only if verbose mode is |
| 278 | // enabled. |
| 279 | //---------------------------------------------------------------------- |
| 280 | void |
| 281 | Log::WarningVerbose (const char *format, ...) |
| 282 | { |
Greg Clayton | f3d0b0c | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 283 | if (m_options.Test(LLDB_LOG_OPTION_VERBOSE)) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 284 | { |
| 285 | char *arg_msg = NULL; |
| 286 | va_list args; |
| 287 | va_start (args, format); |
| 288 | ::vasprintf (&arg_msg, format, args); |
| 289 | va_end (args); |
| 290 | |
| 291 | if (arg_msg != NULL) |
| 292 | { |
| 293 | PrintfWithFlags (LLDB_LOG_FLAG_WARNING | LLDB_LOG_FLAG_VERBOSE, "warning: %s", arg_msg); |
| 294 | free (arg_msg); |
| 295 | } |
| 296 | } |
| 297 | } |
| 298 | //---------------------------------------------------------------------- |
| 299 | // Printing of warnings that are not fatal. |
| 300 | //---------------------------------------------------------------------- |
| 301 | void |
| 302 | Log::Warning (const char *format, ...) |
| 303 | { |
| 304 | char *arg_msg = NULL; |
| 305 | va_list args; |
| 306 | va_start (args, format); |
| 307 | ::vasprintf (&arg_msg, format, args); |
| 308 | va_end (args); |
| 309 | |
| 310 | if (arg_msg != NULL) |
| 311 | { |
| 312 | PrintfWithFlags (LLDB_LOG_FLAG_WARNING, "warning: %s", arg_msg); |
| 313 | free (arg_msg); |
| 314 | } |
| 315 | } |
| 316 | |
| 317 | typedef std::map <std::string, Log::Callbacks> CallbackMap; |
| 318 | typedef CallbackMap::iterator CallbackMapIter; |
| 319 | |
| 320 | typedef std::map <ConstString, LogChannelSP> LogChannelMap; |
| 321 | typedef LogChannelMap::iterator LogChannelMapIter; |
| 322 | |
| 323 | |
| 324 | // Surround our callback map with a singleton function so we don't have any |
| 325 | // global initializers. |
| 326 | static CallbackMap & |
| 327 | GetCallbackMap () |
| 328 | { |
| 329 | static CallbackMap g_callback_map; |
| 330 | return g_callback_map; |
| 331 | } |
| 332 | |
| 333 | static LogChannelMap & |
| 334 | GetChannelMap () |
| 335 | { |
| 336 | static LogChannelMap g_channel_map; |
| 337 | return g_channel_map; |
| 338 | } |
| 339 | |
| 340 | void |
| 341 | Log::RegisterLogChannel (const char *channel, const Log::Callbacks &log_callbacks) |
| 342 | { |
| 343 | GetCallbackMap().insert(std::make_pair(channel, log_callbacks)); |
| 344 | } |
| 345 | |
| 346 | bool |
| 347 | Log::UnregisterLogChannel (const char *channel) |
| 348 | { |
| 349 | return GetCallbackMap().erase(channel) != 0; |
| 350 | } |
| 351 | |
| 352 | bool |
| 353 | Log::GetLogChannelCallbacks (const char *channel, Log::Callbacks &log_callbacks) |
| 354 | { |
| 355 | CallbackMap &callback_map = GetCallbackMap (); |
| 356 | CallbackMapIter pos = callback_map.find(channel); |
| 357 | if (pos != callback_map.end()) |
| 358 | { |
| 359 | log_callbacks = pos->second; |
| 360 | return true; |
| 361 | } |
Greg Clayton | ddff7cc | 2011-02-04 21:13:05 +0000 | [diff] [blame] | 362 | ::memset (&log_callbacks, 0, sizeof(log_callbacks)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 363 | return false; |
| 364 | } |
| 365 | |
| 366 | void |
| 367 | Log::EnableAllLogChannels |
| 368 | ( |
| 369 | StreamSP &log_stream_sp, |
| 370 | uint32_t log_options, |
Jim Ingham | 6c530f2 | 2012-02-21 02:23:08 +0000 | [diff] [blame] | 371 | const char **categories, |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 372 | Stream *feedback_strm |
| 373 | ) |
| 374 | { |
| 375 | CallbackMap &callback_map = GetCallbackMap (); |
| 376 | CallbackMapIter pos, end = callback_map.end(); |
| 377 | |
| 378 | for (pos = callback_map.begin(); pos != end; ++pos) |
Jim Ingham | 6c530f2 | 2012-02-21 02:23:08 +0000 | [diff] [blame] | 379 | pos->second.enable (log_stream_sp, log_options, categories, feedback_strm); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 380 | |
| 381 | LogChannelMap &channel_map = GetChannelMap (); |
| 382 | LogChannelMapIter channel_pos, channel_end = channel_map.end(); |
| 383 | for (channel_pos = channel_map.begin(); channel_pos != channel_end; ++channel_pos) |
| 384 | { |
Jim Ingham | 6c530f2 | 2012-02-21 02:23:08 +0000 | [diff] [blame] | 385 | channel_pos->second->Enable (log_stream_sp, log_options, feedback_strm, categories); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 386 | } |
| 387 | |
| 388 | } |
| 389 | |
| 390 | void |
Greg Clayton | 5e342f5 | 2011-04-13 22:47:15 +0000 | [diff] [blame] | 391 | Log::AutoCompleteChannelName (const char *channel_name, StringList &matches) |
| 392 | { |
| 393 | LogChannelMap &map = GetChannelMap (); |
| 394 | LogChannelMapIter pos, end = map.end(); |
| 395 | for (pos = map.begin(); pos != end; ++pos) |
| 396 | { |
| 397 | const char *pos_channel_name = pos->first.GetCString(); |
| 398 | if (channel_name && channel_name[0]) |
| 399 | { |
| 400 | if (NameMatches (channel_name, eNameMatchStartsWith, pos_channel_name)) |
| 401 | { |
| 402 | matches.AppendString(pos_channel_name); |
| 403 | } |
| 404 | } |
| 405 | else |
| 406 | matches.AppendString(pos_channel_name); |
| 407 | |
| 408 | } |
| 409 | } |
| 410 | |
| 411 | void |
Caroline Tice | 926060e | 2010-10-29 21:48:37 +0000 | [diff] [blame] | 412 | Log::DisableAllLogChannels (Stream *feedback_strm) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 413 | { |
| 414 | CallbackMap &callback_map = GetCallbackMap (); |
| 415 | CallbackMapIter pos, end = callback_map.end(); |
Jim Ingham | 6c530f2 | 2012-02-21 02:23:08 +0000 | [diff] [blame] | 416 | const char *categories[1] = {NULL}; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 417 | |
| 418 | for (pos = callback_map.begin(); pos != end; ++pos) |
Jim Ingham | 6c530f2 | 2012-02-21 02:23:08 +0000 | [diff] [blame] | 419 | pos->second.disable (categories, feedback_strm); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 420 | |
| 421 | LogChannelMap &channel_map = GetChannelMap (); |
| 422 | LogChannelMapIter channel_pos, channel_end = channel_map.end(); |
| 423 | for (channel_pos = channel_map.begin(); channel_pos != channel_end; ++channel_pos) |
Jim Ingham | 6c530f2 | 2012-02-21 02:23:08 +0000 | [diff] [blame] | 424 | channel_pos->second->Disable (categories, feedback_strm); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 425 | } |
| 426 | |
| 427 | void |
Greg Clayton | 990de7b | 2010-11-18 23:32:35 +0000 | [diff] [blame] | 428 | Log::Initialize() |
| 429 | { |
| 430 | Log::Callbacks log_callbacks = { DisableLog, EnableLog, ListLogCategories }; |
| 431 | Log::RegisterLogChannel ("lldb", log_callbacks); |
| 432 | } |
| 433 | |
| 434 | void |
| 435 | Log::Terminate () |
| 436 | { |
| 437 | DisableAllLogChannels (NULL); |
| 438 | } |
| 439 | |
| 440 | void |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 441 | Log::ListAllLogChannels (Stream *strm) |
| 442 | { |
| 443 | CallbackMap &callback_map = GetCallbackMap (); |
| 444 | LogChannelMap &channel_map = GetChannelMap (); |
| 445 | |
| 446 | if (callback_map.empty() && channel_map.empty()) |
| 447 | { |
| 448 | strm->PutCString ("No logging channels are currently registered.\n"); |
| 449 | return; |
| 450 | } |
| 451 | |
| 452 | CallbackMapIter pos, end = callback_map.end(); |
| 453 | for (pos = callback_map.begin(); pos != end; ++pos) |
| 454 | pos->second.list_categories (strm); |
| 455 | |
| 456 | uint32_t idx = 0; |
| 457 | const char *name; |
| 458 | for (idx = 0; (name = PluginManager::GetLogChannelCreateNameAtIndex (idx)) != NULL; ++idx) |
| 459 | { |
| 460 | LogChannelSP log_channel_sp(LogChannel::FindPlugin (name)); |
| 461 | if (log_channel_sp) |
| 462 | log_channel_sp->ListCategories (strm); |
| 463 | } |
| 464 | } |
| 465 | |
| 466 | bool |
| 467 | Log::GetVerbose() const |
| 468 | { |
Jim Ingham | 931851c | 2011-01-22 01:24:30 +0000 | [diff] [blame] | 469 | // FIXME: This has to be centralized between the stream and the log... |
| 470 | if (m_options.Test(LLDB_LOG_OPTION_VERBOSE)) |
| 471 | return true; |
| 472 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 473 | if (m_stream_sp) |
| 474 | return m_stream_sp->GetVerbose(); |
| 475 | return false; |
| 476 | } |
| 477 | |
| 478 | //------------------------------------------------------------------ |
| 479 | // Returns true if the debug flag bit is set in this stream. |
| 480 | //------------------------------------------------------------------ |
| 481 | bool |
| 482 | Log::GetDebug() const |
| 483 | { |
| 484 | if (m_stream_sp) |
| 485 | return m_stream_sp->GetDebug(); |
| 486 | return false; |
| 487 | } |
| 488 | |
| 489 | |
| 490 | LogChannelSP |
| 491 | LogChannel::FindPlugin (const char *plugin_name) |
| 492 | { |
| 493 | LogChannelSP log_channel_sp; |
| 494 | LogChannelMap &channel_map = GetChannelMap (); |
| 495 | ConstString log_channel_name (plugin_name); |
| 496 | LogChannelMapIter pos = channel_map.find (log_channel_name); |
| 497 | if (pos == channel_map.end()) |
| 498 | { |
| 499 | LogChannelCreateInstance create_callback = PluginManager::GetLogChannelCreateCallbackForPluginName (plugin_name); |
| 500 | if (create_callback) |
| 501 | { |
| 502 | log_channel_sp.reset(create_callback()); |
| 503 | if (log_channel_sp) |
| 504 | { |
| 505 | // Cache the one and only loaded instance of each log channel |
| 506 | // plug-in after it has been loaded once. |
| 507 | channel_map[log_channel_name] = log_channel_sp; |
| 508 | } |
| 509 | } |
| 510 | } |
| 511 | else |
| 512 | { |
| 513 | // We have already loaded an instance of this log channel class, |
| 514 | // so just return the cached instance. |
| 515 | log_channel_sp = pos->second; |
| 516 | } |
| 517 | return log_channel_sp; |
| 518 | } |
| 519 | |
| 520 | LogChannel::LogChannel () : |
| 521 | m_log_sp () |
| 522 | { |
| 523 | } |
| 524 | |
| 525 | LogChannel::~LogChannel () |
| 526 | { |
| 527 | } |
| 528 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 529 | |