Files
clang-p2996/lldb/source/Utility/Logging.cpp
Pavel Labath 0f08db66db [lldb] Make logging machinery type-safe
This patch makes use of c++ type checking and scoped enums to make
logging statements shorter and harder to misuse.

Defines like LIBLLDB_LOG_PROCESS are replaces with LLDBLog::Process.
Because it now carries type information we do not need to worry about
matching a specific enum value with the right getter function -- the
compiler will now do that for us.

The main entry point for the logging machinery becomes the GetLog
(template) function, which will obtain the correct Log object based on
the enum type. It achieves this through another template function
(LogChannelFor<T>), which must be specialized for each type, and should
return the appropriate channel object.

This patch also removes the ability to log a message if multiple
categories are enabled simultaneously as it was unused and confusing.

This patch does not actually remove any of the existing interfaces. The
defines and log retrieval functions are left around as wrappers around
the new interfaces. They will be removed in follow-up patch.

Differential Revision: https://reviews.llvm.org/D117490
2022-01-25 12:13:49 +01:00

90 lines
3.7 KiB
C++

//===-- Logging.cpp -------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "lldb/Utility/Logging.h"
#include "lldb/Utility/Log.h"
#include "llvm/ADT/ArrayRef.h"
#include <cstdarg>
using namespace lldb_private;
static constexpr Log::Category g_categories[] = {
{{"api"}, {"log API calls and return values"}, LLDBLog::API},
{{"ast"}, {"log AST"}, LLDBLog::AST},
{{"break"}, {"log breakpoints"}, LLDBLog::Breakpoints},
{{"commands"}, {"log command argument parsing"}, LLDBLog::Commands},
{{"comm"}, {"log communication activities"}, LLDBLog::Communication},
{{"conn"}, {"log connection details"}, LLDBLog::Connection},
{{"demangle"},
{"log mangled names to catch demangler crashes"},
LLDBLog::Demangle},
{{"dyld"},
{"log shared library related activities"},
LLDBLog::DynamicLoader},
{{"event"},
{"log broadcaster, listener and event queue activities"},
LLDBLog::Events},
{{"expr"}, {"log expressions"}, LLDBLog::Expressions},
{{"formatters"},
{"log data formatters related activities"},
LLDBLog::DataFormatters},
{{"host"}, {"log host activities"}, LLDBLog::Host},
{{"jit"}, {"log JIT events in the target"}, LLDBLog::JITLoader},
{{"language"}, {"log language runtime events"}, LLDBLog::Language},
{{"mmap"}, {"log mmap related activities"}, LLDBLog::MMap},
{{"module"},
{"log module activities such as when modules are created, destroyed, "
"replaced, and more"},
LLDBLog::Modules},
{{"object"},
{"log object construction/destruction for important objects"},
LLDBLog::Object},
{{"os"}, {"log OperatingSystem plugin related activities"}, LLDBLog::OS},
{{"platform"}, {"log platform events and activities"}, LLDBLog::Platform},
{{"process"}, {"log process events and activities"}, LLDBLog::Process},
{{"script"}, {"log events about the script interpreter"}, LLDBLog::Script},
{{"state"},
{"log private and public process state changes"},
LLDBLog::State},
{{"step"}, {"log step related activities"}, LLDBLog::Step},
{{"symbol"}, {"log symbol related issues and warnings"}, LLDBLog::Symbols},
{{"system-runtime"}, {"log system runtime events"}, LLDBLog::SystemRuntime},
{{"target"}, {"log target events and activities"}, LLDBLog::Target},
{{"temp"}, {"log internal temporary debug messages"}, LLDBLog::Temporary},
{{"thread"}, {"log thread events and activities"}, LLDBLog::Thread},
{{"types"}, {"log type system related activities"}, LLDBLog::Types},
{{"unwind"}, {"log stack unwind activities"}, LLDBLog::Unwind},
{{"watch"}, {"log watchpoint related activities"}, LLDBLog::Watchpoints},
};
static Log::Channel g_log_channel(g_categories,
LLDBLog::Process | LLDBLog::Thread |
LLDBLog::DynamicLoader |
LLDBLog::Breakpoints |
LLDBLog::Watchpoints | LLDBLog::Step |
LLDBLog::State | LLDBLog::Symbols |
LLDBLog::Target | LLDBLog::Commands);
template <> Log::Channel &lldb_private::LogChannelFor<LLDBLog>() {
return g_log_channel;
}
void lldb_private::InitializeLldbChannel() {
Log::Register("lldb", g_log_channel);
}
Log *lldb_private::GetLogIfAllCategoriesSet(LLDBLog mask) {
return GetLog(mask);
}
Log *lldb_private::GetLogIfAnyCategoriesSet(LLDBLog mask) {
return GetLog(mask);
}