]> git.ipfire.org Git - thirdparty/qemu.git/blame - include/qemu/log.h
log: do not unnecessarily include qom/cpu.h
[thirdparty/qemu.git] / include / qemu / log.h
CommitLineData
79383c9c
BS
1#ifndef QEMU_LOG_H
2#define QEMU_LOG_H
3
eeacee4d 4#include <stdarg.h>
f3eededb
MA
5#include <stdbool.h>
6#include <stdio.h>
7#include "qemu/compiler.h"
eeacee4d
BS
8
9/* Private global variables, don't use */
10extern FILE *qemu_logfile;
11extern 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
22static inline bool qemu_log_enabled(void)
23{
24 return qemu_logfile != NULL;
25}
6d2c5146 26
013a2942
PB
27/* Returns true if qemu_log() will write somewhere else than stderr
28 */
29static inline bool qemu_log_separate(void)
30{
31 return qemu_logfile != NULL && qemu_logfile != stderr;
32}
33
5726c27f
BS
34#define CPU_LOG_TB_OUT_ASM (1 << 0)
35#define CPU_LOG_TB_IN_ASM (1 << 1)
36#define CPU_LOG_TB_OP (1 << 2)
37#define CPU_LOG_TB_OP_OPT (1 << 3)
38#define CPU_LOG_INT (1 << 4)
39#define CPU_LOG_EXEC (1 << 5)
40#define CPU_LOG_PCALL (1 << 6)
5726c27f
BS
41#define CPU_LOG_TB_CPU (1 << 8)
42#define CPU_LOG_RESET (1 << 9)
dafdf1ab 43#define LOG_UNIMP (1 << 10)
e54eba19 44#define LOG_GUEST_ERROR (1 << 11)
339aaf5b 45#define CPU_LOG_MMU (1 << 12)
89a82cd4 46#define CPU_LOG_TB_NOCHAIN (1 << 13)
13829020 47#define CPU_LOG_PAGE (1 << 14)
5726c27f 48
6d2c5146
AL
49/* Returns true if a bit is set in the current loglevel mask
50 */
eeacee4d
BS
51static inline bool qemu_loglevel_mask(int mask)
52{
53 return (qemu_loglevel & mask) != 0;
54}
6d2c5146 55
6d2c5146
AL
56/* Logging functions: */
57
58/* main logging function
59 */
eeacee4d 60void GCC_FMT_ATTR(1, 2) qemu_log(const char *fmt, ...);
6d2c5146
AL
61
62/* vfprintf-like logging function
63 */
726f8cbf
SW
64static inline void GCC_FMT_ATTR(1, 0)
65qemu_log_vprintf(const char *fmt, va_list va)
eeacee4d
BS
66{
67 if (qemu_logfile) {
68 vfprintf(qemu_logfile, fmt, va);
69 }
70}
6d2c5146
AL
71
72/* log only if a bit is set on the current loglevel mask
73 */
eeacee4d 74void GCC_FMT_ATTR(2, 3) qemu_log_mask(int mask, const char *fmt, ...);
6d2c5146
AL
75
76
6d2c5146
AL
77/* Maintenance: */
78
79/* fflush() the log file */
eeacee4d
BS
80static inline void qemu_log_flush(void)
81{
82 fflush(qemu_logfile);
83}
6d2c5146
AL
84
85/* Close the log file */
eeacee4d
BS
86static inline void qemu_log_close(void)
87{
989b697d
PM
88 if (qemu_logfile) {
89 if (qemu_logfile != stderr) {
90 fclose(qemu_logfile);
91 }
92 qemu_logfile = NULL;
93 }
eeacee4d 94}
6d2c5146
AL
95
96/* Set up a new log file */
eeacee4d
BS
97static inline void qemu_log_set_file(FILE *f)
98{
99 qemu_logfile = f;
100}
6d2c5146 101
5726c27f 102/* define log items */
38dad9e5 103typedef struct QEMULogItem {
5726c27f
BS
104 int mask;
105 const char *name;
106 const char *help;
38dad9e5 107} QEMULogItem;
5726c27f 108
38dad9e5 109extern const QEMULogItem qemu_log_items[];
5726c27f 110
24537a01
PM
111/* This is the function that actually does the work of
112 * changing the log level; it should only be accessed via
113 * the qemu_set_log() wrapper.
114 */
115void do_qemu_set_log(int log_flags, bool use_own_buffers);
3437e545 116
24537a01 117static inline void qemu_set_log(int log_flags)
3437e545
BS
118{
119#ifdef CONFIG_USER_ONLY
24537a01 120 do_qemu_set_log(log_flags, true);
3437e545 121#else
24537a01 122 do_qemu_set_log(log_flags, false);
3437e545
BS
123#endif
124}
125
9a7e5424 126void qemu_set_log_filename(const char *filename);
4fde1eba 127int qemu_str_to_log_mask(const char *str);
6d2c5146 128
59a6fa6e
PM
129/* Print a usage message listing all the valid logging categories
130 * to the specified FILE*.
131 */
132void qemu_print_log_usage(FILE *f);
133
79383c9c 134#endif