blob: 344eca3f1b0df889c99c116dd908711c53c9b65e [file] [log] [blame]
blueswir179383c92008-08-30 09:51:20 +00001#ifndef QEMU_LOG_H
2#define QEMU_LOG_H
3
Blue Swirleeacee42012-06-03 16:35:32 +00004#include <stdarg.h>
5#ifdef NEED_CPU_H
6#include "disas.h"
7#endif
8
9/* Private global variables, don't use */
10extern FILE *qemu_logfile;
11extern int qemu_loglevel;
blueswir179383c92008-08-30 09:51:20 +000012
aliguori6d2c5142009-01-15 21:52:11 +000013/*
14 * The new API:
15 *
16 */
17
18/* Log settings checking macros: */
19
20/* Returns true if qemu_log() will really write somewhere
21 */
Blue Swirleeacee42012-06-03 16:35:32 +000022static inline bool qemu_log_enabled(void)
23{
24 return qemu_logfile != NULL;
25}
aliguori6d2c5142009-01-15 21:52:11 +000026
Blue Swirl5726c272012-06-03 15:03:23 +000027#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)
Blue Swirldafdf1a2012-06-03 17:04:28 +000037#define LOG_UNIMP (1 << 10)
Peter Maydelle54eba12012-10-18 14:11:35 +010038#define LOG_GUEST_ERROR (1 << 11)
Blue Swirl5726c272012-06-03 15:03:23 +000039
aliguori6d2c5142009-01-15 21:52:11 +000040/* Returns true if a bit is set in the current loglevel mask
41 */
Blue Swirleeacee42012-06-03 16:35:32 +000042static inline bool qemu_loglevel_mask(int mask)
43{
44 return (qemu_loglevel & mask) != 0;
45}
aliguori6d2c5142009-01-15 21:52:11 +000046
aliguori6d2c5142009-01-15 21:52:11 +000047/* Logging functions: */
48
49/* main logging function
50 */
Blue Swirleeacee42012-06-03 16:35:32 +000051void GCC_FMT_ATTR(1, 2) qemu_log(const char *fmt, ...);
aliguori6d2c5142009-01-15 21:52:11 +000052
53/* vfprintf-like logging function
54 */
Stefan Weil726f8cb2012-06-23 20:41:10 +020055static inline void GCC_FMT_ATTR(1, 0)
56qemu_log_vprintf(const char *fmt, va_list va)
Blue Swirleeacee42012-06-03 16:35:32 +000057{
58 if (qemu_logfile) {
59 vfprintf(qemu_logfile, fmt, va);
60 }
61}
aliguori6d2c5142009-01-15 21:52:11 +000062
63/* log only if a bit is set on the current loglevel mask
64 */
Blue Swirleeacee42012-06-03 16:35:32 +000065void GCC_FMT_ATTR(2, 3) qemu_log_mask(int mask, const char *fmt, ...);
aliguori6d2c5142009-01-15 21:52:11 +000066
67
aliguori6d2c5142009-01-15 21:52:11 +000068/* Special cases: */
69
Andreas Färber3b823212012-06-09 03:54:30 +020070#ifdef NEED_CPU_H
aliguori6d2c5142009-01-15 21:52:11 +000071/* cpu_dump_state() logging functions: */
Blue Swirleeacee42012-06-03 16:35:32 +000072static inline void log_cpu_state(CPUArchState *env1, int flags)
73{
Fabien Chouteauc8f803e2012-05-14 23:39:09 +000074 if (qemu_log_enabled()) {
75 cpu_dump_state(env1, qemu_logfile, fprintf, flags);
76 }
Blue Swirleeacee42012-06-03 16:35:32 +000077}
aliguori6d2c5142009-01-15 21:52:11 +000078
Blue Swirleeacee42012-06-03 16:35:32 +000079static 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}
aliguori6d2c5142009-01-15 21:52:11 +000085
Blue Swirleeacee42012-06-03 16:35:32 +000086/* disas() and target_disas() to qemu_logfile: */
Blue Swirlf4359b92012-09-08 12:40:00 +000087static inline void log_target_disas(CPUArchState *env, target_ulong start,
88 target_ulong len, int flags)
Blue Swirleeacee42012-06-03 16:35:32 +000089{
Blue Swirlf4359b92012-09-08 12:40:00 +000090 target_disas(qemu_logfile, env, start, len, flags);
Blue Swirleeacee42012-06-03 16:35:32 +000091}
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)
aliguori6d2c5142009-01-15 21:52:11 +000099/* page_dump() output to the log file: */
Blue Swirleeacee42012-06-03 16:35:32 +0000100static inline void log_page_dump(void)
101{
102 page_dump(qemu_logfile);
103}
104#endif
Andreas Färber3b823212012-06-09 03:54:30 +0200105#endif
aliguori6d2c5142009-01-15 21:52:11 +0000106
107
aliguori6d2c5142009-01-15 21:52:11 +0000108/* Maintenance: */
109
110/* fflush() the log file */
Blue Swirleeacee42012-06-03 16:35:32 +0000111static inline void qemu_log_flush(void)
112{
113 fflush(qemu_logfile);
114}
aliguori6d2c5142009-01-15 21:52:11 +0000115
116/* Close the log file */
Blue Swirleeacee42012-06-03 16:35:32 +0000117static inline void qemu_log_close(void)
118{
119 fclose(qemu_logfile);
120 qemu_logfile = NULL;
121}
aliguori6d2c5142009-01-15 21:52:11 +0000122
123/* Set up a new log file */
Blue Swirleeacee42012-06-03 16:35:32 +0000124static inline void qemu_log_set_file(FILE *f)
125{
126 qemu_logfile = f;
127}
aliguori6d2c5142009-01-15 21:52:11 +0000128
129/* Set up a new log file, only if none is set */
Blue Swirleeacee42012-06-03 16:35:32 +0000130static inline void qemu_log_try_set_file(FILE *f)
131{
132 if (!qemu_logfile) {
133 qemu_logfile = f;
134 }
135}
aliguori6d2c5142009-01-15 21:52:11 +0000136
Blue Swirl5726c272012-06-03 15:03:23 +0000137/* define log items */
138typedef struct CPULogItem {
139 int mask;
140 const char *name;
141 const char *help;
142} CPULogItem;
143
144extern const CPULogItem cpu_log_items[];
145
Blue Swirl3437e542012-07-07 14:40:18 +0000146void qemu_set_log(int log_flags, bool use_own_buffers);
147
148static inline void cpu_set_log(int log_flags)
149{
150#ifdef CONFIG_USER_ONLY
151 qemu_set_log(log_flags, true);
152#else
153 qemu_set_log(log_flags, false);
154#endif
155}
156
Blue Swirl5726c272012-06-03 15:03:23 +0000157void cpu_set_log_filename(const char *filename);
158int cpu_str_to_log_mask(const char *str);
aliguori6d2c5142009-01-15 21:52:11 +0000159
blueswir179383c92008-08-30 09:51:20 +0000160#endif