]>
Commit | Line | Data |
---|---|---|
79383c9c BS |
1 | #ifndef QEMU_LOG_H |
2 | #define QEMU_LOG_H | |
3 | ||
eeacee4d BS |
4 | #include <stdarg.h> |
5 | #ifdef NEED_CPU_H | |
6 | #include "disas.h" | |
7 | #endif | |
8 | ||
9 | /* Private global variables, don't use */ | |
10 | extern FILE *qemu_logfile; | |
11 | extern int qemu_loglevel; | |
79383c9c | 12 | |
6d2c5146 AL |
13 | /* |
14 | * The new API: | |
15 | * | |
16 | */ | |
17 | ||
18 | /* Log settings checking macros: */ | |
19 | ||
20 | /* Returns true if qemu_log() will really write somewhere | |
21 | */ | |
eeacee4d BS |
22 | static inline bool qemu_log_enabled(void) |
23 | { | |
24 | return qemu_logfile != NULL; | |
25 | } | |
6d2c5146 | 26 | |
5726c27f BS |
27 | #define CPU_LOG_TB_OUT_ASM (1 << 0) |
28 | #define CPU_LOG_TB_IN_ASM (1 << 1) | |
29 | #define CPU_LOG_TB_OP (1 << 2) | |
30 | #define CPU_LOG_TB_OP_OPT (1 << 3) | |
31 | #define CPU_LOG_INT (1 << 4) | |
32 | #define CPU_LOG_EXEC (1 << 5) | |
33 | #define CPU_LOG_PCALL (1 << 6) | |
34 | #define CPU_LOG_IOPORT (1 << 7) | |
35 | #define CPU_LOG_TB_CPU (1 << 8) | |
36 | #define CPU_LOG_RESET (1 << 9) | |
37 | ||
6d2c5146 AL |
38 | /* Returns true if a bit is set in the current loglevel mask |
39 | */ | |
eeacee4d BS |
40 | static inline bool qemu_loglevel_mask(int mask) |
41 | { | |
42 | return (qemu_loglevel & mask) != 0; | |
43 | } | |
6d2c5146 | 44 | |
6d2c5146 AL |
45 | /* Logging functions: */ |
46 | ||
47 | /* main logging function | |
48 | */ | |
eeacee4d | 49 | void GCC_FMT_ATTR(1, 2) qemu_log(const char *fmt, ...); |
6d2c5146 AL |
50 | |
51 | /* vfprintf-like logging function | |
52 | */ | |
eeacee4d BS |
53 | static inline void qemu_log_vprintf(const char *fmt, va_list va) |
54 | { | |
55 | if (qemu_logfile) { | |
56 | vfprintf(qemu_logfile, fmt, va); | |
57 | } | |
58 | } | |
6d2c5146 AL |
59 | |
60 | /* log only if a bit is set on the current loglevel mask | |
61 | */ | |
eeacee4d | 62 | void GCC_FMT_ATTR(2, 3) qemu_log_mask(int mask, const char *fmt, ...); |
6d2c5146 AL |
63 | |
64 | ||
6d2c5146 AL |
65 | /* Special cases: */ |
66 | ||
3b823210 | 67 | #ifdef NEED_CPU_H |
6d2c5146 | 68 | /* cpu_dump_state() logging functions: */ |
eeacee4d BS |
69 | static inline void log_cpu_state(CPUArchState *env1, int flags) |
70 | { | |
71 | cpu_dump_state(env1, qemu_logfile, fprintf, flags); | |
72 | } | |
73 | ||
74 | static inline void log_cpu_state_mask(int mask, CPUArchState *env1, int flags) | |
75 | { | |
76 | if (qemu_loglevel & mask) { | |
77 | log_cpu_state(env1, flags); | |
78 | } | |
79 | } | |
80 | ||
81 | /* disas() and target_disas() to qemu_logfile: */ | |
82 | static inline void log_target_disas(target_ulong start, target_ulong len, | |
83 | int flags) | |
84 | { | |
85 | target_disas(qemu_logfile, start, len, flags); | |
86 | } | |
87 | ||
88 | static inline void log_disas(void *code, unsigned long size) | |
89 | { | |
90 | disas(qemu_logfile, code, size); | |
91 | } | |
92 | ||
93 | #if defined(CONFIG_USER_ONLY) | |
6d2c5146 | 94 | /* page_dump() output to the log file: */ |
eeacee4d BS |
95 | static inline void log_page_dump(void) |
96 | { | |
97 | page_dump(qemu_logfile); | |
98 | } | |
99 | #endif | |
3b823210 | 100 | #endif |
6d2c5146 AL |
101 | |
102 | ||
6d2c5146 AL |
103 | /* Maintenance: */ |
104 | ||
105 | /* fflush() the log file */ | |
eeacee4d BS |
106 | static inline void qemu_log_flush(void) |
107 | { | |
108 | fflush(qemu_logfile); | |
109 | } | |
6d2c5146 AL |
110 | |
111 | /* Close the log file */ | |
eeacee4d BS |
112 | static inline void qemu_log_close(void) |
113 | { | |
114 | fclose(qemu_logfile); | |
115 | qemu_logfile = NULL; | |
116 | } | |
6d2c5146 AL |
117 | |
118 | /* Set up a new log file */ | |
eeacee4d BS |
119 | static inline void qemu_log_set_file(FILE *f) |
120 | { | |
121 | qemu_logfile = f; | |
122 | } | |
6d2c5146 AL |
123 | |
124 | /* Set up a new log file, only if none is set */ | |
eeacee4d BS |
125 | static inline void qemu_log_try_set_file(FILE *f) |
126 | { | |
127 | if (!qemu_logfile) { | |
128 | qemu_logfile = f; | |
129 | } | |
130 | } | |
6d2c5146 | 131 | |
5726c27f BS |
132 | /* define log items */ |
133 | typedef struct CPULogItem { | |
134 | int mask; | |
135 | const char *name; | |
136 | const char *help; | |
137 | } CPULogItem; | |
138 | ||
139 | extern const CPULogItem cpu_log_items[]; | |
140 | ||
141 | void cpu_set_log(int log_flags); | |
142 | void cpu_set_log_filename(const char *filename); | |
143 | int cpu_str_to_log_mask(const char *str); | |
6d2c5146 | 144 | |
79383c9c | 145 | #endif |