]> Git Repo - qemu.git/blame - include/qemu/log.h
user: introduce "-d page"
[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"
a0762859 8#include "qom/cpu.h"
eeacee4d 9#ifdef NEED_CPU_H
76cad711 10#include "disas/disas.h"
eeacee4d
BS
11#endif
12
13/* Private global variables, don't use */
14extern FILE *qemu_logfile;
15extern int qemu_loglevel;
79383c9c 16
6d2c5146
AL
17/*
18 * The new API:
19 *
20 */
21
22/* Log settings checking macros: */
23
24/* Returns true if qemu_log() will really write somewhere
25 */
eeacee4d
BS
26static inline bool qemu_log_enabled(void)
27{
28 return qemu_logfile != NULL;
29}
6d2c5146 30
013a2942
PB
31/* Returns true if qemu_log() will write somewhere else than stderr
32 */
33static inline bool qemu_log_separate(void)
34{
35 return qemu_logfile != NULL && qemu_logfile != stderr;
36}
37
5726c27f
BS
38#define CPU_LOG_TB_OUT_ASM (1 << 0)
39#define CPU_LOG_TB_IN_ASM (1 << 1)
40#define CPU_LOG_TB_OP (1 << 2)
41#define CPU_LOG_TB_OP_OPT (1 << 3)
42#define CPU_LOG_INT (1 << 4)
43#define CPU_LOG_EXEC (1 << 5)
44#define CPU_LOG_PCALL (1 << 6)
5726c27f
BS
45#define CPU_LOG_TB_CPU (1 << 8)
46#define CPU_LOG_RESET (1 << 9)
dafdf1ab 47#define LOG_UNIMP (1 << 10)
e54eba19 48#define LOG_GUEST_ERROR (1 << 11)
339aaf5b 49#define CPU_LOG_MMU (1 << 12)
89a82cd4 50#define CPU_LOG_TB_NOCHAIN (1 << 13)
13829020 51#define CPU_LOG_PAGE (1 << 14)
5726c27f 52
6d2c5146
AL
53/* Returns true if a bit is set in the current loglevel mask
54 */
eeacee4d
BS
55static inline bool qemu_loglevel_mask(int mask)
56{
57 return (qemu_loglevel & mask) != 0;
58}
6d2c5146 59
6d2c5146
AL
60/* Logging functions: */
61
62/* main logging function
63 */
eeacee4d 64void GCC_FMT_ATTR(1, 2) qemu_log(const char *fmt, ...);
6d2c5146
AL
65
66/* vfprintf-like logging function
67 */
726f8cbf
SW
68static inline void GCC_FMT_ATTR(1, 0)
69qemu_log_vprintf(const char *fmt, va_list va)
eeacee4d
BS
70{
71 if (qemu_logfile) {
72 vfprintf(qemu_logfile, fmt, va);
73 }
74}
6d2c5146
AL
75
76/* log only if a bit is set on the current loglevel mask
77 */
eeacee4d 78void GCC_FMT_ATTR(2, 3) qemu_log_mask(int mask, const char *fmt, ...);
6d2c5146
AL
79
80
6d2c5146
AL
81/* Special cases: */
82
83/* cpu_dump_state() logging functions: */
a0762859
AF
84/**
85 * log_cpu_state:
86 * @cpu: The CPU whose state is to be logged.
87 * @flags: Flags what to log.
88 *
89 * Logs the output of cpu_dump_state().
90 */
91static inline void log_cpu_state(CPUState *cpu, int flags)
eeacee4d 92{
c8f803e7 93 if (qemu_log_enabled()) {
a0762859 94 cpu_dump_state(cpu, qemu_logfile, fprintf, flags);
c8f803e7 95 }
eeacee4d
BS
96}
97
a0762859
AF
98/**
99 * log_cpu_state_mask:
100 * @mask: Mask when to log.
101 * @cpu: The CPU whose state is to be logged.
102 * @flags: Flags what to log.
103 *
104 * Logs the output of cpu_dump_state() if loglevel includes @mask.
105 */
106static inline void log_cpu_state_mask(int mask, CPUState *cpu, int flags)
eeacee4d
BS
107{
108 if (qemu_loglevel & mask) {
a0762859 109 log_cpu_state(cpu, flags);
eeacee4d
BS
110 }
111}
112
a0762859 113#ifdef NEED_CPU_H
eeacee4d 114/* disas() and target_disas() to qemu_logfile: */
d49190c4 115static inline void log_target_disas(CPUState *cpu, target_ulong start,
f4359b9f 116 target_ulong len, int flags)
eeacee4d 117{
d49190c4 118 target_disas(qemu_logfile, cpu, start, len, flags);
eeacee4d
BS
119}
120
121static inline void log_disas(void *code, unsigned long size)
122{
123 disas(qemu_logfile, code, size);
124}
125
126#if defined(CONFIG_USER_ONLY)
6d2c5146 127/* page_dump() output to the log file: */
eeacee4d
BS
128static inline void log_page_dump(void)
129{
130 page_dump(qemu_logfile);
131}
132#endif
3b823210 133#endif
6d2c5146
AL
134
135
6d2c5146
AL
136/* Maintenance: */
137
138/* fflush() the log file */
eeacee4d
BS
139static inline void qemu_log_flush(void)
140{
141 fflush(qemu_logfile);
142}
6d2c5146
AL
143
144/* Close the log file */
eeacee4d
BS
145static inline void qemu_log_close(void)
146{
989b697d
PM
147 if (qemu_logfile) {
148 if (qemu_logfile != stderr) {
149 fclose(qemu_logfile);
150 }
151 qemu_logfile = NULL;
152 }
eeacee4d 153}
6d2c5146
AL
154
155/* Set up a new log file */
eeacee4d
BS
156static inline void qemu_log_set_file(FILE *f)
157{
158 qemu_logfile = f;
159}
6d2c5146 160
5726c27f 161/* define log items */
38dad9e5 162typedef struct QEMULogItem {
5726c27f
BS
163 int mask;
164 const char *name;
165 const char *help;
38dad9e5 166} QEMULogItem;
5726c27f 167
38dad9e5 168extern const QEMULogItem qemu_log_items[];
5726c27f 169
24537a01
PM
170/* This is the function that actually does the work of
171 * changing the log level; it should only be accessed via
172 * the qemu_set_log() wrapper.
173 */
174void do_qemu_set_log(int log_flags, bool use_own_buffers);
3437e545 175
24537a01 176static inline void qemu_set_log(int log_flags)
3437e545
BS
177{
178#ifdef CONFIG_USER_ONLY
24537a01 179 do_qemu_set_log(log_flags, true);
3437e545 180#else
24537a01 181 do_qemu_set_log(log_flags, false);
3437e545
BS
182#endif
183}
184
9a7e5424 185void qemu_set_log_filename(const char *filename);
4fde1eba 186int qemu_str_to_log_mask(const char *str);
6d2c5146 187
59a6fa6e
PM
188/* Print a usage message listing all the valid logging categories
189 * to the specified FILE*.
190 */
191void qemu_print_log_usage(FILE *f);
192
79383c9c 193#endif
This page took 0.62822 seconds and 4 git commands to generate.