]> Git Repo - qemu.git/blame - include/qemu/log.h
qemu_log_lock/unlock now preserves the qemu_logfile handle.
[qemu.git] / include / qemu / log.h
CommitLineData
79383c9c
BS
1#ifndef QEMU_LOG_H
2#define QEMU_LOG_H
3
be0aa7ac
PM
4/* A small part of this API is split into its own header */
5#include "qemu/log-for-trace.h"
eeacee4d 6
be0aa7ac 7/* Private global variable, don't use */
eeacee4d 8extern FILE *qemu_logfile;
79383c9c 9
6d2c5146
AL
10/*
11 * The new API:
12 *
13 */
14
15/* Log settings checking macros: */
16
17/* Returns true if qemu_log() will really write somewhere
18 */
eeacee4d
BS
19static inline bool qemu_log_enabled(void)
20{
21 return qemu_logfile != NULL;
22}
6d2c5146 23
013a2942
PB
24/* Returns true if qemu_log() will write somewhere else than stderr
25 */
26static inline bool qemu_log_separate(void)
27{
28 return qemu_logfile != NULL && qemu_logfile != stderr;
29}
30
5726c27f
BS
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)
5726c27f
BS
38#define CPU_LOG_TB_CPU (1 << 8)
39#define CPU_LOG_RESET (1 << 9)
dafdf1ab 40#define LOG_UNIMP (1 << 10)
e54eba19 41#define LOG_GUEST_ERROR (1 << 11)
339aaf5b 42#define CPU_LOG_MMU (1 << 12)
89a82cd4 43#define CPU_LOG_TB_NOCHAIN (1 << 13)
13829020 44#define CPU_LOG_PAGE (1 << 14)
be0aa7ac 45/* LOG_TRACE (1 << 15) is defined in log-for-trace.h */
5a18407f 46#define CPU_LOG_TB_OP_IND (1 << 16)
ae765180 47#define CPU_LOG_TB_FPU (1 << 17)
ca76a669 48#define CPU_LOG_PLUGIN (1 << 18)
5726c27f 49
1ee73216
RH
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.
54 */
55
fc59d2d8 56static inline FILE *qemu_log_lock(void)
1ee73216
RH
57{
58 qemu_flockfile(qemu_logfile);
fc59d2d8 59 return logfile->fd;
1ee73216
RH
60}
61
fc59d2d8 62static inline void qemu_log_unlock(FILE *fd)
1ee73216 63{
fc59d2d8
RF
64 if (fd) {
65 qemu_funlockfile(fd);
66 }
1ee73216
RH
67}
68
6d2c5146
AL
69/* Logging functions: */
70
6d2c5146
AL
71/* vfprintf-like logging function
72 */
726f8cbf
SW
73static inline void GCC_FMT_ATTR(1, 0)
74qemu_log_vprintf(const char *fmt, va_list va)
eeacee4d
BS
75{
76 if (qemu_logfile) {
77 vfprintf(qemu_logfile, fmt, va);
78 }
79}
6d2c5146 80
7ee60623
PM
81/* log only if a bit is set on the current loglevel mask:
82 * @mask: bit to check in the mask
83 * @fmt: printf-style format string
84 * @args: optional arguments for format string
6d2c5146 85 */
7ee60623
PM
86#define qemu_log_mask(MASK, FMT, ...) \
87 do { \
88 if (unlikely(qemu_loglevel_mask(MASK))) { \
89 qemu_log(FMT, ## __VA_ARGS__); \
90 } \
91 } while (0)
6d2c5146 92
d977e1c2
AB
93/* log only if a bit is set on the current loglevel mask
94 * and we are in the address range we care about:
95 * @mask: bit to check in the mask
96 * @addr: address to check in dfilter
97 * @fmt: printf-style format string
98 * @args: optional arguments for format string
99 */
100#define qemu_log_mask_and_addr(MASK, ADDR, FMT, ...) \
101 do { \
102 if (unlikely(qemu_loglevel_mask(MASK)) && \
103 qemu_log_in_addr_range(ADDR)) { \
104 qemu_log(FMT, ## __VA_ARGS__); \
105 } \
106 } while (0)
107
6d2c5146
AL
108/* Maintenance: */
109
5726c27f 110/* define log items */
38dad9e5 111typedef struct QEMULogItem {
5726c27f
BS
112 int mask;
113 const char *name;
114 const char *help;
38dad9e5 115} QEMULogItem;
5726c27f 116
38dad9e5 117extern const QEMULogItem qemu_log_items[];
5726c27f 118
f2937a33
PB
119void qemu_set_log(int log_flags);
120void qemu_log_needs_buffers(void);
daa76aa4 121void qemu_set_log_filename(const char *filename, Error **errp);
bd6fee9f 122void qemu_set_dfilter_ranges(const char *ranges, Error **errp);
3514552e 123bool qemu_log_in_addr_range(uint64_t addr);
4fde1eba 124int qemu_str_to_log_mask(const char *str);
6d2c5146 125
59a6fa6e
PM
126/* Print a usage message listing all the valid logging categories
127 * to the specified FILE*.
128 */
129void qemu_print_log_usage(FILE *f);
130
99affd1d
DL
131/* fflush() the log file */
132void qemu_log_flush(void);
133/* Close the log file */
134void qemu_log_close(void);
135
79383c9c 136#endif
This page took 0.751451 seconds and 4 git commands to generate.