master
h 140 lines 4.33 KB
Raw
1 #ifndef QEMU_LOG_H
2 #define QEMU_LOG_H
3
4 /* A small part of this API is split into its own header */
5 #include "qemu/log-for-trace.h"
6
7 /*
8 * The new API:
9 */
10
11 /* Returns true if qemu_log() will really write somewhere. */
12 bool qemu_log_enabled(void);
13
14 /* Returns true if qemu_log() will write somewhere other than stderr. */
15 bool qemu_log_separate(void);
16
17 #define CPU_LOG_TB_OUT_ASM (1u << 0)
18 #define CPU_LOG_TB_IN_ASM (1u << 1)
19 #define CPU_LOG_TB_OP (1u << 2)
20 #define CPU_LOG_TB_OP_OPT (1u << 3)
21 #define CPU_LOG_INT (1u << 4)
22 #define CPU_LOG_EXEC (1u << 5)
23 #define CPU_LOG_PCALL (1u << 6)
24 #define CPU_LOG_TB_CPU (1u << 8)
25 #define CPU_LOG_RESET (1u << 9)
26 #define LOG_UNIMP (1u << 10)
27 #define LOG_GUEST_ERROR (1u << 11)
28 #define CPU_LOG_MMU (1u << 12)
29 #define CPU_LOG_TB_NOCHAIN (1u << 13)
30 #define CPU_LOG_PAGE (1u << 14)
31 /* LOG_TRACE (1 << 15) is defined in log-for-trace.h */
32 #define CPU_LOG_TB_OP_IND (1u << 16)
33 #define CPU_LOG_TB_FPU (1u << 17)
34 #define CPU_LOG_PLUGIN (1u << 18)
35 /* LOG_STRACE is used for user-mode strace logging. */
36 #define LOG_STRACE (1u << 19)
37 #define LOG_PER_THREAD (1u << 20)
38 #define CPU_LOG_TB_VPU (1u << 21)
39 #define LOG_TB_OP_PLUGIN (1u << 22)
40 #define LOG_INVALID_MEM (1u << 23)
41
42 /* Lock/unlock output. */
43
44 /**
45 * Acquires a lock on the current log output stream.
46 * The returned FILE object should be used with the
47 * fprintf() function to output the log message, and
48 * then qemu_log_unlock() called to release the lock.
49 *
50 * The primary use case is to be able to incrementally
51 * output fragments of a complete log message in an
52 * efficient and race free manner.
53 *
54 * The simpler qemu_log() method should normally only
55 * be used to output complete log messages, and not
56 * within scope of a qemu_log_trylock() call.
57 *
58 * A typical usage pattern would be
59 *
60 * FILE *f = qemu_log_trylock()
61 *
62 * fprintf(f, "Something ");
63 * fprintf(f, "Something ");
64 * fprintf(f, "Something ");
65 * fprintf(f, "The end\n");
66 *
67 * qemu_log_unlock(f);
68 *
69 * Returns: the current FILE if available, NULL on error
70 */
71 FILE *qemu_log_trylock(void) G_GNUC_WARN_UNUSED_RESULT;
72
73 /**
74 * As qemu_log_trylock(), but will also print the message
75 * context, if any is configured and this caused the
76 * acquisition of the FILE lock
77 */
78 FILE *qemu_log_trylock_with_context(void) G_GNUC_WARN_UNUSED_RESULT;
79
80 /**
81 * Releases the lock on the log output, previously
82 * acquired by qemu_log_trylock().
83 */
84 void qemu_log_unlock(FILE *fd);
85
86 /* Logging functions: */
87
88 /* log only if a bit is set on the current loglevel mask:
89 * @mask: bit to check in the mask
90 * @fmt: printf-style format string
91 * @args: optional arguments for format string
92 */
93 #define qemu_log_mask(MASK, FMT, ...) \
94 do { \
95 if (unlikely(qemu_loglevel_mask(MASK))) { \
96 qemu_log(FMT, ## __VA_ARGS__); \
97 } \
98 } while (0)
99
100 /* log only if a bit is set on the current loglevel mask
101 * and we are in the address range we care about:
102 * @mask: bit to check in the mask
103 * @addr: address to check in dfilter
104 * @fmt: printf-style format string
105 * @args: optional arguments for format string
106 */
107 #define qemu_log_mask_and_addr(MASK, ADDR, FMT, ...) \
108 do { \
109 if (unlikely(qemu_loglevel_mask(MASK)) && \
110 qemu_log_in_addr_range(ADDR)) { \
111 qemu_log(FMT, ## __VA_ARGS__); \
112 } \
113 } while (0)
114
115 /* Maintenance: */
116
117 /* define log items */
118 typedef struct QEMULogItem {
119 int mask;
120 const char *name;
121 const char *help;
122 } QEMULogItem;
123
124 extern const QEMULogItem qemu_log_items[];
125
126 ssize_t rust_fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream);
127
128 bool qemu_set_log(int log_flags, Error **errp);
129 bool qemu_set_log_filename(const char *filename, Error **errp);
130 bool qemu_set_log_filename_flags(const char *name, int flags, Error **errp);
131 void qemu_set_dfilter_ranges(const char *ranges, Error **errp);
132 bool qemu_log_in_addr_range(uint64_t addr);
133 int qemu_str_to_log_mask(const char *str);
134
135 /* Print a usage message listing all the valid logging categories
136 * to the specified FILE*.
137 */
138 void qemu_print_log_usage(FILE *f);
139
140 #endif