LLDB mainline
Classes | Namespaces | Macros | Functions
Log.h File Reference
#include "lldb/Utility/Flags.h"
#include "lldb/lldb-defines.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/FormatVariadic.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/RWMutex.h"
#include <atomic>
#include <cstdarg>
#include <cstdint>
#include <memory>
#include <mutex>
#include <string>
#include <type_traits>

Go to the source code of this file.

Classes

class  lldb_private::LogHandler
 
class  lldb_private::StreamLogHandler
 
class  lldb_private::CallbackLogHandler
 
class  lldb_private::RotatingLogHandler
 
class  lldb_private::TeeLogHandler
 A T-style log handler that multiplexes messages to two log handlers. More...
 
class  lldb_private::Log
 
struct  lldb_private::Log::Category
 
class  lldb_private::Log::Channel
 

Namespaces

namespace  llvm
 
namespace  lldb_private
 A class that represents a running process on the host machine.
 

Macros

#define LLDB_LOG_OPTION_VERBOSE   (1u << 1)
 
#define LLDB_LOG_OPTION_PREPEND_SEQUENCE   (1u << 3)
 
#define LLDB_LOG_OPTION_PREPEND_TIMESTAMP   (1u << 4)
 
#define LLDB_LOG_OPTION_PREPEND_PROC_AND_THREAD   (1u << 5)
 
#define LLDB_LOG_OPTION_PREPEND_THREAD_NAME   (1U << 6)
 
#define LLDB_LOG_OPTION_BACKTRACE   (1U << 7)
 
#define LLDB_LOG_OPTION_APPEND   (1U << 8)
 
#define LLDB_LOG_OPTION_PREPEND_FILE_FUNCTION   (1U << 9)
 
#define LLDB_LOG(log, ...)
 The LLDB_LOG* macros defined below are the way to emit log messages.
 
#define LLDB_LOGF(log, ...)
 
#define LLDB_LOGV(log, ...)
 
#define LLDB_LOG_ERROR(log, error, ...)
 
#define LLDB_LOG_ERRORV(log, error, ...)
 

Functions

template<typename Cat >
Log::Channel & lldb_private::LogChannelFor ()=delete
 
template<typename Cat >
Log * lldb_private::GetLog (Cat mask)
 Retrieve the Log object for the channel associated with the given log enum.
 

Macro Definition Documentation

◆ LLDB_LOG

#define LLDB_LOG (   log,
  ... 
)
Value:
do { \
::lldb_private::Log *log_private = (log); \
if (log_private) \
log_private->Format(__FILE__, __func__, __VA_ARGS__); \
} while (0)
void Format(llvm::StringRef file, llvm::StringRef function, const char *format, Args &&... args)
Definition: Log.h:238

The LLDB_LOG* macros defined below are the way to emit log messages.

Note that the macros surround the arguments in a check for the log being on, so you can freely call methods in arguments without affecting the non-log execution flow.

If you need to do more complex computations to prepare the log message be sure to add your own if (log) check, since we don't want logging to have any effect when not on.

However, the LLDB_LOG macro uses the llvm::formatv system (see the ProgrammersManual page in the llvm docs for more details). This allows the use of "format_providers" to auto-format datatypes, and there are already formatters for some of the llvm and lldb datatypes.

So if you need to do non-trivial formatting of one of these types, be sure to grep the lldb and llvm sources for "format_provider" to see if there is already a formatter before doing in situ formatting, and if possible add a provider if one does not already exist.

Definition at line 359 of file Log.h.

◆ LLDB_LOG_ERROR

#define LLDB_LOG_ERROR (   log,
  error,
  ... 
)
Value:
do { \
::lldb_private::Log *log_private = (log); \
::llvm::Error error_private = (error); \
if (log_private && error_private) { \
log_private->FormatError(::std::move(error_private), __FILE__, __func__, \
__VA_ARGS__); \
} else \
::llvm::consumeError(::std::move(error_private)); \
} while (0)
static llvm::raw_ostream & error(Stream &strm)
void FormatError(llvm::Error error, llvm::StringRef file, llvm::StringRef function, const char *format, Args &&... args)
Definition: Log.h:244

Definition at line 382 of file Log.h.

◆ LLDB_LOG_ERRORV

#define LLDB_LOG_ERRORV (   log,
  error,
  ... 
)
Value:
do { \
::lldb_private::Log *log_private = (log); \
::llvm::Error error_private = (error); \
if (log_private && log_private->GetVerbose() && error_private) { \
log_private->FormatError(::std::move(error_private), __FILE__, __func__, \
__VA_ARGS__); \
} else \
::llvm::consumeError(::std::move(error_private)); \
} while (0)
bool GetVerbose() const
Definition: Log.cpp:314

Definition at line 396 of file Log.h.

◆ LLDB_LOG_OPTION_APPEND

#define LLDB_LOG_OPTION_APPEND   (1U << 8)

Definition at line 42 of file Log.h.

◆ LLDB_LOG_OPTION_BACKTRACE

#define LLDB_LOG_OPTION_BACKTRACE   (1U << 7)

Definition at line 41 of file Log.h.

◆ LLDB_LOG_OPTION_PREPEND_FILE_FUNCTION

#define LLDB_LOG_OPTION_PREPEND_FILE_FUNCTION   (1U << 9)

Definition at line 43 of file Log.h.

◆ LLDB_LOG_OPTION_PREPEND_PROC_AND_THREAD

#define LLDB_LOG_OPTION_PREPEND_PROC_AND_THREAD   (1u << 5)

Definition at line 39 of file Log.h.

◆ LLDB_LOG_OPTION_PREPEND_SEQUENCE

#define LLDB_LOG_OPTION_PREPEND_SEQUENCE   (1u << 3)

Definition at line 37 of file Log.h.

◆ LLDB_LOG_OPTION_PREPEND_THREAD_NAME

#define LLDB_LOG_OPTION_PREPEND_THREAD_NAME   (1U << 6)

Definition at line 40 of file Log.h.

◆ LLDB_LOG_OPTION_PREPEND_TIMESTAMP

#define LLDB_LOG_OPTION_PREPEND_TIMESTAMP   (1u << 4)

Definition at line 38 of file Log.h.

◆ LLDB_LOG_OPTION_VERBOSE

#define LLDB_LOG_OPTION_VERBOSE   (1u << 1)

Definition at line 36 of file Log.h.

◆ LLDB_LOGF

#define LLDB_LOGF (   log,
  ... 
)
Value:
do { \
::lldb_private::Log *log_private = (log); \
if (log_private) \
log_private->Formatf(__FILE__, __func__, __VA_ARGS__); \
} while (0)
void Formatf(llvm::StringRef file, llvm::StringRef function, const char *format,...) __attribute__((format(printf
Definition: Log.cpp:159

Definition at line 366 of file Log.h.

◆ LLDB_LOGV

#define LLDB_LOGV (   log,
  ... 
)
Value:
do { \
::lldb_private::Log *log_private = (log); \
if (log_private && log_private->GetVerbose()) \
log_private->Format(__FILE__, __func__, __VA_ARGS__); \
} while (0)

Definition at line 373 of file Log.h.