78b548583e
Inside qemu_log, we perform qemu_log_trylock/unlock, which need not be done if we have already performed the lock beforehand. Always check the result of qemu_log_trylock -- only checking qemu_loglevel_mask races with the acquisition of the lock on the logfile. Reviewed-by: Alex Bennée <alex.bennee@linaro.org> Signed-off-by: Richard Henderson <richard.henderson@linaro.org> Message-Id: <20220417183019.755276-10-richard.henderson@linaro.org>
85 lines
1.9 KiB
C
85 lines
1.9 KiB
C
#ifndef QEMU_EXEC_LOG_H
|
|
#define QEMU_EXEC_LOG_H
|
|
|
|
#include "qemu/log.h"
|
|
#include "hw/core/cpu.h"
|
|
#include "disas/disas.h"
|
|
|
|
/* cpu_dump_state() logging functions: */
|
|
/**
|
|
* 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)
|
|
{
|
|
QemuLogFile *logfile;
|
|
|
|
if (qemu_log_enabled()) {
|
|
rcu_read_lock();
|
|
logfile = qatomic_rcu_read(&qemu_logfile);
|
|
if (logfile) {
|
|
cpu_dump_state(cpu, logfile->fd, flags);
|
|
}
|
|
rcu_read_unlock();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 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)
|
|
{
|
|
if (qemu_loglevel & mask) {
|
|
log_cpu_state(cpu, flags);
|
|
}
|
|
}
|
|
|
|
#ifdef NEED_CPU_H
|
|
/* disas() and target_disas() to qemu_logfile: */
|
|
static inline void log_target_disas(CPUState *cpu, target_ulong start,
|
|
target_ulong len)
|
|
{
|
|
QemuLogFile *logfile;
|
|
rcu_read_lock();
|
|
logfile = qatomic_rcu_read(&qemu_logfile);
|
|
if (logfile) {
|
|
target_disas(logfile->fd, cpu, start, len);
|
|
}
|
|
rcu_read_unlock();
|
|
}
|
|
|
|
static inline void log_disas(const void *code, unsigned long size)
|
|
{
|
|
QemuLogFile *logfile;
|
|
rcu_read_lock();
|
|
logfile = qatomic_rcu_read(&qemu_logfile);
|
|
if (logfile) {
|
|
disas(logfile->fd, code, size);
|
|
}
|
|
rcu_read_unlock();
|
|
}
|
|
|
|
#if defined(CONFIG_USER_ONLY)
|
|
/* page_dump() output to the log file: */
|
|
static inline void log_page_dump(const char *operation)
|
|
{
|
|
FILE *logfile = qemu_log_trylock();
|
|
if (logfile) {
|
|
fprintf(logfile, "page layout changed following %s\n", operation);
|
|
page_dump(logfile);
|
|
}
|
|
qemu_log_unlock(logfile);
|
|
}
|
|
#endif
|
|
#endif
|
|
|
|
#endif
|