plugin: add qemu_plugin_outs helper
[qemu/ar7.git] / include / qemu / log.h
bloba91105b2adca5bb28e1ff0a04b4480cd446e456e
1 #ifndef QEMU_LOG_H
2 #define QEMU_LOG_H
4 /* A small part of this API is split into its own header */
5 #include "qemu/log-for-trace.h"
7 /* Private global variable, don't use */
8 extern FILE *qemu_logfile;
10 /*
11 * The new API:
15 /* Log settings checking macros: */
17 /* Returns true if qemu_log() will really write somewhere
19 static inline bool qemu_log_enabled(void)
21 return qemu_logfile != NULL;
24 /* Returns true if qemu_log() will write somewhere else than stderr
26 static inline bool qemu_log_separate(void)
28 return qemu_logfile != NULL && qemu_logfile != stderr;
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_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 #define CPU_LOG_MMU (1 << 12)
43 #define CPU_LOG_TB_NOCHAIN (1 << 13)
44 #define CPU_LOG_PAGE (1 << 14)
45 /* LOG_TRACE (1 << 15) is defined in log-for-trace.h */
46 #define CPU_LOG_TB_OP_IND (1 << 16)
47 #define CPU_LOG_TB_FPU (1 << 17)
48 #define CPU_LOG_PLUGIN (1 << 18)
50 /* Lock output for a series of related logs. Since this is not needed
51 * for a single qemu_log / qemu_log_mask / qemu_log_mask_and_addr, we
52 * assume that qemu_loglevel_mask has already been tested, and that
53 * qemu_loglevel is never set when qemu_logfile is unset.
56 static inline void qemu_log_lock(void)
58 qemu_flockfile(qemu_logfile);
61 static inline void qemu_log_unlock(void)
63 qemu_funlockfile(qemu_logfile);
66 /* Logging functions: */
68 /* vfprintf-like logging function
70 static inline void GCC_FMT_ATTR(1, 0)
71 qemu_log_vprintf(const char *fmt, va_list va)
73 if (qemu_logfile) {
74 vfprintf(qemu_logfile, fmt, va);
78 /* log only if a bit is set on the current loglevel mask:
79 * @mask: bit to check in the mask
80 * @fmt: printf-style format string
81 * @args: optional arguments for format string
83 #define qemu_log_mask(MASK, FMT, ...) \
84 do { \
85 if (unlikely(qemu_loglevel_mask(MASK))) { \
86 qemu_log(FMT, ## __VA_ARGS__); \
87 } \
88 } while (0)
90 /* log only if a bit is set on the current loglevel mask
91 * and we are in the address range we care about:
92 * @mask: bit to check in the mask
93 * @addr: address to check in dfilter
94 * @fmt: printf-style format string
95 * @args: optional arguments for format string
97 #define qemu_log_mask_and_addr(MASK, ADDR, FMT, ...) \
98 do { \
99 if (unlikely(qemu_loglevel_mask(MASK)) && \
100 qemu_log_in_addr_range(ADDR)) { \
101 qemu_log(FMT, ## __VA_ARGS__); \
103 } while (0)
105 /* Maintenance: */
107 /* define log items */
108 typedef struct QEMULogItem {
109 int mask;
110 const char *name;
111 const char *help;
112 } QEMULogItem;
114 extern const QEMULogItem qemu_log_items[];
116 void qemu_set_log(int log_flags);
117 void qemu_log_needs_buffers(void);
118 void qemu_set_log_filename(const char *filename, Error **errp);
119 void qemu_set_dfilter_ranges(const char *ranges, Error **errp);
120 bool qemu_log_in_addr_range(uint64_t addr);
121 int qemu_str_to_log_mask(const char *str);
123 /* Print a usage message listing all the valid logging categories
124 * to the specified FILE*.
126 void qemu_print_log_usage(FILE *f);
128 /* fflush() the log file */
129 void qemu_log_flush(void);
130 /* Close the log file */
131 void qemu_log_close(void);
133 #endif