1#ifndef QEMU_LOG_H
2#define QEMU_LOG_H
3
4
5#include "qemu/log-for-trace.h"
6
7
8extern FILE *qemu_logfile;
9
10
11
12
13
14
15
16
17
18
19static inline bool qemu_log_enabled(void)
20{
21 return qemu_logfile != NULL;
22}
23
24
25
26static inline bool qemu_log_separate(void)
27{
28 return qemu_logfile != NULL && qemu_logfile != stderr;
29}
30
31#define CPU_LOG_TB_OUT_ASM (1 << 0)
32#define CPU_LOG_TB_IN_ASM (1 << 1)
33#define CPU_LOG_TB_OP (1 << 2)
34#define CPU_LOG_TB_OP_OPT (1 << 3)
35#define CPU_LOG_INT (1 << 4)
36#define CPU_LOG_EXEC (1 << 5)
37#define CPU_LOG_PCALL (1 << 6)
38#define CPU_LOG_TB_CPU (1 << 8)
39#define CPU_LOG_RESET (1 << 9)
40#define LOG_UNIMP (1 << 10)
41#define LOG_GUEST_ERROR (1 << 11)
42#define CPU_LOG_MMU (1 << 12)
43#define CPU_LOG_TB_NOCHAIN (1 << 13)
44#define CPU_LOG_PAGE (1 << 14)
45
46#define CPU_LOG_TB_OP_IND (1 << 16)
47#define CPU_LOG_TB_FPU (1 << 17)
48
49
50
51
52
53
54
55static inline void qemu_log_lock(void)
56{
57 qemu_flockfile(qemu_logfile);
58}
59
60static inline void qemu_log_unlock(void)
61{
62 qemu_funlockfile(qemu_logfile);
63}
64
65
66
67
68
69static inline void GCC_FMT_ATTR(1, 0)
70qemu_log_vprintf(const char *fmt, va_list va)
71{
72 if (qemu_logfile) {
73 vfprintf(qemu_logfile, fmt, va);
74 }
75}
76
77
78
79
80
81
82#define qemu_log_mask(MASK, FMT, ...) \
83 do { \
84 if (unlikely(qemu_loglevel_mask(MASK))) { \
85 qemu_log(FMT, ## __VA_ARGS__); \
86 } \
87 } while (0)
88
89
90
91
92
93
94
95
96#define qemu_log_mask_and_addr(MASK, ADDR, FMT, ...) \
97 do { \
98 if (unlikely(qemu_loglevel_mask(MASK)) && \
99 qemu_log_in_addr_range(ADDR)) { \
100 qemu_log(FMT, ## __VA_ARGS__); \
101 } \
102 } while (0)
103
104
105
106
107typedef struct QEMULogItem {
108 int mask;
109 const char *name;
110 const char *help;
111} QEMULogItem;
112
113extern const QEMULogItem qemu_log_items[];
114
115void qemu_set_log(int log_flags);
116void qemu_log_needs_buffers(void);
117void qemu_set_log_filename(const char *filename, Error **errp);
118void qemu_set_dfilter_ranges(const char *ranges, Error **errp);
119bool qemu_log_in_addr_range(uint64_t addr);
120int qemu_str_to_log_mask(const char *str);
121
122
123
124
125void qemu_print_log_usage(FILE *f);
126
127
128void qemu_log_flush(void);
129
130void qemu_log_close(void);
131
132#endif
133