]>
Commit | Line | Data |
---|---|---|
79383c9c BS |
1 | #ifndef QEMU_LOG_H |
2 | #define QEMU_LOG_H | |
3 | ||
eeacee4d BS |
4 | |
5 | /* Private global variables, don't use */ | |
6 | extern FILE *qemu_logfile; | |
7 | extern int qemu_loglevel; | |
79383c9c | 8 | |
6d2c5146 AL |
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 | */ | |
eeacee4d BS |
18 | static inline bool qemu_log_enabled(void) |
19 | { | |
20 | return qemu_logfile != NULL; | |
21 | } | |
6d2c5146 | 22 | |
013a2942 PB |
23 | /* Returns true if qemu_log() will write somewhere else than stderr |
24 | */ | |
25 | static inline bool qemu_log_separate(void) | |
26 | { | |
27 | return qemu_logfile != NULL && qemu_logfile != stderr; | |
28 | } | |
29 | ||
5726c27f BS |
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) | |
5726c27f BS |
37 | #define CPU_LOG_TB_CPU (1 << 8) |
38 | #define CPU_LOG_RESET (1 << 9) | |
dafdf1ab | 39 | #define LOG_UNIMP (1 << 10) |
e54eba19 | 40 | #define LOG_GUEST_ERROR (1 << 11) |
339aaf5b | 41 | #define CPU_LOG_MMU (1 << 12) |
89a82cd4 | 42 | #define CPU_LOG_TB_NOCHAIN (1 << 13) |
13829020 | 43 | #define CPU_LOG_PAGE (1 << 14) |
ed7f5f1d | 44 | #define LOG_TRACE (1 << 15) |
5726c27f | 45 | |
6d2c5146 AL |
46 | /* Returns true if a bit is set in the current loglevel mask |
47 | */ | |
eeacee4d BS |
48 | static inline bool qemu_loglevel_mask(int mask) |
49 | { | |
50 | return (qemu_loglevel & mask) != 0; | |
51 | } | |
6d2c5146 | 52 | |
6d2c5146 AL |
53 | /* Logging functions: */ |
54 | ||
55 | /* main logging function | |
56 | */ | |
eeacee4d | 57 | void GCC_FMT_ATTR(1, 2) qemu_log(const char *fmt, ...); |
6d2c5146 AL |
58 | |
59 | /* vfprintf-like logging function | |
60 | */ | |
726f8cbf SW |
61 | static inline void GCC_FMT_ATTR(1, 0) |
62 | qemu_log_vprintf(const char *fmt, va_list va) | |
eeacee4d BS |
63 | { |
64 | if (qemu_logfile) { | |
65 | vfprintf(qemu_logfile, fmt, va); | |
66 | } | |
67 | } | |
6d2c5146 | 68 | |
7ee60623 PM |
69 | /* log only if a bit is set on the current loglevel mask: |
70 | * @mask: bit to check in the mask | |
71 | * @fmt: printf-style format string | |
72 | * @args: optional arguments for format string | |
6d2c5146 | 73 | */ |
7ee60623 PM |
74 | #define qemu_log_mask(MASK, FMT, ...) \ |
75 | do { \ | |
76 | if (unlikely(qemu_loglevel_mask(MASK))) { \ | |
77 | qemu_log(FMT, ## __VA_ARGS__); \ | |
78 | } \ | |
79 | } while (0) | |
6d2c5146 | 80 | |
d977e1c2 AB |
81 | /* log only if a bit is set on the current loglevel mask |
82 | * and we are in the address range we care about: | |
83 | * @mask: bit to check in the mask | |
84 | * @addr: address to check in dfilter | |
85 | * @fmt: printf-style format string | |
86 | * @args: optional arguments for format string | |
87 | */ | |
88 | #define qemu_log_mask_and_addr(MASK, ADDR, FMT, ...) \ | |
89 | do { \ | |
90 | if (unlikely(qemu_loglevel_mask(MASK)) && \ | |
91 | qemu_log_in_addr_range(ADDR)) { \ | |
92 | qemu_log(FMT, ## __VA_ARGS__); \ | |
93 | } \ | |
94 | } while (0) | |
95 | ||
6d2c5146 AL |
96 | /* Maintenance: */ |
97 | ||
98 | /* fflush() the log file */ | |
eeacee4d BS |
99 | static inline void qemu_log_flush(void) |
100 | { | |
101 | fflush(qemu_logfile); | |
102 | } | |
6d2c5146 AL |
103 | |
104 | /* Close the log file */ | |
eeacee4d BS |
105 | static inline void qemu_log_close(void) |
106 | { | |
989b697d PM |
107 | if (qemu_logfile) { |
108 | if (qemu_logfile != stderr) { | |
109 | fclose(qemu_logfile); | |
110 | } | |
111 | qemu_logfile = NULL; | |
112 | } | |
eeacee4d | 113 | } |
6d2c5146 | 114 | |
5726c27f | 115 | /* define log items */ |
38dad9e5 | 116 | typedef struct QEMULogItem { |
5726c27f BS |
117 | int mask; |
118 | const char *name; | |
119 | const char *help; | |
38dad9e5 | 120 | } QEMULogItem; |
5726c27f | 121 | |
38dad9e5 | 122 | extern const QEMULogItem qemu_log_items[]; |
5726c27f | 123 | |
24537a01 PM |
124 | /* This is the function that actually does the work of |
125 | * changing the log level; it should only be accessed via | |
126 | * the qemu_set_log() wrapper. | |
127 | */ | |
128 | void do_qemu_set_log(int log_flags, bool use_own_buffers); | |
3437e545 | 129 | |
24537a01 | 130 | static inline void qemu_set_log(int log_flags) |
3437e545 BS |
131 | { |
132 | #ifdef CONFIG_USER_ONLY | |
24537a01 | 133 | do_qemu_set_log(log_flags, true); |
3437e545 | 134 | #else |
24537a01 | 135 | do_qemu_set_log(log_flags, false); |
3437e545 BS |
136 | #endif |
137 | } | |
138 | ||
9a7e5424 | 139 | void qemu_set_log_filename(const char *filename); |
3514552e AB |
140 | void qemu_set_dfilter_ranges(const char *ranges); |
141 | bool qemu_log_in_addr_range(uint64_t addr); | |
4fde1eba | 142 | int qemu_str_to_log_mask(const char *str); |
6d2c5146 | 143 | |
59a6fa6e PM |
144 | /* Print a usage message listing all the valid logging categories |
145 | * to the specified FILE*. | |
146 | */ | |
147 | void qemu_print_log_usage(FILE *f); | |
148 | ||
79383c9c | 149 | #endif |