]>
Commit | Line | Data |
---|---|---|
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" | |
eeacee4d | 6 | |
be0aa7ac | 7 | /* Private global variable, don't use */ |
eeacee4d | 8 | extern FILE *qemu_logfile; |
79383c9c | 9 | |
6d2c5146 AL |
10 | /* |
11 | * The new API: | |
12 | * | |
13 | */ | |
14 | ||
15 | /* Log settings checking macros: */ | |
16 | ||
17 | /* Returns true if qemu_log() will really write somewhere | |
18 | */ | |
eeacee4d BS |
19 | static inline bool qemu_log_enabled(void) |
20 | { | |
21 | return qemu_logfile != NULL; | |
22 | } | |
6d2c5146 | 23 | |
013a2942 PB |
24 | /* Returns true if qemu_log() will write somewhere else than stderr |
25 | */ | |
26 | static inline bool qemu_log_separate(void) | |
27 | { | |
28 | return qemu_logfile != NULL && qemu_logfile != stderr; | |
29 | } | |
30 | ||
5726c27f BS |
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) | |
5726c27f BS |
38 | #define CPU_LOG_TB_CPU (1 << 8) |
39 | #define CPU_LOG_RESET (1 << 9) | |
dafdf1ab | 40 | #define LOG_UNIMP (1 << 10) |
e54eba19 | 41 | #define LOG_GUEST_ERROR (1 << 11) |
339aaf5b | 42 | #define CPU_LOG_MMU (1 << 12) |
89a82cd4 | 43 | #define CPU_LOG_TB_NOCHAIN (1 << 13) |
13829020 | 44 | #define CPU_LOG_PAGE (1 << 14) |
be0aa7ac | 45 | /* LOG_TRACE (1 << 15) is defined in log-for-trace.h */ |
5a18407f | 46 | #define CPU_LOG_TB_OP_IND (1 << 16) |
5726c27f | 47 | |
1ee73216 RH |
48 | /* Lock output for a series of related logs. Since this is not needed |
49 | * for a single qemu_log / qemu_log_mask / qemu_log_mask_and_addr, we | |
50 | * assume that qemu_loglevel_mask has already been tested, and that | |
51 | * qemu_loglevel is never set when qemu_logfile is unset. | |
52 | */ | |
53 | ||
54 | static inline void qemu_log_lock(void) | |
55 | { | |
56 | qemu_flockfile(qemu_logfile); | |
57 | } | |
58 | ||
59 | static inline void qemu_log_unlock(void) | |
60 | { | |
61 | qemu_funlockfile(qemu_logfile); | |
62 | } | |
63 | ||
6d2c5146 AL |
64 | /* Logging functions: */ |
65 | ||
6d2c5146 AL |
66 | /* vfprintf-like logging function |
67 | */ | |
726f8cbf SW |
68 | static inline void GCC_FMT_ATTR(1, 0) |
69 | qemu_log_vprintf(const char *fmt, va_list va) | |
eeacee4d BS |
70 | { |
71 | if (qemu_logfile) { | |
72 | vfprintf(qemu_logfile, fmt, va); | |
73 | } | |
74 | } | |
6d2c5146 | 75 | |
7ee60623 PM |
76 | /* log only if a bit is set on the current loglevel mask: |
77 | * @mask: bit to check in the mask | |
78 | * @fmt: printf-style format string | |
79 | * @args: optional arguments for format string | |
6d2c5146 | 80 | */ |
7ee60623 PM |
81 | #define qemu_log_mask(MASK, FMT, ...) \ |
82 | do { \ | |
83 | if (unlikely(qemu_loglevel_mask(MASK))) { \ | |
84 | qemu_log(FMT, ## __VA_ARGS__); \ | |
85 | } \ | |
86 | } while (0) | |
6d2c5146 | 87 | |
d977e1c2 AB |
88 | /* log only if a bit is set on the current loglevel mask |
89 | * and we are in the address range we care about: | |
90 | * @mask: bit to check in the mask | |
91 | * @addr: address to check in dfilter | |
92 | * @fmt: printf-style format string | |
93 | * @args: optional arguments for format string | |
94 | */ | |
95 | #define qemu_log_mask_and_addr(MASK, ADDR, FMT, ...) \ | |
96 | do { \ | |
97 | if (unlikely(qemu_loglevel_mask(MASK)) && \ | |
98 | qemu_log_in_addr_range(ADDR)) { \ | |
99 | qemu_log(FMT, ## __VA_ARGS__); \ | |
100 | } \ | |
101 | } while (0) | |
102 | ||
6d2c5146 AL |
103 | /* Maintenance: */ |
104 | ||
5726c27f | 105 | /* define log items */ |
38dad9e5 | 106 | typedef struct QEMULogItem { |
5726c27f BS |
107 | int mask; |
108 | const char *name; | |
109 | const char *help; | |
38dad9e5 | 110 | } QEMULogItem; |
5726c27f | 111 | |
38dad9e5 | 112 | extern const QEMULogItem qemu_log_items[]; |
5726c27f | 113 | |
f2937a33 PB |
114 | void qemu_set_log(int log_flags); |
115 | void qemu_log_needs_buffers(void); | |
daa76aa4 | 116 | void qemu_set_log_filename(const char *filename, Error **errp); |
bd6fee9f | 117 | void qemu_set_dfilter_ranges(const char *ranges, Error **errp); |
3514552e | 118 | bool qemu_log_in_addr_range(uint64_t addr); |
4fde1eba | 119 | int qemu_str_to_log_mask(const char *str); |
6d2c5146 | 120 | |
59a6fa6e PM |
121 | /* Print a usage message listing all the valid logging categories |
122 | * to the specified FILE*. | |
123 | */ | |
124 | void qemu_print_log_usage(FILE *f); | |
125 | ||
99affd1d DL |
126 | /* fflush() the log file */ |
127 | void qemu_log_flush(void); | |
128 | /* Close the log file */ | |
129 | void qemu_log_close(void); | |
130 | ||
79383c9c | 131 | #endif |