qemu/include/qemu/log.h
<<
>>
Prefs
   1#ifndef QEMU_LOG_H
   2#define QEMU_LOG_H
   3
   4
   5/* Private global variables, don't use */
   6extern FILE *qemu_logfile;
   7extern int qemu_loglevel;
   8
   9/* 
  10 * The new API:
  11 *
  12 */
  13
  14/* Log settings checking macros: */
  15
  16/* Returns true if qemu_log() will really write somewhere
  17 */
  18static inline bool qemu_log_enabled(void)
  19{
  20    return qemu_logfile != NULL;
  21}
  22
  23/* Returns true if qemu_log() will write somewhere else than stderr
  24 */
  25static inline bool qemu_log_separate(void)
  26{
  27    return qemu_logfile != NULL && qemu_logfile != stderr;
  28}
  29
  30#define CPU_LOG_TB_OUT_ASM (1 << 0)
  31#define CPU_LOG_TB_IN_ASM  (1 << 1)
  32#define CPU_LOG_TB_OP      (1 << 2)
  33#define CPU_LOG_TB_OP_OPT  (1 << 3)
  34#define CPU_LOG_INT        (1 << 4)
  35#define CPU_LOG_EXEC       (1 << 5)
  36#define CPU_LOG_PCALL      (1 << 6)
  37#define CPU_LOG_TB_CPU     (1 << 8)
  38#define CPU_LOG_RESET      (1 << 9)
  39#define LOG_UNIMP          (1 << 10)
  40#define LOG_GUEST_ERROR    (1 << 11)
  41#define CPU_LOG_MMU        (1 << 12)
  42#define CPU_LOG_TB_NOCHAIN (1 << 13)
  43#define CPU_LOG_PAGE       (1 << 14)
  44#define LOG_TRACE          (1 << 15)
  45
  46/* device entries */
  47#define DEV_LOG_NET_DEV    (1 << 16)
  48#define DEV_LOG_NAND       (1 << 17)
  49#define DEV_LOG_NANDC      (1 << 18)
  50#define DEV_LOG_SD         (1 << 19)
  51#define DEV_LOG_SDHCI      (1 << 20)
  52#define DEV_LOG_SPI        (1 << 21)
  53#define DEV_LOG_SPI_DEV    (1 << 22)
  54#define LOG_FDT            (1 << 23)
  55#define LOG_PM             (1 << 24)
  56
  57/* Returns true if a bit is set in the current loglevel mask
  58 */
  59static inline bool qemu_loglevel_mask(int mask)
  60{
  61    return (qemu_loglevel & mask) != 0;
  62}
  63
  64/* Logging functions: */
  65
  66/* main logging function
  67 */
  68void GCC_FMT_ATTR(1, 2) qemu_log(const char *fmt, ...);
  69
  70/* vfprintf-like logging function
  71 */
  72static inline void GCC_FMT_ATTR(1, 0)
  73qemu_log_vprintf(const char *fmt, va_list va)
  74{
  75    if (qemu_logfile) {
  76        vfprintf(qemu_logfile, fmt, va);
  77    }
  78}
  79
  80/* log only if a bit is set on the current loglevel mask:
  81 * @mask: bit to check in the mask
  82 * @fmt: printf-style format string
  83 * @args: optional arguments for format string
  84 */
  85#define qemu_log_mask(MASK, FMT, ...)                   \
  86    do {                                                \
  87        if (unlikely(qemu_loglevel_mask(MASK))) {       \
  88            qemu_log(FMT, ## __VA_ARGS__);              \
  89        }                                               \
  90    } while (0)
  91
  92/* log only if a bit is set on the current loglevel mask
  93 * and we are in the address range we care about:
  94 * @mask: bit to check in the mask
  95 * @addr: address to check in dfilter
  96 * @fmt: printf-style format string
  97 * @args: optional arguments for format string
  98 */
  99#define qemu_log_mask_and_addr(MASK, ADDR, FMT, ...)    \
 100    do {                                                \
 101        if (unlikely(qemu_loglevel_mask(MASK)) &&       \
 102                     qemu_log_in_addr_range(ADDR)) {    \
 103            qemu_log(FMT, ## __VA_ARGS__);              \
 104        }                                               \
 105    } while (0)
 106
 107/* Maintenance: */
 108
 109/* define log items */
 110typedef struct QEMULogItem {
 111    int mask;
 112    const char *name;
 113    const char *help;
 114} QEMULogItem;
 115
 116extern const QEMULogItem qemu_log_items[];
 117
 118/* This is the function that actually does the work of
 119 * changing the log level; it should only be accessed via
 120 * the qemu_set_log() wrapper.
 121 */
 122void do_qemu_set_log(int log_flags, bool use_own_buffers);
 123
 124static inline void qemu_set_log(int log_flags)
 125{
 126#ifdef CONFIG_USER_ONLY
 127    do_qemu_set_log(log_flags, true);
 128#else
 129    do_qemu_set_log(log_flags, false);
 130#endif
 131}
 132
 133void qemu_set_log_filename(const char *filename);
 134void qemu_set_dfilter_ranges(const char *ranges);
 135bool qemu_log_in_addr_range(uint64_t addr);
 136int qemu_str_to_log_mask(const char *str);
 137
 138/* Print a usage message listing all the valid logging categories
 139 * to the specified FILE*.
 140 */
 141void qemu_print_log_usage(FILE *f);
 142
 143/* fflush() the log file */
 144void qemu_log_flush(void);
 145/* Close the log file */
 146void qemu_log_close(void);
 147
 148#endif
 149