blob: bb2d9f3c2180de83ef9931c95ae0d52913c1432a [file] [log] [blame]
Alexander Shaposhnikov696bd632016-11-26 05:23:44 +00001//===-- Logging.cpp ---------------------------------------------*- C++ -*-===//
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002//
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
Zachary Turner6f9e6902017-03-03 20:56:28 +000010#include "lldb/Utility/Logging.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000011
12// C Includes
13// C++ Includes
Zachary Turner4171da52014-09-19 20:12:32 +000014#include <atomic>
Kate Stoneb9c1b512016-09-06 20:57:50 +000015#include <cstring>
Eugene Zelenko89183722016-03-11 21:55:47 +000016
Chris Lattner30fdc8d2010-06-08 16:52:24 +000017// Other libraries and framework includes
18// Project includes
Zachary Turner6f9e6902017-03-03 20:56:28 +000019#include "lldb/Utility/Log.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000020
21using namespace lldb;
22using namespace lldb_private;
23
Pavel Labatha2fc1e02017-02-22 11:51:12 +000024static constexpr Log::Category g_categories[] = {
25 {{"api"}, {"log API calls and return values"}, LIBLLDB_LOG_API},
26 {{"break"}, {"log breakpoints"}, LIBLLDB_LOG_BREAKPOINTS},
27 {{"commands"}, {"log command argument parsing"}, LIBLLDB_LOG_COMMANDS},
28 {{"comm"}, {"log communication activities"}, LIBLLDB_LOG_COMMUNICATION},
29 {{"conn"}, {"log connection details"}, LIBLLDB_LOG_CONNECTION},
30 {{"demangle"}, {"log mangled names to catch demangler crashes"}, LIBLLDB_LOG_DEMANGLE},
31 {{"dyld"}, {"log shared library related activities"}, LIBLLDB_LOG_DYNAMIC_LOADER},
32 {{"event"}, {"log broadcaster, listener and event queue activities"}, LIBLLDB_LOG_EVENTS},
33 {{"expr"}, {"log expressions"}, LIBLLDB_LOG_EXPRESSIONS},
34 {{"formatters"}, {"log data formatters related activities"}, LIBLLDB_LOG_DATAFORMATTERS},
35 {{"host"}, {"log host activities"}, LIBLLDB_LOG_HOST},
36 {{"jit"}, {"log JIT events in the target"}, LIBLLDB_LOG_JIT_LOADER},
37 {{"language"}, {"log language runtime events"}, LIBLLDB_LOG_LANGUAGE},
38 {{"mmap"}, {"log mmap related activities"}, LIBLLDB_LOG_MMAP},
39 {{"module"}, {"log module activities such as when modules are created, destroyed, replaced, and more"}, LIBLLDB_LOG_MODULES},
40 {{"object"}, {"log object construction/destruction for important objects"}, LIBLLDB_LOG_OBJECT},
41 {{"os"}, {"log OperatingSystem plugin related activities"}, LIBLLDB_LOG_OS},
42 {{"platform"}, {"log platform events and activities"}, LIBLLDB_LOG_PLATFORM},
43 {{"process"}, {"log process events and activities"}, LIBLLDB_LOG_PROCESS},
44 {{"script"}, {"log events about the script interpreter"}, LIBLLDB_LOG_SCRIPT},
45 {{"state"}, {"log private and public process state changes"}, LIBLLDB_LOG_STATE},
46 {{"step"}, {"log step related activities"}, LIBLLDB_LOG_STEP},
47 {{"symbol"}, {"log symbol related issues and warnings"}, LIBLLDB_LOG_SYMBOLS},
48 {{"system-runtime"}, {"log system runtime events"}, LIBLLDB_LOG_SYSTEM_RUNTIME},
49 {{"target"}, {"log target events and activities"}, LIBLLDB_LOG_TARGET},
50 {{"thread"}, {"log thread events and activities"}, LIBLLDB_LOG_THREAD},
51 {{"types"}, {"log type system related activities"}, LIBLLDB_LOG_TYPES},
52 {{"unwind"}, {"log stack unwind activities"}, LIBLLDB_LOG_UNWIND},
53 {{"watch"}, {"log watchpoint related activities"}, LIBLLDB_LOG_WATCHPOINTS},
54};
Greg Clayton5160ce52013-03-27 23:08:40 +000055
Pavel Labatha2fc1e02017-02-22 11:51:12 +000056static Log::Channel g_log_channel(g_categories, LIBLLDB_LOG_DEFAULT);
Eugene Zelenko89183722016-03-11 21:55:47 +000057
Pavel Labatha2fc1e02017-02-22 11:51:12 +000058void lldb_private::InitializeLog() {
59 Log::Register("lldb", g_log_channel);
Kate Stoneb9c1b512016-09-06 20:57:50 +000060}
Chris Lattner30fdc8d2010-06-08 16:52:24 +000061
Kate Stoneb9c1b512016-09-06 20:57:50 +000062Log *lldb_private::GetLogIfAllCategoriesSet(uint32_t mask) {
Pavel Labatha2fc1e02017-02-22 11:51:12 +000063 return g_log_channel.GetLogIfAll(mask);
Kate Stoneb9c1b512016-09-06 20:57:50 +000064}
65
66Log *lldb_private::GetLogIfAnyCategoriesSet(uint32_t mask) {
Pavel Labatha2fc1e02017-02-22 11:51:12 +000067 return g_log_channel.GetLogIfAny(mask);
Kate Stoneb9c1b512016-09-06 20:57:50 +000068}
69
Kate Stoneb9c1b512016-09-06 20:57:50 +000070
Pavel Labatha2fc1e02017-02-22 11:51:12 +000071void lldb_private::LogIfAnyCategoriesSet(uint32_t mask, const char *format, ...) {
72 if (Log *log = GetLogIfAnyCategoriesSet(mask)) {
73 va_list args;
74 va_start(args, format);
75 log->VAPrintf(format, args);
76 va_end(args);
Kate Stoneb9c1b512016-09-06 20:57:50 +000077 }
Caroline Tice20ad3c42010-10-29 21:48:37 +000078}