2008-08-30 11:51:20 +02:00
|
|
|
#ifndef QEMU_LOG_H
|
|
|
|
#define QEMU_LOG_H
|
|
|
|
|
2018-02-13 15:00:29 +01:00
|
|
|
/* A small part of this API is split into its own header */
|
|
|
|
#include "qemu/log-for-trace.h"
|
2019-11-18 22:15:27 +01:00
|
|
|
#include "qemu/rcu.h"
|
|
|
|
|
|
|
|
typedef struct QemuLogFile {
|
|
|
|
struct rcu_head rcu;
|
|
|
|
FILE *fd;
|
|
|
|
} QemuLogFile;
|
2012-06-03 18:35:32 +02:00
|
|
|
|
2018-02-13 15:00:29 +01:00
|
|
|
/* Private global variable, don't use */
|
2019-11-18 22:15:27 +01:00
|
|
|
extern QemuLogFile *qemu_logfile;
|
|
|
|
|
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)
|
|
|
|
{
|
2019-11-18 22:15:27 +01:00
|
|
|
QemuLogFile *logfile;
|
|
|
|
bool res = false;
|
|
|
|
|
|
|
|
rcu_read_lock();
|
2020-09-23 12:56:46 +02:00
|
|
|
logfile = qatomic_rcu_read(&qemu_logfile);
|
2019-11-18 22:15:27 +01:00
|
|
|
if (logfile && logfile->fd != stderr) {
|
|
|
|
res = true;
|
|
|
|
}
|
|
|
|
rcu_read_unlock();
|
|
|
|
return res;
|
2015-11-13 13:16:27 +01:00
|
|
|
}
|
|
|
|
|
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)
|
2018-02-13 15:00:29 +01:00
|
|
|
/* LOG_TRACE (1 << 15) is defined in log-for-trace.h */
|
2016-06-24 05:34:33 +02:00
|
|
|
#define CPU_LOG_TB_OP_IND (1 << 16)
|
2018-05-15 15:58:44 +02:00
|
|
|
#define CPU_LOG_TB_FPU (1 << 17)
|
2019-10-11 17:34:05 +02:00
|
|
|
#define CPU_LOG_PLUGIN (1 << 18)
|
2020-02-04 03:54:14 +01:00
|
|
|
/* LOG_STRACE is used for user-mode strace logging. */
|
|
|
|
#define LOG_STRACE (1 << 19)
|
2012-06-03 17:03:23 +02:00
|
|
|
|
2016-09-23 00:17:10 +02:00
|
|
|
/* Lock output for a series of related logs. Since this is not needed
|
|
|
|
* for a single qemu_log / qemu_log_mask / qemu_log_mask_and_addr, we
|
|
|
|
* assume that qemu_loglevel_mask has already been tested, and that
|
|
|
|
* qemu_loglevel is never set when qemu_logfile is unset.
|
|
|
|
*/
|
|
|
|
|
2019-11-18 22:15:26 +01:00
|
|
|
static inline FILE *qemu_log_lock(void)
|
2016-09-23 00:17:10 +02:00
|
|
|
{
|
2019-11-18 22:15:27 +01:00
|
|
|
QemuLogFile *logfile;
|
|
|
|
rcu_read_lock();
|
2020-09-23 12:56:46 +02:00
|
|
|
logfile = qatomic_rcu_read(&qemu_logfile);
|
2019-11-18 22:15:27 +01:00
|
|
|
if (logfile) {
|
|
|
|
qemu_flockfile(logfile->fd);
|
|
|
|
return logfile->fd;
|
|
|
|
} else {
|
|
|
|
return NULL;
|
|
|
|
}
|
2016-09-23 00:17:10 +02:00
|
|
|
}
|
|
|
|
|
2019-11-18 22:15:26 +01:00
|
|
|
static inline void qemu_log_unlock(FILE *fd)
|
2016-09-23 00:17:10 +02:00
|
|
|
{
|
2019-11-18 22:15:26 +01:00
|
|
|
if (fd) {
|
|
|
|
qemu_funlockfile(fd);
|
|
|
|
}
|
2019-11-18 22:15:27 +01:00
|
|
|
rcu_read_unlock();
|
2016-09-23 00:17:10 +02:00
|
|
|
}
|
|
|
|
|
2009-01-15 22:52:11 +01:00
|
|
|
/* Logging functions: */
|
|
|
|
|
|
|
|
/* 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
|
|
|
{
|
2019-11-18 22:15:27 +01:00
|
|
|
QemuLogFile *logfile;
|
|
|
|
|
|
|
|
rcu_read_lock();
|
2020-09-23 12:56:46 +02:00
|
|
|
logfile = qatomic_rcu_read(&qemu_logfile);
|
2019-11-18 22:15:27 +01:00
|
|
|
if (logfile) {
|
|
|
|
vfprintf(logfile->fd, fmt, va);
|
2012-06-03 18:35:32 +02:00
|
|
|
}
|
2019-11-18 22:15:27 +01:00
|
|
|
rcu_read_unlock();
|
2012-06-03 18:35:32 +02:00
|
|
|
}
|
2009-01-15 22:52:11 +01:00
|
|
|
|
2016-03-15 19:12:03 +01:00
|
|
|
/* log only if a bit is set on the current loglevel mask:
|
|
|
|
* @mask: bit to check in the mask
|
|
|
|
* @fmt: printf-style format string
|
|
|
|
* @args: optional arguments for format string
|
2009-01-15 22:52:11 +01:00
|
|
|
*/
|
2016-03-15 19:12:03 +01:00
|
|
|
#define qemu_log_mask(MASK, FMT, ...) \
|
|
|
|
do { \
|
|
|
|
if (unlikely(qemu_loglevel_mask(MASK))) { \
|
|
|
|
qemu_log(FMT, ## __VA_ARGS__); \
|
|
|
|
} \
|
|
|
|
} while (0)
|
2009-01-15 22:52:11 +01:00
|
|
|
|
2016-03-15 15:30:21 +01:00
|
|
|
/* log only if a bit is set on the current loglevel mask
|
|
|
|
* and we are in the address range we care about:
|
|
|
|
* @mask: bit to check in the mask
|
|
|
|
* @addr: address to check in dfilter
|
|
|
|
* @fmt: printf-style format string
|
|
|
|
* @args: optional arguments for format string
|
|
|
|
*/
|
|
|
|
#define qemu_log_mask_and_addr(MASK, ADDR, FMT, ...) \
|
|
|
|
do { \
|
|
|
|
if (unlikely(qemu_loglevel_mask(MASK)) && \
|
|
|
|
qemu_log_in_addr_range(ADDR)) { \
|
|
|
|
qemu_log(FMT, ## __VA_ARGS__); \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
2009-01-15 22:52:11 +01:00
|
|
|
/* Maintenance: */
|
|
|
|
|
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
|
|
|
|
2015-12-04 13:12:57 +01:00
|
|
|
void qemu_set_log(int log_flags);
|
|
|
|
void qemu_log_needs_buffers(void);
|
2016-06-15 19:27:16 +02:00
|
|
|
void qemu_set_log_filename(const char *filename, Error **errp);
|
2016-06-15 19:27:15 +02:00
|
|
|
void qemu_set_dfilter_ranges(const char *ranges, Error **errp);
|
2016-03-15 15:30:20 +01:00
|
|
|
bool qemu_log_in_addr_range(uint64_t addr);
|
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);
|
|
|
|
|
2016-03-16 12:36:52 +01:00
|
|
|
/* fflush() the log file */
|
|
|
|
void qemu_log_flush(void);
|
|
|
|
/* Close the log file */
|
|
|
|
void qemu_log_close(void);
|
|
|
|
|
2008-08-30 11:51:20 +02:00
|
|
|
#endif
|