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
48 lines
1.5 KiB
C++
48 lines
1.5 KiB
C++
//===-- ProcessPOSIXLog.h -----------------------------------------*- C++
|
|
//-*-===//
|
|
//
|
|
// 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
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef liblldb_ProcessPOSIXLog_h_
|
|
#define liblldb_ProcessPOSIXLog_h_
|
|
|
|
|
|
#include "lldb/Utility/Log.h"
|
|
|
|
namespace lldb_private {
|
|
|
|
enum class POSIXLog : Log::MaskType {
|
|
Breakpoints = Log::ChannelFlag<0>,
|
|
Memory = Log::ChannelFlag<1>,
|
|
Process = Log::ChannelFlag<2>,
|
|
Ptrace = Log::ChannelFlag<3>,
|
|
Registers = Log::ChannelFlag<4>,
|
|
Thread = Log::ChannelFlag<5>,
|
|
Watchpoints = Log::ChannelFlag<6>,
|
|
LLVM_MARK_AS_BITMASK_ENUM(Watchpoints)
|
|
};
|
|
|
|
#define POSIX_LOG_PROCESS ::lldb_private::POSIXLog::Process
|
|
#define POSIX_LOG_THREAD ::lldb_private::POSIXLog::Thread
|
|
#define POSIX_LOG_MEMORY ::lldb_private::POSIXLog::Memory
|
|
#define POSIX_LOG_PTRACE ::lldb_private::POSIXLog::Ptrace
|
|
#define POSIX_LOG_REGISTERS ::lldb_private::POSIXLog::Registers
|
|
#define POSIX_LOG_BREAKPOINTS ::lldb_private::POSIXLog::Breakpoints
|
|
#define POSIX_LOG_WATCHPOINTS ::lldb_private::POSIXLog::Watchpoints
|
|
|
|
class ProcessPOSIXLog {
|
|
public:
|
|
static void Initialize();
|
|
|
|
static Log *GetLogIfAllCategoriesSet(POSIXLog mask) { return GetLog(mask); }
|
|
};
|
|
|
|
template <> Log::Channel &LogChannelFor<POSIXLog>();
|
|
} // namespace lldb_private
|
|
|
|
#endif // liblldb_ProcessPOSIXLog_h_
|