]> git.proxmox.com Git - qemu.git/blame - include/qemu/log.h
qemu-log: Rename CPULogItem, cpu_log_items to QEMULogItem, qemu_log_items
[qemu.git] / include / qemu / log.h
CommitLineData
79383c9c
BS
1#ifndef QEMU_LOG_H
2#define QEMU_LOG_H
3
eeacee4d
BS
4#include <stdarg.h>
5#ifdef NEED_CPU_H
76cad711 6#include "disas/disas.h"
eeacee4d
BS
7#endif
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
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)
dafdf1ab 37#define LOG_UNIMP (1 << 10)
e54eba19 38#define LOG_GUEST_ERROR (1 << 11)
5726c27f 39
6d2c5146
AL
40/* Returns true if a bit is set in the current loglevel mask
41 */
eeacee4d
BS
42static inline bool qemu_loglevel_mask(int mask)
43{
44 return (qemu_loglevel & mask) != 0;
45}
6d2c5146 46
6d2c5146
AL
47/* Logging functions: */
48
49/* main logging function
50 */
eeacee4d 51void GCC_FMT_ATTR(1, 2) qemu_log(const char *fmt, ...);
6d2c5146
AL
52
53/* vfprintf-like logging function
54 */
726f8cbf
SW
55static inline void GCC_FMT_ATTR(1, 0)
56qemu_log_vprintf(const char *fmt, va_list va)
eeacee4d
BS
57{
58 if (qemu_logfile) {
59 vfprintf(qemu_logfile, fmt, va);
60 }
61}
6d2c5146
AL
62
63/* log only if a bit is set on the current loglevel mask
64 */
eeacee4d 65void GCC_FMT_ATTR(2, 3) qemu_log_mask(int mask, const char *fmt, ...);
6d2c5146
AL
66
67
6d2c5146
AL
68/* Special cases: */
69
3b823210 70#ifdef NEED_CPU_H
6d2c5146 71/* cpu_dump_state() logging functions: */
eeacee4d
BS
72static inline void log_cpu_state(CPUArchState *env1, int flags)
73{
c8f803e7
FC
74 if (qemu_log_enabled()) {
75 cpu_dump_state(env1, qemu_logfile, fprintf, flags);
76 }
eeacee4d
BS
77}
78
79static inline void log_cpu_state_mask(int mask, CPUArchState *env1, int flags)
80{
81 if (qemu_loglevel & mask) {
82 log_cpu_state(env1, flags);
83 }
84}
85
86/* disas() and target_disas() to qemu_logfile: */
f4359b9f
BS
87static inline void log_target_disas(CPUArchState *env, target_ulong start,
88 target_ulong len, int flags)
eeacee4d 89{
f4359b9f 90 target_disas(qemu_logfile, env, start, len, flags);
eeacee4d
BS
91}
92
93static inline void log_disas(void *code, unsigned long size)
94{
95 disas(qemu_logfile, code, size);
96}
97
98#if defined(CONFIG_USER_ONLY)
6d2c5146 99/* page_dump() output to the log file: */
eeacee4d
BS
100static inline void log_page_dump(void)
101{
102 page_dump(qemu_logfile);
103}
104#endif
3b823210 105#endif
6d2c5146
AL
106
107
6d2c5146
AL
108/* Maintenance: */
109
110/* fflush() the log file */
eeacee4d
BS
111static inline void qemu_log_flush(void)
112{
113 fflush(qemu_logfile);
114}
6d2c5146
AL
115
116/* Close the log file */
eeacee4d
BS
117static inline void qemu_log_close(void)
118{
119 fclose(qemu_logfile);
120 qemu_logfile = NULL;
121}
6d2c5146
AL
122
123/* Set up a new log file */
eeacee4d
BS
124static inline void qemu_log_set_file(FILE *f)
125{
126 qemu_logfile = f;
127}
6d2c5146
AL
128
129/* Set up a new log file, only if none is set */
eeacee4d
BS
130static inline void qemu_log_try_set_file(FILE *f)
131{
132 if (!qemu_logfile) {
133 qemu_logfile = f;
134 }
135}
6d2c5146 136
5726c27f 137/* define log items */
38dad9e5 138typedef struct QEMULogItem {
5726c27f
BS
139 int mask;
140 const char *name;
141 const char *help;
38dad9e5 142} QEMULogItem;
5726c27f 143
38dad9e5 144extern const QEMULogItem qemu_log_items[];
5726c27f 145
24537a01
PM
146/* This is the function that actually does the work of
147 * changing the log level; it should only be accessed via
148 * the qemu_set_log() wrapper.
149 */
150void do_qemu_set_log(int log_flags, bool use_own_buffers);
3437e545 151
24537a01 152static inline void qemu_set_log(int log_flags)
3437e545
BS
153{
154#ifdef CONFIG_USER_ONLY
24537a01 155 do_qemu_set_log(log_flags, true);
3437e545 156#else
24537a01 157 do_qemu_set_log(log_flags, false);
3437e545
BS
158#endif
159}
160
9a7e5424 161void qemu_set_log_filename(const char *filename);
4fde1eba 162int qemu_str_to_log_mask(const char *str);
6d2c5146 163
59a6fa6e
PM
164/* Print a usage message listing all the valid logging categories
165 * to the specified FILE*.
166 */
167void qemu_print_log_usage(FILE *f);
168
79383c9c 169#endif