]> git.proxmox.com Git - qemu.git/blob - include/qemu/log.h
log.h: Supply missing includes
[qemu.git] / include / qemu / log.h
1 #ifndef QEMU_LOG_H
2 #define QEMU_LOG_H
3
4 #include <stdarg.h>
5 #include <stdbool.h>
6 #include <stdio.h>
7 #include "qemu/compiler.h"
8 #ifdef NEED_CPU_H
9 #include "disas/disas.h"
10 #endif
11
12 /* Private global variables, don't use */
13 extern FILE *qemu_logfile;
14 extern int qemu_loglevel;
15
16 /*
17 * The new API:
18 *
19 */
20
21 /* Log settings checking macros: */
22
23 /* Returns true if qemu_log() will really write somewhere
24 */
25 static inline bool qemu_log_enabled(void)
26 {
27 return qemu_logfile != NULL;
28 }
29
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)
37 #define CPU_LOG_IOPORT (1 << 7)
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
43 /* Returns true if a bit is set in the current loglevel mask
44 */
45 static inline bool qemu_loglevel_mask(int mask)
46 {
47 return (qemu_loglevel & mask) != 0;
48 }
49
50 /* Logging functions: */
51
52 /* main logging function
53 */
54 void GCC_FMT_ATTR(1, 2) qemu_log(const char *fmt, ...);
55
56 /* vfprintf-like logging function
57 */
58 static inline void GCC_FMT_ATTR(1, 0)
59 qemu_log_vprintf(const char *fmt, va_list va)
60 {
61 if (qemu_logfile) {
62 vfprintf(qemu_logfile, fmt, va);
63 }
64 }
65
66 /* log only if a bit is set on the current loglevel mask
67 */
68 void GCC_FMT_ATTR(2, 3) qemu_log_mask(int mask, const char *fmt, ...);
69
70
71 /* Special cases: */
72
73 #ifdef NEED_CPU_H
74 /* cpu_dump_state() logging functions: */
75 static inline void log_cpu_state(CPUArchState *env1, int flags)
76 {
77 if (qemu_log_enabled()) {
78 cpu_dump_state(env1, qemu_logfile, fprintf, flags);
79 }
80 }
81
82 static inline void log_cpu_state_mask(int mask, CPUArchState *env1, int flags)
83 {
84 if (qemu_loglevel & mask) {
85 log_cpu_state(env1, flags);
86 }
87 }
88
89 /* disas() and target_disas() to qemu_logfile: */
90 static inline void log_target_disas(CPUArchState *env, target_ulong start,
91 target_ulong len, int flags)
92 {
93 target_disas(qemu_logfile, env, start, len, flags);
94 }
95
96 static inline void log_disas(void *code, unsigned long size)
97 {
98 disas(qemu_logfile, code, size);
99 }
100
101 #if defined(CONFIG_USER_ONLY)
102 /* page_dump() output to the log file: */
103 static inline void log_page_dump(void)
104 {
105 page_dump(qemu_logfile);
106 }
107 #endif
108 #endif
109
110
111 /* Maintenance: */
112
113 /* fflush() the log file */
114 static inline void qemu_log_flush(void)
115 {
116 fflush(qemu_logfile);
117 }
118
119 /* Close the log file */
120 static inline void qemu_log_close(void)
121 {
122 if (qemu_logfile) {
123 if (qemu_logfile != stderr) {
124 fclose(qemu_logfile);
125 }
126 qemu_logfile = NULL;
127 }
128 }
129
130 /* Set up a new log file */
131 static inline void qemu_log_set_file(FILE *f)
132 {
133 qemu_logfile = f;
134 }
135
136 /* define log items */
137 typedef struct QEMULogItem {
138 int mask;
139 const char *name;
140 const char *help;
141 } QEMULogItem;
142
143 extern const QEMULogItem qemu_log_items[];
144
145 /* This is the function that actually does the work of
146 * changing the log level; it should only be accessed via
147 * the qemu_set_log() wrapper.
148 */
149 void do_qemu_set_log(int log_flags, bool use_own_buffers);
150
151 static inline void qemu_set_log(int log_flags)
152 {
153 #ifdef CONFIG_USER_ONLY
154 do_qemu_set_log(log_flags, true);
155 #else
156 do_qemu_set_log(log_flags, false);
157 #endif
158 }
159
160 void qemu_set_log_filename(const char *filename);
161 int qemu_str_to_log_mask(const char *str);
162
163 /* Print a usage message listing all the valid logging categories
164 * to the specified FILE*.
165 */
166 void qemu_print_log_usage(FILE *f);
167
168 #endif