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 /* Returns true if qemu_log() will write somewhere else than stderr
33 static inline bool qemu_log_separate(void)
35 return qemu_logfile
!= NULL
&& qemu_logfile
!= stderr
;
38 #define CPU_LOG_TB_OUT_ASM (1 << 0)
39 #define CPU_LOG_TB_IN_ASM (1 << 1)
40 #define CPU_LOG_TB_OP (1 << 2)
41 #define CPU_LOG_TB_OP_OPT (1 << 3)
42 #define CPU_LOG_INT (1 << 4)
43 #define CPU_LOG_EXEC (1 << 5)
44 #define CPU_LOG_PCALL (1 << 6)
45 #define CPU_LOG_TB_CPU (1 << 8)
46 #define CPU_LOG_RESET (1 << 9)
47 #define LOG_UNIMP (1 << 10)
48 #define LOG_GUEST_ERROR (1 << 11)
49 #define CPU_LOG_MMU (1 << 12)
50 #define CPU_LOG_TB_NOCHAIN (1 << 13)
51 #define CPU_LOG_PAGE (1 << 14)
53 /* Returns true if a bit is set in the current loglevel mask
55 static inline bool qemu_loglevel_mask(int mask
)
57 return (qemu_loglevel
& mask
) != 0;
60 /* Logging functions: */
62 /* main logging function
64 void GCC_FMT_ATTR(1, 2) qemu_log(const char *fmt
, ...);
66 /* vfprintf-like logging function
68 static inline void GCC_FMT_ATTR(1, 0)
69 qemu_log_vprintf(const char *fmt
, va_list va
)
72 vfprintf(qemu_logfile
, fmt
, va
);
76 /* log only if a bit is set on the current loglevel mask
78 void GCC_FMT_ATTR(2, 3) qemu_log_mask(int mask
, const char *fmt
, ...);
83 /* cpu_dump_state() logging functions: */
86 * @cpu: The CPU whose state is to be logged.
87 * @flags: Flags what to log.
89 * Logs the output of cpu_dump_state().
91 static inline void log_cpu_state(CPUState
*cpu
, int flags
)
93 if (qemu_log_enabled()) {
94 cpu_dump_state(cpu
, qemu_logfile
, fprintf
, flags
);
100 * @mask: Mask when to log.
101 * @cpu: The CPU whose state is to be logged.
102 * @flags: Flags what to log.
104 * Logs the output of cpu_dump_state() if loglevel includes @mask.
106 static inline void log_cpu_state_mask(int mask
, CPUState
*cpu
, int flags
)
108 if (qemu_loglevel
& mask
) {
109 log_cpu_state(cpu
, flags
);
114 /* disas() and target_disas() to qemu_logfile: */
115 static inline void log_target_disas(CPUState
*cpu
, target_ulong start
,
116 target_ulong len
, int flags
)
118 target_disas(qemu_logfile
, cpu
, start
, len
, flags
);
121 static inline void log_disas(void *code
, unsigned long size
)
123 disas(qemu_logfile
, code
, size
);
126 #if defined(CONFIG_USER_ONLY)
127 /* page_dump() output to the log file: */
128 static inline void log_page_dump(void)
130 page_dump(qemu_logfile
);
138 /* fflush() the log file */
139 static inline void qemu_log_flush(void)
141 fflush(qemu_logfile
);
144 /* Close the log file */
145 static inline void qemu_log_close(void)
148 if (qemu_logfile
!= stderr
) {
149 fclose(qemu_logfile
);
155 /* Set up a new log file */
156 static inline void qemu_log_set_file(FILE *f
)
161 /* define log items */
162 typedef struct QEMULogItem
{
168 extern const QEMULogItem qemu_log_items
[];
170 /* This is the function that actually does the work of
171 * changing the log level; it should only be accessed via
172 * the qemu_set_log() wrapper.
174 void do_qemu_set_log(int log_flags
, bool use_own_buffers
);
176 static inline void qemu_set_log(int log_flags
)
178 #ifdef CONFIG_USER_ONLY
179 do_qemu_set_log(log_flags
, true);
181 do_qemu_set_log(log_flags
, false);
185 void qemu_set_log_filename(const char *filename
);
186 int qemu_str_to_log_mask(const char *str
);
188 /* Print a usage message listing all the valid logging categories
189 * to the specified FILE*.
191 void qemu_print_log_usage(FILE *f
);