LLDB mainline
lldb_private::Log Class Referencefinal

#include <Log.h>

Classes

struct  Category
class  Channel

Public Types

using MaskType = uint64_t
 The underlying type of all log channel enums.

Public Member Functions

 Log (Channel &channel)
 ~Log ()=default
void PutCString (const char *cstr)
void PutString (llvm::StringRef str)
template<typename... Args>
void Format (llvm::StringRef file, llvm::StringRef function, const char *format, Args &&... args)
template<typename... Args>
void FormatError (llvm::Error error, llvm::StringRef file, llvm::StringRef function, const char *format, Args &&... args)
void Formatf (llvm::StringRef file, llvm::StringRef function, const char *format,...) __attribute__((format(printf
void void Printf (const char *format,...) __attribute__((format(printf
 Prefer using LLDB_LOGF whenever possible.
void void void Verbose (const char *fmt,...) __attribute__((format(printf
void void void const Flags GetOptions () const
MaskType GetMask () const
bool GetVerbose () const
void VAPrintf (const char *format, va_list args)
void VAFormatf (llvm::StringRef file, llvm::StringRef function, const char *format, va_list args)
void Enable (const std::shared_ptr< LogHandler > &handler_sp, std::optional< MaskType > flags=std::nullopt, uint32_t options=0)
void Disable (std::optional< MaskType > flags=std::nullopt)

Static Public Member Functions

static void Register (llvm::StringRef name, Channel &channel)
static void Unregister (llvm::StringRef name)
static llvm::Error EnableLogChannel (const std::shared_ptr< LogHandler > &log_handler_sp, uint32_t log_options, llvm::StringRef channel, llvm::ArrayRef< const char * > categories)
static bool DisableLogChannel (llvm::StringRef channel, llvm::ArrayRef< const char * > categories, llvm::raw_ostream &error_stream)
static bool DumpLogChannel (llvm::StringRef channel, llvm::raw_ostream &output_stream, llvm::raw_ostream &error_stream)
static bool ListChannelCategories (llvm::StringRef channel, llvm::raw_ostream &stream)
static std::vector< llvm::StringRef > ListChannels ()
 Returns the list of log channels.
static void ForEachChannelCategory (llvm::StringRef channel, llvm::function_ref< void(llvm::StringRef, llvm::StringRef)> lambda)
 Calls the given lambda for every category in the given channel.
static void DisableAllLogChannels ()
static void ListAllLogChannels (llvm::raw_ostream &stream)

Static Public Attributes

template<MaskType Bit>
static constexpr MaskType ChannelFlag = MaskType(1) << Bit

Private Types

typedef llvm::StringMap< LogChannelMap

Private Member Functions

void WriteHeader (llvm::raw_ostream &OS, llvm::StringRef file, llvm::StringRef function)
void WriteJSONHeader (llvm::json::Object &obj, llvm::StringRef file, llvm::StringRef function)
void WriteMessage (llvm::StringRef message)
void EmitJSONMessage (llvm::StringRef file, llvm::StringRef function, llvm::StringRef message)
void Format (llvm::StringRef file, llvm::StringRef function, const llvm::formatv_object_base &payload)
std::shared_ptr< LogHandlerGetHandler ()
bool Dump (llvm::raw_ostream &stream)
 Log (const Log &)=delete
void operator= (const Log &)=delete

Static Private Member Functions

static void ForEachCategory (const Log::ChannelMap::value_type &entry, llvm::function_ref< void(llvm::StringRef, llvm::StringRef)> lambda)
static void ListCategories (llvm::raw_ostream &stream, const ChannelMap::value_type &entry)
static llvm::Expected< Log::MaskTypeGetFlags (const ChannelMap::value_type &entry, llvm::ArrayRef< const char * > categories)
 Convert an array of category names into a set of category flags.

Private Attributes

Channelm_channel
llvm::sys::RWMutex m_mutex
std::shared_ptr< LogHandlerm_handler
std::atomic< uint32_t > m_options {0}
std::atomic< MaskTypem_mask {0}

Static Private Attributes

static llvm::ManagedStatic< ChannelMapg_channel_map

Detailed Description

Definition at line 136 of file Log.h.

Member Typedef Documentation

◆ ChannelMap

typedef llvm::StringMap<Log> lldb_private::Log::ChannelMap
private

Definition at line 310 of file Log.h.

◆ MaskType

using lldb_private::Log::MaskType = uint64_t

The underlying type of all log channel enums.

Declare them as: enum class MyLog : MaskType { Channel0 = Log::ChannelFlag<0>, Channel1 = Log::ChannelFlag<1>, ..., LLVM_MARK_AS_BITMASK_ENUM(LastChannel), };

Definition at line 145 of file Log.h.

Constructor & Destructor Documentation

◆ Log() [1/2]

lldb_private::Log::Log ( Channel & channel)
inline

Definition at line 234 of file Log.h.

References m_channel.

Referenced by Log(), and operator=().

◆ ~Log()

lldb_private::Log::~Log ( )
default

◆ Log() [2/2]

lldb_private::Log::Log ( const Log & )
privatedelete

References Log().

Member Function Documentation

◆ Disable()

void Log::Disable ( std::optional< MaskType > flags = std::nullopt)

Definition at line 131 of file Log.cpp.

References m_channel, m_handler, m_mask, and m_mutex.

◆ DisableAllLogChannels()

void Log::DisableAllLogChannels ( )
static

◆ DisableLogChannel()

bool Log::DisableLogChannel ( llvm::StringRef channel,
llvm::ArrayRef< const char * > categories,
llvm::raw_ostream & error_stream )
static

Definition at line 250 of file Log.cpp.

References g_channel_map, GetFlags(), and lldb_private::toString().

Referenced by CommandObjectLogDisable::DoExecute().

◆ Dump()

bool Log::Dump ( llvm::raw_ostream & stream)
private

Definition at line 144 of file Log.cpp.

References m_handler, and m_mutex.

◆ DumpLogChannel()

bool Log::DumpLogChannel ( llvm::StringRef channel,
llvm::raw_ostream & output_stream,
llvm::raw_ostream & error_stream )
static

Definition at line 274 of file Log.cpp.

References g_channel_map.

Referenced by CommandObjectLogDump::DoExecute().

◆ EmitJSONMessage()

void Log::EmitJSONMessage ( llvm::StringRef file,
llvm::StringRef function,
llvm::StringRef message )
private

Definition at line 441 of file Log.cpp.

References WriteJSONHeader(), and WriteMessage().

Referenced by Format(), and PutString().

◆ Enable()

void Log::Enable ( const std::shared_ptr< LogHandler > & handler_sp,
std::optional< MaskType > flags = std::nullopt,
uint32_t options = 0 )

Definition at line 116 of file Log.cpp.

References m_channel, m_handler, m_mask, m_mutex, and m_options.

◆ EnableLogChannel()

llvm::Error Log::EnableLogChannel ( const std::shared_ptr< LogHandler > & log_handler_sp,
uint32_t log_options,
llvm::StringRef channel,
llvm::ArrayRef< const char * > categories )
static

Definition at line 230 of file Log.cpp.

References g_channel_map, and GetFlags().

Referenced by lldb_private::Debugger::EnableLog().

◆ ForEachCategory()

void Log::ForEachCategory ( const Log::ChannelMap::value_type & entry,
llvm::function_ref< void(llvm::StringRef, llvm::StringRef)> lambda )
staticprivate

Definition at line 57 of file Log.cpp.

Referenced by ForEachChannelCategory(), and ListCategories().

◆ ForEachChannelCategory()

void Log::ForEachChannelCategory ( llvm::StringRef channel,
llvm::function_ref< void(llvm::StringRef, llvm::StringRef)> lambda )
static

Calls the given lambda for every category in the given channel.

If no channel with the given name exists, lambda is never called.

Definition at line 306 of file Log.cpp.

References ForEachCategory(), and g_channel_map.

Referenced by CompleteEnableDisable().

◆ Format() [1/2]

template<typename... Args>
void lldb_private::Log::Format ( llvm::StringRef file,
llvm::StringRef function,
const char * format,
Args &&... args )
inline

Definition at line 241 of file Log.h.

References Format().

Referenced by Format(), FormatError(), and VAFormatf().

◆ Format() [2/2]

void Log::Format ( llvm::StringRef file,
llvm::StringRef function,
const llvm::formatv_object_base & payload )
private

◆ FormatError()

template<typename... Args>
void lldb_private::Log::FormatError ( llvm::Error error,
llvm::StringRef file,
llvm::StringRef function,
const char * format,
Args &&... args )
inline

Definition at line 247 of file Log.h.

References error(), and Format().

◆ Formatf()

void Log::Formatf ( llvm::StringRef file,
llvm::StringRef function,
const char * format,
... )

Definition at line 190 of file Log.cpp.

References VAFormatf().

◆ GetFlags()

llvm::Expected< Log::MaskType > Log::GetFlags ( const ChannelMap::value_type & entry,
llvm::ArrayRef< const char * > categories )
staticprivate

Convert an array of category names into a set of category flags.

Returns a bitmask of categories, or an error message in the case that at least one category name was not recognised. All unknown category names are included in the error.

Definition at line 76 of file Log.cpp.

References ListCategories().

Referenced by DisableLogChannel(), and EnableLogChannel().

◆ GetHandler()

std::shared_ptr< LogHandler > lldb_private::Log::GetHandler ( )
inlineprivate

Definition at line 303 of file Log.h.

References m_handler, and m_mutex.

Referenced by WriteMessage().

◆ GetMask()

Log::MaskType Log::GetMask ( ) const

Definition at line 158 of file Log.cpp.

References m_mask.

Referenced by lldb_private::Log::Channel::GetLog().

◆ GetOptions()

const Flags Log::GetOptions ( ) const

Definition at line 154 of file Log.cpp.

References m_options.

Referenced by Format(), PutString(), WriteHeader(), and WriteJSONHeader().

◆ GetVerbose()

bool Log::GetVerbose ( ) const

◆ ListAllLogChannels()

void Log::ListAllLogChannels ( llvm::raw_ostream & stream)
static

Definition at line 323 of file Log.cpp.

References g_channel_map, and ListCategories().

Referenced by CommandObjectLogList::DoExecute().

◆ ListCategories()

void Log::ListCategories ( llvm::raw_ostream & stream,
const ChannelMap::value_type & entry )
staticprivate

Definition at line 66 of file Log.cpp.

References ForEachCategory().

Referenced by GetFlags(), ListAllLogChannels(), and ListChannelCategories().

◆ ListChannelCategories()

bool Log::ListChannelCategories ( llvm::StringRef channel,
llvm::raw_ostream & stream )
static

Definition at line 290 of file Log.cpp.

References g_channel_map, and ListCategories().

Referenced by CommandObjectLogList::DoExecute().

◆ ListChannels()

std::vector< llvm::StringRef > Log::ListChannels ( )
static

Returns the list of log channels.

Definition at line 316 of file Log.cpp.

References g_channel_map.

Referenced by CompleteEnableDisable(), and CommandObjectLogList::HandleArgumentCompletion().

◆ operator=()

void lldb_private::Log::operator= ( const Log & )
privatedelete

References Log().

◆ Printf()

void Log::Printf ( const char * format,
... )

Prefer using LLDB_LOGF whenever possible.

Definition at line 177 of file Log.cpp.

References VAPrintf().

Referenced by ProcessMachCore::LoadBinariesViaMetadata(), ObjectFileMachO::LoadCoreFileImages(), and lldb_private::formatters::NSNumberSummaryProvider().

◆ PutCString()

◆ PutString()

◆ Register()

◆ Unregister()

◆ VAFormatf()

void Log::VAFormatf ( llvm::StringRef file,
llvm::StringRef function,
const char * format,
va_list args )

Definition at line 198 of file Log.cpp.

References Format(), and lldb_private::VASprintf().

Referenced by Formatf().

◆ VAPrintf()

void Log::VAPrintf ( const char * format,
va_list args )

Definition at line 184 of file Log.cpp.

References PutString(), and lldb_private::VASprintf().

Referenced by Printf(), and Verbose().

◆ Verbose()

void Log::Verbose ( const char * fmt,
... )

Definition at line 206 of file Log.cpp.

References GetVerbose(), and VAPrintf().

◆ WriteHeader()

◆ WriteJSONHeader()

void Log::WriteJSONHeader ( llvm::json::Object & obj,
llvm::StringRef file,
llvm::StringRef function )
private

◆ WriteMessage()

void Log::WriteMessage ( llvm::StringRef message)
private

Definition at line 419 of file Log.cpp.

References GetHandler().

Referenced by EmitJSONMessage(), Format(), and PutString().

Member Data Documentation

◆ ChannelFlag

template<MaskType Bit>
MaskType lldb_private::Log::ChannelFlag = MaskType(1) << Bit
staticconstexpr

Definition at line 148 of file Log.h.

◆ g_channel_map

◆ m_channel

Channel& lldb_private::Log::m_channel
private

Definition at line 280 of file Log.h.

Referenced by Disable(), Enable(), and Log().

◆ m_handler

std::shared_ptr<LogHandler> lldb_private::Log::m_handler
private

Definition at line 288 of file Log.h.

Referenced by Disable(), Dump(), Enable(), and GetHandler().

◆ m_mask

std::atomic<MaskType> lldb_private::Log::m_mask {0}
private

Definition at line 290 of file Log.h.

Referenced by Disable(), Enable(), and GetMask().

◆ m_mutex

llvm::sys::RWMutex lldb_private::Log::m_mutex
private

Definition at line 286 of file Log.h.

Referenced by Disable(), Dump(), Enable(), and GetHandler().

◆ m_options

std::atomic<uint32_t> lldb_private::Log::m_options {0}
private

Definition at line 289 of file Log.h.

Referenced by Enable(), GetOptions(), and GetVerbose().


The documentation for this class was generated from the following files: