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#include "qom/cpu.h"
9#ifdef NEED_CPU_H
10#include "disas/disas.h"
11#endif
12
13
14extern FILE *qemu_logfile;
15extern int qemu_loglevel;
16
17
18
19
20
21
22
23
24
25
26static inline bool qemu_log_enabled(void)
27{
28 return qemu_logfile != NULL;
29}
30
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
44
45
46static inline bool qemu_loglevel_mask(int mask)
47{
48 return (qemu_loglevel & mask) != 0;
49}
50
51
52
53
54
55void GCC_FMT_ATTR(1, 2) qemu_log(const char *fmt, ...);
56
57
58
59static inline void GCC_FMT_ATTR(1, 0)
60qemu_log_vprintf(const char *fmt, va_list va)
61{
62 if (qemu_logfile) {
63 vfprintf(qemu_logfile, fmt, va);
64 }
65}
66
67
68
69void GCC_FMT_ATTR(2, 3) qemu_log_mask(int mask, const char *fmt, ...);
70
71
72
73
74
75
76
77
78
79
80
81
82static inline void log_cpu_state(CPUState *cpu, int flags)
83{
84 if (qemu_log_enabled()) {
85 cpu_dump_state(cpu, qemu_logfile, fprintf, flags);
86 }
87}
88
89
90
91
92
93
94
95
96
97static inline void log_cpu_state_mask(int mask, CPUState *cpu, int flags)
98{
99 if (qemu_loglevel & mask) {
100 log_cpu_state(cpu, flags);
101 }
102}
103
104#ifdef NEED_CPU_H
105
106static inline void log_target_disas(CPUArchState *env, target_ulong start,
107 target_ulong len, int flags)
108{
109 target_disas(qemu_logfile, env, start, len, flags);
110}
111
112static inline void log_disas(void *code, unsigned long size)
113{
114 disas(qemu_logfile, code, size);
115}
116
117#if defined(CONFIG_USER_ONLY)
118
119static inline void log_page_dump(void)
120{
121 page_dump(qemu_logfile);
122}
123#endif
124#endif
125
126
127
128
129
130static inline void qemu_log_flush(void)
131{
132 fflush(qemu_logfile);
133}
134
135
136static inline void qemu_log_close(void)
137{
138 if (qemu_logfile) {
139 if (qemu_logfile != stderr) {
140 fclose(qemu_logfile);
141 }
142 qemu_logfile = NULL;
143 }
144}
145
146
147static inline void qemu_log_set_file(FILE *f)
148{
149 qemu_logfile = f;
150}
151
152
153typedef struct QEMULogItem {
154 int mask;
155 const char *name;
156 const char *help;
157} QEMULogItem;
158
159extern const QEMULogItem qemu_log_items[];
160
161
162
163
164
165void do_qemu_set_log(int log_flags, bool use_own_buffers);
166
167static inline void qemu_set_log(int log_flags)
168{
169#ifdef CONFIG_USER_ONLY
170 do_qemu_set_log(log_flags, true);
171#else
172 do_qemu_set_log(log_flags, false);
173#endif
174}
175
176void qemu_set_log_filename(const char *filename);
177int qemu_str_to_log_mask(const char *str);
178
179
180
181
182void qemu_print_log_usage(FILE *f);
183
184#endif
185