LLDB  mainline
Classes | Namespaces | Macros
Log.h File Reference
#include "lldb/Utility/Flags.h"
#include "lldb/Utility/Logging.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 <string>
#include <type_traits>
Include dependency graph for Log.h:

Go to the source code of this file.

Classes

class  lldb_private::Log
 
struct  lldb_private::Log::Category
 
class  lldb_private::Log::Channel
 

Namespaces

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

Macros

#define LLDB_LOG_OPTION_THREADSAFE   (1u << 0)
 
#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. More...
 
#define LLDB_LOGF(log, ...)
 
#define LLDB_LOGV(log, ...)
 
#define LLDB_LOG_ERROR(log, error, ...)
 

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)

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 242 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)

Definition at line 265 of file Log.h.

◆ LLDB_LOG_OPTION_APPEND

#define LLDB_LOG_OPTION_APPEND   (1U << 8)

Definition at line 43 of file Log.h.

◆ LLDB_LOG_OPTION_BACKTRACE

#define LLDB_LOG_OPTION_BACKTRACE   (1U << 7)

Definition at line 42 of file Log.h.

◆ LLDB_LOG_OPTION_PREPEND_FILE_FUNCTION

#define LLDB_LOG_OPTION_PREPEND_FILE_FUNCTION   (1U << 9)

Definition at line 44 of file Log.h.

◆ LLDB_LOG_OPTION_PREPEND_PROC_AND_THREAD

#define LLDB_LOG_OPTION_PREPEND_PROC_AND_THREAD   (1u << 5)

Definition at line 40 of file Log.h.

◆ LLDB_LOG_OPTION_PREPEND_SEQUENCE

#define LLDB_LOG_OPTION_PREPEND_SEQUENCE   (1u << 3)

Definition at line 38 of file Log.h.

◆ LLDB_LOG_OPTION_PREPEND_THREAD_NAME

#define LLDB_LOG_OPTION_PREPEND_THREAD_NAME   (1U << 6)

Definition at line 41 of file Log.h.

◆ LLDB_LOG_OPTION_PREPEND_TIMESTAMP

#define LLDB_LOG_OPTION_PREPEND_TIMESTAMP   (1u << 4)

Definition at line 39 of file Log.h.

◆ LLDB_LOG_OPTION_THREADSAFE

#define LLDB_LOG_OPTION_THREADSAFE   (1u << 0)

Definition at line 36 of file Log.h.

◆ LLDB_LOG_OPTION_VERBOSE

#define LLDB_LOG_OPTION_VERBOSE   (1u << 1)

Definition at line 37 of file Log.h.

◆ LLDB_LOGF

#define LLDB_LOGF (   log,
  ... 
)
Value:
do { \
::lldb_private::Log *log_private = (log); \
if (log_private) \
log_private->Printf(__VA_ARGS__); \
} while (0)

Definition at line 249 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 256 of file Log.h.

lldb_private::Log::GetVerbose
bool GetVerbose() const
Definition: Log.cpp:276
lldb_private::Log::Printf
void Printf(const char *format,...) __attribute__((format(printf
Prefer using LLDB_LOGF whenever possible.
Definition: Log.cpp:122
error
static llvm::raw_ostream & error(Stream &strm)
Definition: CommandReturnObject.cpp:17
lldb_private::Log::Format
void Format(llvm::StringRef file, llvm::StringRef function, const char *format, Args &&... args)
Definition: Log.h:140
Error
llvm::Error Error
Definition: UdtRecordCompleter.cpp:29
lldb_private::Log
Definition: Log.h:49