2008-08-30 11:51:20 +02:00
|
|
|
#ifndef QEMU_LOG_H
|
|
|
|
#define QEMU_LOG_H
|
|
|
|
|
2012-06-03 18:35:32 +02:00
|
|
|
#include <stdarg.h>
|
2013-06-07 15:00:32 +02:00
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "qemu/compiler.h"
|
2013-06-16 07:28:50 +02:00
|
|
|
#include "qom/cpu.h"
|
2012-06-03 18:35:32 +02:00
|
|
|
#ifdef NEED_CPU_H
|
2012-10-24 11:12:21 +02:00
|
|
|
#include "disas/disas.h"
|
2012-06-03 18:35:32 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Private global variables, don't use */
|
|
|
|
extern FILE *qemu_logfile;
|
|
|
|
extern int qemu_loglevel;
|
2008-08-30 11:51:20 +02:00
|
|
|
|
2009-01-15 22:52:11 +01:00
|
|
|
/*
|
|
|
|
* The new API:
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Log settings checking macros: */
|
|
|
|
|
|
|
|
/* Returns true if qemu_log() will really write somewhere
|
|
|
|
*/
|
2012-06-03 18:35:32 +02:00
|
|
|
static inline bool qemu_log_enabled(void)
|
|
|
|
{
|
|
|
|
return qemu_logfile != NULL;
|
|
|
|
}
|
2009-01-15 22:52:11 +01:00
|
|
|
|
2015-11-13 13:16:27 +01:00
|
|
|
/* Returns true if qemu_log() will write somewhere else than stderr
|
|
|
|
*/
|
|
|
|
static inline bool qemu_log_separate(void)
|
|
|
|
{
|
|
|
|
return qemu_logfile != NULL && qemu_logfile != stderr;
|
|
|
|
}
|
|
|
|
|
2012-06-03 17:03:23 +02:00
|
|
|
#define CPU_LOG_TB_OUT_ASM (1 << 0)
|
|
|
|
#define CPU_LOG_TB_IN_ASM (1 << 1)
|
|
|
|
#define CPU_LOG_TB_OP (1 << 2)
|
|
|
|
#define CPU_LOG_TB_OP_OPT (1 << 3)
|
|
|
|
#define CPU_LOG_INT (1 << 4)
|
|
|
|
#define CPU_LOG_EXEC (1 << 5)
|
|
|
|
#define CPU_LOG_PCALL (1 << 6)
|
|
|
|
#define CPU_LOG_TB_CPU (1 << 8)
|
|
|
|
#define CPU_LOG_RESET (1 << 9)
|
2012-06-03 19:04:28 +02:00
|
|
|
#define LOG_UNIMP (1 << 10)
|
2012-10-18 15:11:35 +02:00
|
|
|
#define LOG_GUEST_ERROR (1 << 11)
|
2014-12-13 17:48:18 +01:00
|
|
|
#define CPU_LOG_MMU (1 << 12)
|
2015-09-17 00:33:53 +02:00
|
|
|
#define CPU_LOG_TB_NOCHAIN (1 << 13)
|
2015-11-13 12:32:19 +01:00
|
|
|
#define CPU_LOG_PAGE (1 << 14)
|
2012-06-03 17:03:23 +02:00
|
|
|
|
2009-01-15 22:52:11 +01:00
|
|
|
/* Returns true if a bit is set in the current loglevel mask
|
|
|
|
*/
|
2012-06-03 18:35:32 +02:00
|
|
|
static inline bool qemu_loglevel_mask(int mask)
|
|
|
|
{
|
|
|
|
return (qemu_loglevel & mask) != 0;
|
|
|
|
}
|
2009-01-15 22:52:11 +01:00
|
|
|
|
|
|
|
/* Logging functions: */
|
|
|
|
|
|
|
|
/* main logging function
|
|
|
|
*/
|
2012-06-03 18:35:32 +02:00
|
|
|
void GCC_FMT_ATTR(1, 2) qemu_log(const char *fmt, ...);
|
2009-01-15 22:52:11 +01:00
|
|
|
|
|
|
|
/* vfprintf-like logging function
|
|
|
|
*/
|
2012-06-23 20:41:10 +02:00
|
|
|
static inline void GCC_FMT_ATTR(1, 0)
|
|
|
|
qemu_log_vprintf(const char *fmt, va_list va)
|
2012-06-03 18:35:32 +02:00
|
|
|
{
|
|
|
|
if (qemu_logfile) {
|
|
|
|
vfprintf(qemu_logfile, fmt, va);
|
|
|
|
}
|
|
|
|
}
|
2009-01-15 22:52:11 +01:00
|
|
|
|
|
|
|
/* log only if a bit is set on the current loglevel mask
|
|
|
|
*/
|
2012-06-03 18:35:32 +02:00
|
|
|
void GCC_FMT_ATTR(2, 3) qemu_log_mask(int mask, const char *fmt, ...);
|
2009-01-15 22:52:11 +01:00
|
|
|
|
|
|
|
|
|
|
|
/* Special cases: */
|
|
|
|
|
|
|
|
/* cpu_dump_state() logging functions: */
|
2013-06-16 07:28:50 +02:00
|
|
|
/**
|
|
|
|
* log_cpu_state:
|
|
|
|
* @cpu: The CPU whose state is to be logged.
|
|
|
|
* @flags: Flags what to log.
|
|
|
|
*
|
|
|
|
* Logs the output of cpu_dump_state().
|
|
|
|
*/
|
|
|
|
static inline void log_cpu_state(CPUState *cpu, int flags)
|
2012-06-03 18:35:32 +02:00
|
|
|
{
|
2012-05-15 01:39:09 +02:00
|
|
|
if (qemu_log_enabled()) {
|
2013-06-16 07:28:50 +02:00
|
|
|
cpu_dump_state(cpu, qemu_logfile, fprintf, flags);
|
2012-05-15 01:39:09 +02:00
|
|
|
}
|
2012-06-03 18:35:32 +02:00
|
|
|
}
|
|
|
|
|
2013-06-16 07:28:50 +02:00
|
|
|
/**
|
|
|
|
* log_cpu_state_mask:
|
|
|
|
* @mask: Mask when to log.
|
|
|
|
* @cpu: The CPU whose state is to be logged.
|
|
|
|
* @flags: Flags what to log.
|
|
|
|
*
|
|
|
|
* Logs the output of cpu_dump_state() if loglevel includes @mask.
|
|
|
|
*/
|
|
|
|
static inline void log_cpu_state_mask(int mask, CPUState *cpu, int flags)
|
2012-06-03 18:35:32 +02:00
|
|
|
{
|
|
|
|
if (qemu_loglevel & mask) {
|
2013-06-16 07:28:50 +02:00
|
|
|
log_cpu_state(cpu, flags);
|
2012-06-03 18:35:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-16 07:28:50 +02:00
|
|
|
#ifdef NEED_CPU_H
|
2012-06-03 18:35:32 +02:00
|
|
|
/* disas() and target_disas() to qemu_logfile: */
|
2015-05-24 23:20:41 +02:00
|
|
|
static inline void log_target_disas(CPUState *cpu, target_ulong start,
|
2012-09-08 14:40:00 +02:00
|
|
|
target_ulong len, int flags)
|
2012-06-03 18:35:32 +02:00
|
|
|
{
|
2015-05-24 23:20:41 +02:00
|
|
|
target_disas(qemu_logfile, cpu, start, len, flags);
|
2012-06-03 18:35:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void log_disas(void *code, unsigned long size)
|
|
|
|
{
|
|
|
|
disas(qemu_logfile, code, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(CONFIG_USER_ONLY)
|
2009-01-15 22:52:11 +01:00
|
|
|
/* page_dump() output to the log file: */
|
2012-06-03 18:35:32 +02:00
|
|
|
static inline void log_page_dump(void)
|
|
|
|
{
|
|
|
|
page_dump(qemu_logfile);
|
|
|
|
}
|
|
|
|
#endif
|
2012-06-09 03:54:30 +02:00
|
|
|
#endif
|
2009-01-15 22:52:11 +01:00
|
|
|
|
|
|
|
|
|
|
|
/* Maintenance: */
|
|
|
|
|
|
|
|
/* fflush() the log file */
|
2012-06-03 18:35:32 +02:00
|
|
|
static inline void qemu_log_flush(void)
|
|
|
|
{
|
|
|
|
fflush(qemu_logfile);
|
|
|
|
}
|
2009-01-15 22:52:11 +01:00
|
|
|
|
|
|
|
/* Close the log file */
|
2012-06-03 18:35:32 +02:00
|
|
|
static inline void qemu_log_close(void)
|
|
|
|
{
|
2013-02-26 18:52:40 +01:00
|
|
|
if (qemu_logfile) {
|
|
|
|
if (qemu_logfile != stderr) {
|
|
|
|
fclose(qemu_logfile);
|
|
|
|
}
|
|
|
|
qemu_logfile = NULL;
|
|
|
|
}
|
2012-06-03 18:35:32 +02:00
|
|
|
}
|
2009-01-15 22:52:11 +01:00
|
|
|
|
|
|
|
/* Set up a new log file */
|
2012-06-03 18:35:32 +02:00
|
|
|
static inline void qemu_log_set_file(FILE *f)
|
|
|
|
{
|
|
|
|
qemu_logfile = f;
|
|
|
|
}
|
2009-01-15 22:52:11 +01:00
|
|
|
|
2012-06-03 17:03:23 +02:00
|
|
|
/* define log items */
|
2013-02-11 17:41:25 +01:00
|
|
|
typedef struct QEMULogItem {
|
2012-06-03 17:03:23 +02:00
|
|
|
int mask;
|
|
|
|
const char *name;
|
|
|
|
const char *help;
|
2013-02-11 17:41:25 +01:00
|
|
|
} QEMULogItem;
|
2012-06-03 17:03:23 +02:00
|
|
|
|
2013-02-11 17:41:25 +01:00
|
|
|
extern const QEMULogItem qemu_log_items[];
|
2012-06-03 17:03:23 +02:00
|
|
|
|
2013-02-11 17:41:23 +01:00
|
|
|
/* This is the function that actually does the work of
|
|
|
|
* changing the log level; it should only be accessed via
|
|
|
|
* the qemu_set_log() wrapper.
|
|
|
|
*/
|
|
|
|
void do_qemu_set_log(int log_flags, bool use_own_buffers);
|
2012-07-07 16:40:18 +02:00
|
|
|
|
2013-02-11 17:41:23 +01:00
|
|
|
static inline void qemu_set_log(int log_flags)
|
2012-07-07 16:40:18 +02:00
|
|
|
{
|
|
|
|
#ifdef CONFIG_USER_ONLY
|
2013-02-11 17:41:23 +01:00
|
|
|
do_qemu_set_log(log_flags, true);
|
2012-07-07 16:40:18 +02:00
|
|
|
#else
|
2013-02-11 17:41:23 +01:00
|
|
|
do_qemu_set_log(log_flags, false);
|
2012-07-07 16:40:18 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2013-02-11 17:41:20 +01:00
|
|
|
void qemu_set_log_filename(const char *filename);
|
2013-02-11 17:41:22 +01:00
|
|
|
int qemu_str_to_log_mask(const char *str);
|
2009-01-15 22:52:11 +01:00
|
|
|
|
2013-02-11 17:41:21 +01:00
|
|
|
/* Print a usage message listing all the valid logging categories
|
|
|
|
* to the specified FILE*.
|
|
|
|
*/
|
|
|
|
void qemu_print_log_usage(FILE *f);
|
|
|
|
|
2008-08-30 11:51:20 +02:00
|
|
|
#endif
|