qapi: Remove QMP events and commands from user-mode builds
[qemu/ar7.git] / include / qemu / log.h
blob9b8066020729a7d027fd4eab9ab39de79ce7b5cc
1 #ifndef QEMU_LOG_H
2 #define QEMU_LOG_H
4 /* A small part of this API is split into its own header */
5 #include "qemu/log-for-trace.h"
6 #include "qemu/rcu.h"
8 typedef struct QemuLogFile {
9 struct rcu_head rcu;
10 FILE *fd;
11 } QemuLogFile;
13 /* Private global variable, don't use */
14 extern QemuLogFile *qemu_logfile;
17 /*
18 * The new API:
22 /* Log settings checking macros: */
24 /* Returns true if qemu_log() will really write somewhere
26 static inline bool qemu_log_enabled(void)
28 return qemu_logfile != NULL;
31 /* Returns true if qemu_log() will write somewhere else than stderr
33 static inline bool qemu_log_separate(void)
35 QemuLogFile *logfile;
36 bool res = false;
38 rcu_read_lock();
39 logfile = qatomic_rcu_read(&qemu_logfile);
40 if (logfile && logfile->fd != stderr) {
41 res = true;
43 rcu_read_unlock();
44 return res;
47 #define CPU_LOG_TB_OUT_ASM (1 << 0)
48 #define CPU_LOG_TB_IN_ASM (1 << 1)
49 #define CPU_LOG_TB_OP (1 << 2)
50 #define CPU_LOG_TB_OP_OPT (1 << 3)
51 #define CPU_LOG_INT (1 << 4)
52 #define CPU_LOG_EXEC (1 << 5)
53 #define CPU_LOG_PCALL (1 << 6)
54 #define CPU_LOG_TB_CPU (1 << 8)
55 #define CPU_LOG_RESET (1 << 9)
56 #define LOG_UNIMP (1 << 10)
57 #define LOG_GUEST_ERROR (1 << 11)
58 #define CPU_LOG_MMU (1 << 12)
59 #define CPU_LOG_TB_NOCHAIN (1 << 13)
60 #define CPU_LOG_PAGE (1 << 14)
61 /* LOG_TRACE (1 << 15) is defined in log-for-trace.h */
62 #define CPU_LOG_TB_OP_IND (1 << 16)
63 #define CPU_LOG_TB_FPU (1 << 17)
64 #define CPU_LOG_PLUGIN (1 << 18)
65 /* LOG_STRACE is used for user-mode strace logging. */
66 #define LOG_STRACE (1 << 19)
68 /* Lock output for a series of related logs. Since this is not needed
69 * for a single qemu_log / qemu_log_mask / qemu_log_mask_and_addr, we
70 * assume that qemu_loglevel_mask has already been tested, and that
71 * qemu_loglevel is never set when qemu_logfile is unset.
74 static inline FILE *qemu_log_lock(void)
76 QemuLogFile *logfile;
77 rcu_read_lock();
78 logfile = qatomic_rcu_read(&qemu_logfile);
79 if (logfile) {
80 qemu_flockfile(logfile->fd);
81 return logfile->fd;
82 } else {
83 return NULL;
87 static inline void qemu_log_unlock(FILE *fd)
89 if (fd) {
90 qemu_funlockfile(fd);
92 rcu_read_unlock();
95 /* Logging functions: */
97 /* vfprintf-like logging function
99 static inline void GCC_FMT_ATTR(1, 0)
100 qemu_log_vprintf(const char *fmt, va_list va)
102 QemuLogFile *logfile;
104 rcu_read_lock();
105 logfile = qatomic_rcu_read(&qemu_logfile);
106 if (logfile) {
107 vfprintf(logfile->fd, fmt, va);
109 rcu_read_unlock();
112 /* log only if a bit is set on the current loglevel mask:
113 * @mask: bit to check in the mask
114 * @fmt: printf-style format string
115 * @args: optional arguments for format string
117 #define qemu_log_mask(MASK, FMT, ...) \
118 do { \
119 if (unlikely(qemu_loglevel_mask(MASK))) { \
120 qemu_log(FMT, ## __VA_ARGS__); \
122 } while (0)
124 /* log only if a bit is set on the current loglevel mask
125 * and we are in the address range we care about:
126 * @mask: bit to check in the mask
127 * @addr: address to check in dfilter
128 * @fmt: printf-style format string
129 * @args: optional arguments for format string
131 #define qemu_log_mask_and_addr(MASK, ADDR, FMT, ...) \
132 do { \
133 if (unlikely(qemu_loglevel_mask(MASK)) && \
134 qemu_log_in_addr_range(ADDR)) { \
135 qemu_log(FMT, ## __VA_ARGS__); \
137 } while (0)
139 /* Maintenance: */
141 /* define log items */
142 typedef struct QEMULogItem {
143 int mask;
144 const char *name;
145 const char *help;
146 } QEMULogItem;
148 extern const QEMULogItem qemu_log_items[];
150 void qemu_set_log(int log_flags);
151 void qemu_log_needs_buffers(void);
152 void qemu_set_log_filename(const char *filename, Error **errp);
153 void qemu_set_dfilter_ranges(const char *ranges, Error **errp);
154 bool qemu_log_in_addr_range(uint64_t addr);
155 int qemu_str_to_log_mask(const char *str);
157 /* Print a usage message listing all the valid logging categories
158 * to the specified FILE*.
160 void qemu_print_log_usage(FILE *f);
162 /* fflush() the log file */
163 void qemu_log_flush(void);
164 /* Close the log file */
165 void qemu_log_close(void);
167 #endif