]>
Commit | Line | Data |
---|---|---|
79383c9c BS |
1 | #ifndef QEMU_LOG_H |
2 | #define QEMU_LOG_H | |
3 | ||
eeacee4d | 4 | #include <stdarg.h> |
f3eededb MA |
5 | #include <stdbool.h> |
6 | #include <stdio.h> | |
7 | #include "qemu/compiler.h" | |
a0762859 | 8 | #include "qom/cpu.h" |
eeacee4d | 9 | #ifdef NEED_CPU_H |
76cad711 | 10 | #include "disas/disas.h" |
eeacee4d BS |
11 | #endif |
12 | ||
13 | /* Private global variables, don't use */ | |
14 | extern FILE *qemu_logfile; | |
15 | extern int qemu_loglevel; | |
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 |
26 | static inline bool qemu_log_enabled(void) |
27 | { | |
28 | return qemu_logfile != NULL; | |
29 | } | |
6d2c5146 | 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) | |
38 | #define CPU_LOG_IOPORT (1 << 7) | |
39 | #define CPU_LOG_TB_CPU (1 << 8) | |
40 | #define CPU_LOG_RESET (1 << 9) | |
dafdf1ab | 41 | #define LOG_UNIMP (1 << 10) |
e54eba19 | 42 | #define LOG_GUEST_ERROR (1 << 11) |
339aaf5b | 43 | #define CPU_LOG_MMU (1 << 12) |
5726c27f | 44 | |
6d2c5146 AL |
45 | /* Returns true if a bit is set in the current loglevel mask |
46 | */ | |
eeacee4d BS |
47 | static inline bool qemu_loglevel_mask(int mask) |
48 | { | |
49 | return (qemu_loglevel & mask) != 0; | |
50 | } | |
6d2c5146 | 51 | |
6d2c5146 AL |
52 | /* Logging functions: */ |
53 | ||
54 | /* main logging function | |
55 | */ | |
eeacee4d | 56 | void GCC_FMT_ATTR(1, 2) qemu_log(const char *fmt, ...); |
6d2c5146 AL |
57 | |
58 | /* vfprintf-like logging function | |
59 | */ | |
726f8cbf SW |
60 | static inline void GCC_FMT_ATTR(1, 0) |
61 | qemu_log_vprintf(const char *fmt, va_list va) | |
eeacee4d BS |
62 | { |
63 | if (qemu_logfile) { | |
64 | vfprintf(qemu_logfile, fmt, va); | |
65 | } | |
66 | } | |
6d2c5146 AL |
67 | |
68 | /* log only if a bit is set on the current loglevel mask | |
69 | */ | |
eeacee4d | 70 | void GCC_FMT_ATTR(2, 3) qemu_log_mask(int mask, const char *fmt, ...); |
6d2c5146 AL |
71 | |
72 | ||
6d2c5146 AL |
73 | /* Special cases: */ |
74 | ||
75 | /* cpu_dump_state() logging functions: */ | |
a0762859 AF |
76 | /** |
77 | * log_cpu_state: | |
78 | * @cpu: The CPU whose state is to be logged. | |
79 | * @flags: Flags what to log. | |
80 | * | |
81 | * Logs the output of cpu_dump_state(). | |
82 | */ | |
83 | static inline void log_cpu_state(CPUState *cpu, int flags) | |
eeacee4d | 84 | { |
c8f803e7 | 85 | if (qemu_log_enabled()) { |
a0762859 | 86 | cpu_dump_state(cpu, qemu_logfile, fprintf, flags); |
c8f803e7 | 87 | } |
eeacee4d BS |
88 | } |
89 | ||
a0762859 AF |
90 | /** |
91 | * log_cpu_state_mask: | |
92 | * @mask: Mask when to log. | |
93 | * @cpu: The CPU whose state is to be logged. | |
94 | * @flags: Flags what to log. | |
95 | * | |
96 | * Logs the output of cpu_dump_state() if loglevel includes @mask. | |
97 | */ | |
98 | static inline void log_cpu_state_mask(int mask, CPUState *cpu, int flags) | |
eeacee4d BS |
99 | { |
100 | if (qemu_loglevel & mask) { | |
a0762859 | 101 | log_cpu_state(cpu, flags); |
eeacee4d BS |
102 | } |
103 | } | |
104 | ||
a0762859 | 105 | #ifdef NEED_CPU_H |
eeacee4d | 106 | /* disas() and target_disas() to qemu_logfile: */ |
d49190c4 | 107 | static inline void log_target_disas(CPUState *cpu, target_ulong start, |
f4359b9f | 108 | target_ulong len, int flags) |
eeacee4d | 109 | { |
d49190c4 | 110 | target_disas(qemu_logfile, cpu, start, len, flags); |
eeacee4d BS |
111 | } |
112 | ||
113 | static inline void log_disas(void *code, unsigned long size) | |
114 | { | |
115 | disas(qemu_logfile, code, size); | |
116 | } | |
117 | ||
118 | #if defined(CONFIG_USER_ONLY) | |
6d2c5146 | 119 | /* page_dump() output to the log file: */ |
eeacee4d BS |
120 | static inline void log_page_dump(void) |
121 | { | |
122 | page_dump(qemu_logfile); | |
123 | } | |
124 | #endif | |
3b823210 | 125 | #endif |
6d2c5146 AL |
126 | |
127 | ||
6d2c5146 AL |
128 | /* Maintenance: */ |
129 | ||
130 | /* fflush() the log file */ | |
eeacee4d BS |
131 | static inline void qemu_log_flush(void) |
132 | { | |
133 | fflush(qemu_logfile); | |
134 | } | |
6d2c5146 AL |
135 | |
136 | /* Close the log file */ | |
eeacee4d BS |
137 | static inline void qemu_log_close(void) |
138 | { | |
989b697d PM |
139 | if (qemu_logfile) { |
140 | if (qemu_logfile != stderr) { | |
141 | fclose(qemu_logfile); | |
142 | } | |
143 | qemu_logfile = NULL; | |
144 | } | |
eeacee4d | 145 | } |
6d2c5146 AL |
146 | |
147 | /* Set up a new log file */ | |
eeacee4d BS |
148 | static inline void qemu_log_set_file(FILE *f) |
149 | { | |
150 | qemu_logfile = f; | |
151 | } | |
6d2c5146 | 152 | |
5726c27f | 153 | /* define log items */ |
38dad9e5 | 154 | typedef struct QEMULogItem { |
5726c27f BS |
155 | int mask; |
156 | const char *name; | |
157 | const char *help; | |
38dad9e5 | 158 | } QEMULogItem; |
5726c27f | 159 | |
38dad9e5 | 160 | extern const QEMULogItem qemu_log_items[]; |
5726c27f | 161 | |
24537a01 PM |
162 | /* This is the function that actually does the work of |
163 | * changing the log level; it should only be accessed via | |
164 | * the qemu_set_log() wrapper. | |
165 | */ | |
166 | void do_qemu_set_log(int log_flags, bool use_own_buffers); | |
3437e545 | 167 | |
24537a01 | 168 | static inline void qemu_set_log(int log_flags) |
3437e545 BS |
169 | { |
170 | #ifdef CONFIG_USER_ONLY | |
24537a01 | 171 | do_qemu_set_log(log_flags, true); |
3437e545 | 172 | #else |
24537a01 | 173 | do_qemu_set_log(log_flags, false); |
3437e545 BS |
174 | #endif |
175 | } | |
176 | ||
9a7e5424 | 177 | void qemu_set_log_filename(const char *filename); |
4fde1eba | 178 | int qemu_str_to_log_mask(const char *str); |
6d2c5146 | 179 | |
59a6fa6e PM |
180 | /* Print a usage message listing all the valid logging categories |
181 | * to the specified FILE*. | |
182 | */ | |
183 | void qemu_print_log_usage(FILE *f); | |
184 | ||
79383c9c | 185 | #endif |