7 #include "qemu/compiler.h"
10 #include "disas/disas.h"
13 /* Private global variables, don't use */
14 extern FILE *qemu_logfile
;
15 extern int qemu_loglevel
;
22 /* Log settings checking macros: */
24 /* Returns true if qemu_log() will really write somewhere
26 static inline bool qemu_log_enabled(void)
28 return qemu_logfile
!= NULL
;
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)
41 #define LOG_UNIMP (1 << 10)
42 #define LOG_GUEST_ERROR (1 << 11)
43 #define CPU_LOG_MMU (1 << 12)
44 #define CPU_LOG_TB_NOCHAIN (1 << 13)
46 /* Returns true if a bit is set in the current loglevel mask
48 static inline bool qemu_loglevel_mask(int mask
)
50 return (qemu_loglevel
& mask
) != 0;
53 /* Logging functions: */
55 /* main logging function
57 void GCC_FMT_ATTR(1, 2) qemu_log(const char *fmt
, ...);
59 /* vfprintf-like logging function
61 static inline void GCC_FMT_ATTR(1, 0)
62 qemu_log_vprintf(const char *fmt
, va_list va
)
65 vfprintf(qemu_logfile
, fmt
, va
);
69 /* log only if a bit is set on the current loglevel mask
71 void GCC_FMT_ATTR(2, 3) qemu_log_mask(int mask
, const char *fmt
, ...);
76 /* cpu_dump_state() logging functions: */
79 * @cpu: The CPU whose state is to be logged.
80 * @flags: Flags what to log.
82 * Logs the output of cpu_dump_state().
84 static inline void log_cpu_state(CPUState
*cpu
, int flags
)
86 if (qemu_log_enabled()) {
87 cpu_dump_state(cpu
, qemu_logfile
, fprintf
, flags
);
93 * @mask: Mask when to log.
94 * @cpu: The CPU whose state is to be logged.
95 * @flags: Flags what to log.
97 * Logs the output of cpu_dump_state() if loglevel includes @mask.
99 static inline void log_cpu_state_mask(int mask
, CPUState
*cpu
, int flags
)
101 if (qemu_loglevel
& mask
) {
102 log_cpu_state(cpu
, flags
);
107 /* disas() and target_disas() to qemu_logfile: */
108 static inline void log_target_disas(CPUState
*cpu
, target_ulong start
,
109 target_ulong len
, int flags
)
111 target_disas(qemu_logfile
, cpu
, start
, len
, flags
);
114 static inline void log_disas(void *code
, unsigned long size
)
116 disas(qemu_logfile
, code
, size
);
119 #if defined(CONFIG_USER_ONLY)
120 /* page_dump() output to the log file: */
121 static inline void log_page_dump(void)
123 page_dump(qemu_logfile
);
131 /* fflush() the log file */
132 static inline void qemu_log_flush(void)
134 fflush(qemu_logfile
);
137 /* Close the log file */
138 static inline void qemu_log_close(void)
141 if (qemu_logfile
!= stderr
) {
142 fclose(qemu_logfile
);
148 /* Set up a new log file */
149 static inline void qemu_log_set_file(FILE *f
)
154 /* define log items */
155 typedef struct QEMULogItem
{
161 extern const QEMULogItem qemu_log_items
[];
163 /* This is the function that actually does the work of
164 * changing the log level; it should only be accessed via
165 * the qemu_set_log() wrapper.
167 void do_qemu_set_log(int log_flags
, bool use_own_buffers
);
169 static inline void qemu_set_log(int log_flags
)
171 #ifdef CONFIG_USER_ONLY
172 do_qemu_set_log(log_flags
, true);
174 do_qemu_set_log(log_flags
, false);
178 void qemu_set_log_filename(const char *filename
);
179 int qemu_str_to_log_mask(const char *str
);
181 /* Print a usage message listing all the valid logging categories
182 * to the specified FILE*.
184 void qemu_print_log_usage(FILE *f
);