]> git.proxmox.com Git - mirror_qemu.git/blame - include/qemu/log.h
Replace GCC_FMT_ATTR with G_GNUC_PRINTF
[mirror_qemu.git] / include / qemu / log.h
CommitLineData
79383c9c
BS
1#ifndef QEMU_LOG_H
2#define QEMU_LOG_H
3
be0aa7ac
PM
4/* A small part of this API is split into its own header */
5#include "qemu/log-for-trace.h"
7606488c
RF
6#include "qemu/rcu.h"
7
8typedef struct QemuLogFile {
9 struct rcu_head rcu;
10 FILE *fd;
11} QemuLogFile;
eeacee4d 12
be0aa7ac 13/* Private global variable, don't use */
7606488c
RF
14extern QemuLogFile *qemu_logfile;
15
79383c9c 16
6d2c5146
AL
17/*
18 * The new API:
19 *
20 */
21
22/* Log settings checking macros: */
23
24/* Returns true if qemu_log() will really write somewhere
25 */
eeacee4d
BS
26static inline bool qemu_log_enabled(void)
27{
28 return qemu_logfile != NULL;
29}
6d2c5146 30
013a2942
PB
31/* Returns true if qemu_log() will write somewhere else than stderr
32 */
33static inline bool qemu_log_separate(void)
34{
7606488c
RF
35 QemuLogFile *logfile;
36 bool res = false;
37
38 rcu_read_lock();
d73415a3 39 logfile = qatomic_rcu_read(&qemu_logfile);
7606488c
RF
40 if (logfile && logfile->fd != stderr) {
41 res = true;
42 }
43 rcu_read_unlock();
44 return res;
013a2942
PB
45}
46
5726c27f
BS
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)
5726c27f
BS
54#define CPU_LOG_TB_CPU (1 << 8)
55#define CPU_LOG_RESET (1 << 9)
dafdf1ab 56#define LOG_UNIMP (1 << 10)
e54eba19 57#define LOG_GUEST_ERROR (1 << 11)
339aaf5b 58#define CPU_LOG_MMU (1 << 12)
89a82cd4 59#define CPU_LOG_TB_NOCHAIN (1 << 13)
13829020 60#define CPU_LOG_PAGE (1 << 14)
be0aa7ac 61/* LOG_TRACE (1 << 15) is defined in log-for-trace.h */
5a18407f 62#define CPU_LOG_TB_OP_IND (1 << 16)
ae765180 63#define CPU_LOG_TB_FPU (1 << 17)
ca76a669 64#define CPU_LOG_PLUGIN (1 << 18)
4b25a506
JK
65/* LOG_STRACE is used for user-mode strace logging. */
66#define LOG_STRACE (1 << 19)
5726c27f 67
1ee73216
RH
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.
72 */
73
fc59d2d8 74static inline FILE *qemu_log_lock(void)
1ee73216 75{
7606488c
RF
76 QemuLogFile *logfile;
77 rcu_read_lock();
d73415a3 78 logfile = qatomic_rcu_read(&qemu_logfile);
7606488c
RF
79 if (logfile) {
80 qemu_flockfile(logfile->fd);
81 return logfile->fd;
82 } else {
83 return NULL;
84 }
1ee73216
RH
85}
86
fc59d2d8 87static inline void qemu_log_unlock(FILE *fd)
1ee73216 88{
fc59d2d8
RF
89 if (fd) {
90 qemu_funlockfile(fd);
91 }
7606488c 92 rcu_read_unlock();
1ee73216
RH
93}
94
6d2c5146
AL
95/* Logging functions: */
96
6d2c5146
AL
97/* vfprintf-like logging function
98 */
9edc6313 99static inline void G_GNUC_PRINTF(1, 0)
726f8cbf 100qemu_log_vprintf(const char *fmt, va_list va)
eeacee4d 101{
7606488c
RF
102 QemuLogFile *logfile;
103
104 rcu_read_lock();
d73415a3 105 logfile = qatomic_rcu_read(&qemu_logfile);
7606488c
RF
106 if (logfile) {
107 vfprintf(logfile->fd, fmt, va);
eeacee4d 108 }
7606488c 109 rcu_read_unlock();
eeacee4d 110}
6d2c5146 111
7ee60623
PM
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
6d2c5146 116 */
7ee60623
PM
117#define qemu_log_mask(MASK, FMT, ...) \
118 do { \
119 if (unlikely(qemu_loglevel_mask(MASK))) { \
120 qemu_log(FMT, ## __VA_ARGS__); \
121 } \
122 } while (0)
6d2c5146 123
d977e1c2
AB
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
130 */
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__); \
136 } \
137 } while (0)
138
6d2c5146
AL
139/* Maintenance: */
140
5726c27f 141/* define log items */
38dad9e5 142typedef struct QEMULogItem {
5726c27f
BS
143 int mask;
144 const char *name;
145 const char *help;
38dad9e5 146} QEMULogItem;
5726c27f 147
38dad9e5 148extern const QEMULogItem qemu_log_items[];
5726c27f 149
f2937a33
PB
150void qemu_set_log(int log_flags);
151void qemu_log_needs_buffers(void);
daa76aa4 152void qemu_set_log_filename(const char *filename, Error **errp);
bd6fee9f 153void qemu_set_dfilter_ranges(const char *ranges, Error **errp);
3514552e 154bool qemu_log_in_addr_range(uint64_t addr);
4fde1eba 155int qemu_str_to_log_mask(const char *str);
6d2c5146 156
59a6fa6e
PM
157/* Print a usage message listing all the valid logging categories
158 * to the specified FILE*.
159 */
160void qemu_print_log_usage(FILE *f);
161
99affd1d
DL
162/* fflush() the log file */
163void qemu_log_flush(void);
164/* Close the log file */
165void qemu_log_close(void);
166
79383c9c 167#endif