[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 01/11] qemu-log: introduce qemu_log_separate
From: |
Paolo Bonzini |
Subject: |
[Qemu-devel] [PATCH 01/11] qemu-log: introduce qemu_log_separate |
Date: |
Sat, 12 Dec 2015 11:36:17 +0100 |
In some cases, the same message is printed both on stderr and in the log.
Avoid duplicate output in the default case where stderr _is_ the log,
and standardize this to stderr+log where it used to use stdio+log.
Signed-off-by: Paolo Bonzini <address@hidden>
---
exec.c | 2 +-
include/qemu/log.h | 7 +++++++
linux-user/main.c | 4 ++--
target-cris/translate.c | 6 ++++--
target-ppc/excp_helper.c | 7 +++----
target-ppc/translate.c | 40 ++++++++++++++++++++++++----------------
target-s390x/helper.c | 2 +-
target-s390x/mmu_helper.c | 2 +-
8 files changed, 43 insertions(+), 27 deletions(-)
diff --git a/exec.c b/exec.c
index 53a4b8c..dd11ef9 100644
--- a/exec.c
+++ b/exec.c
@@ -870,7 +870,7 @@ void cpu_abort(CPUState *cpu, const char *fmt, ...)
vfprintf(stderr, fmt, ap);
fprintf(stderr, "\n");
cpu_dump_state(cpu, stderr, fprintf, CPU_DUMP_FPU | CPU_DUMP_CCOP);
- if (qemu_log_enabled()) {
+ if (qemu_log_separate()) {
qemu_log("qemu: fatal: ");
qemu_log_vprintf(fmt, ap2);
qemu_log("\n");
diff --git a/include/qemu/log.h b/include/qemu/log.h
index 362cbc4..964ab9d 100644
--- a/include/qemu/log.h
+++ b/include/qemu/log.h
@@ -28,6 +28,13 @@ static inline bool qemu_log_enabled(void)
return qemu_logfile != NULL;
}
+/* 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;
+}
+
#define CPU_LOG_TB_OUT_ASM (1 << 0)
#define CPU_LOG_TB_IN_ASM (1 << 1)
#define CPU_LOG_TB_OP (1 << 2)
diff --git a/linux-user/main.c b/linux-user/main.c
index 8acfe0f..a04e91e 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -1472,8 +1472,8 @@ do {
\
CPUState *cs = ENV_GET_CPU(env); \
fprintf(stderr, fmt , ## __VA_ARGS__); \
cpu_dump_state(cs, stderr, fprintf, 0); \
- qemu_log(fmt, ## __VA_ARGS__); \
- if (qemu_log_enabled()) { \
+ if (qemu_log_separate()) { \
+ qemu_log(fmt, ## __VA_ARGS__); \
log_cpu_state(cs, 0); \
} \
} while (0)
diff --git a/target-cris/translate.c b/target-cris/translate.c
index 2d710cc..354c86d 100644
--- a/target-cris/translate.c
+++ b/target-cris/translate.c
@@ -130,8 +130,10 @@ typedef struct DisasContext {
static void gen_BUG(DisasContext *dc, const char *file, int line)
{
- printf("BUG: pc=%x %s %d\n", dc->pc, file, line);
- qemu_log("BUG: pc=%x %s %d\n", dc->pc, file, line);
+ fprintf(stderr, "BUG: pc=%x %s %d\n", dc->pc, file, line);
+ if (qemu_log_separate()) {
+ qemu_log("BUG: pc=%x %s %d\n", dc->pc, file, line);
+ }
cpu_abort(CPU(dc->cpu), "%s:%d\n", file, line);
}
diff --git a/target-ppc/excp_helper.c b/target-ppc/excp_helper.c
index 4250106..102d789 100644
--- a/target-ppc/excp_helper.c
+++ b/target-ppc/excp_helper.c
@@ -131,12 +131,11 @@ static inline void powerpc_excp(PowerPCCPU *cpu, int
excp_model, int excp)
/* Machine check exception is not enabled.
* Enter checkstop state.
*/
- if (qemu_log_enabled()) {
+ fprintf(stderr, "Machine check while not allowed. "
+ "Entering checkstop state\n");
+ if (qemu_log_separate()) {
qemu_log("Machine check while not allowed. "
"Entering checkstop state\n");
- } else {
- fprintf(stderr, "Machine check while not allowed. "
- "Entering checkstop state\n");
}
cs->halted = 1;
cs->interrupt_request |= CPU_INTERRUPT_EXITTB;
diff --git a/target-ppc/translate.c b/target-ppc/translate.c
index 41a7258..cdf46dd 100644
--- a/target-ppc/translate.c
+++ b/target-ppc/translate.c
@@ -4285,19 +4285,23 @@ static inline void gen_op_mfspr(DisasContext *ctx)
* allowing userland application to read the PVR
*/
if (sprn != SPR_PVR) {
- qemu_log("Trying to read privileged spr %d (0x%03x) at "
- TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
- printf("Trying to read privileged spr %d (0x%03x) at "
- TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
+ fprintf(stderr, "Trying to read privileged spr %d (0x%03x) at "
+ TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
+ if (qemu_log_separate()) {
+ qemu_log("Trying to read privileged spr %d (0x%03x) at "
+ TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
+ }
}
gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
}
} else {
/* Not defined */
- qemu_log("Trying to read invalid spr %d (0x%03x) at "
- TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
- printf("Trying to read invalid spr %d (0x%03x) at "
- TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
+ fprintf(stderr, "Trying to read invalid spr %d (0x%03x) at "
+ TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
+ if (qemu_log_separate()) {
+ qemu_log("Trying to read invalid spr %d (0x%03x) at "
+ TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
+ }
gen_inval_exception(ctx, POWERPC_EXCP_INVAL_SPR);
}
}
@@ -4431,18 +4435,22 @@ static void gen_mtspr(DisasContext *ctx)
(*write_cb)(ctx, sprn, rS(ctx->opcode));
} else {
/* Privilege exception */
- qemu_log("Trying to write privileged spr %d (0x%03x) at "
- TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
- printf("Trying to write privileged spr %d (0x%03x) at "
- TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
+ fprintf(stderr, "Trying to write privileged spr %d (0x%03x) at "
+ TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
+ if (qemu_log_separate()) {
+ qemu_log("Trying to write privileged spr %d (0x%03x) at "
+ TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
+ }
gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
}
} else {
/* Not defined */
- qemu_log("Trying to write invalid spr %d (0x%03x) at "
- TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
- printf("Trying to write invalid spr %d (0x%03x) at "
- TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
+ if (qemu_log_separate()) {
+ qemu_log("Trying to write invalid spr %d (0x%03x) at "
+ TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
+ }
+ fprintf(stderr, "Trying to write invalid spr %d (0x%03x) at "
+ TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
gen_inval_exception(ctx, POWERPC_EXCP_INVAL_SPR);
}
}
diff --git a/target-s390x/helper.c b/target-s390x/helper.c
index d887006..aa58f39 100644
--- a/target-s390x/helper.c
+++ b/target-s390x/helper.c
@@ -33,7 +33,7 @@
#ifdef DEBUG_S390_STDOUT
#define DPRINTF(fmt, ...) \
do { fprintf(stderr, fmt, ## __VA_ARGS__); \
- qemu_log(fmt, ##__VA_ARGS__); } while (0)
+ if (qemu_log_separate()) qemu_log(fmt, ##__VA_ARGS__); } while (0)
#else
#define DPRINTF(fmt, ...) \
do { qemu_log(fmt, ## __VA_ARGS__); } while (0)
diff --git a/target-s390x/mmu_helper.c b/target-s390x/mmu_helper.c
index 058a370..f4e1872 100644
--- a/target-s390x/mmu_helper.c
+++ b/target-s390x/mmu_helper.c
@@ -30,7 +30,7 @@
#ifdef DEBUG_S390_STDOUT
#define DPRINTF(fmt, ...) \
do { fprintf(stderr, fmt, ## __VA_ARGS__); \
- qemu_log(fmt, ##__VA_ARGS__); } while (0)
+ if (qemu_log_separate()) qemu_log(fmt, ##__VA_ARGS__); } while (0)
#else
#define DPRINTF(fmt, ...) \
do { qemu_log(fmt, ## __VA_ARGS__); } while (0)
--
2.5.0
- [Qemu-devel] [PATCH 00/11] Avoid always-active qemu_log calls, Paolo Bonzini, 2015/12/12
- [Qemu-devel] [PATCH 02/11] alpha: convert "naked" qemu_log to tracepoint, Paolo Bonzini, 2015/12/12
- [Qemu-devel] [PATCH 01/11] qemu-log: introduce qemu_log_separate,
Paolo Bonzini <=
- [Qemu-devel] [PATCH 03/11] cris: avoid "naked" qemu_log, Paolo Bonzini, 2015/12/12
- [Qemu-devel] [PATCH 05/11] s390x: avoid "naked" qemu_log, Paolo Bonzini, 2015/12/12
- [Qemu-devel] [PATCH 04/11] microblaze: avoid "naked" qemu_log, Paolo Bonzini, 2015/12/12
- [Qemu-devel] [PATCH 06/11] ppc: cleanup logging, Paolo Bonzini, 2015/12/12
- [Qemu-devel] [PATCH 07/11] tricore: avoid "naked" qemu_log, Paolo Bonzini, 2015/12/12