Skip to content

Commit

Permalink
log: Change log_cpu_state[_mask]() argument to CPUState
Browse files Browse the repository at this point in the history
Since commit 878096e (cpu: Turn
cpu_dump_{state,statistics}() into CPUState hooks) CPUArchState is no
longer needed.

Add documentation and make the functions available through qemu/log.h
outside NEED_CPU_H to allow use in qom/cpu.c. Moving them to qom/cpu.h
was not yet possible due to convoluted include paths, so that some
devices grow an implicit and unneeded dependency on qom/cpu.h for now.

Acked-by: Michael Walle <michael@walle.cc> (for lm32)
Reviewed-by: Richard Henderson <rth@twiddle.net>
[AF: Simplified mb_cpu_do_interrupt() and do_interrupt_all() changes]
Signed-off-by: Andreas Färber <afaerber@suse.de>
  • Loading branch information
afaerber committed Jul 9, 2013
1 parent 518e9d7 commit a076285
Show file tree
Hide file tree
Showing 30 changed files with 63 additions and 45 deletions.
6 changes: 3 additions & 3 deletions cpu-exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -577,15 +577,15 @@ int cpu_exec(CPUArchState *env)
if (qemu_loglevel_mask(CPU_LOG_TB_CPU)) {
/* restore flags in standard format */
#if defined(TARGET_I386)
log_cpu_state(env, CPU_DUMP_CCOP);
log_cpu_state(cpu, CPU_DUMP_CCOP);
#elif defined(TARGET_M68K)
cpu_m68k_flush_flags(env, env->cc_op);
env->cc_op = CC_OP_FLAGS;
env->sr = (env->sr & 0xffe0)
| env->cc_dest | (env->cc_x << 4);
log_cpu_state(env, 0);
log_cpu_state(cpu, 0);
#else
log_cpu_state(env, 0);
log_cpu_state(cpu, 0);
#endif
}
#endif /* DEBUG_DISAS */
Expand Down
2 changes: 1 addition & 1 deletion exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ void cpu_abort(CPUArchState *env, const char *fmt, ...)
qemu_log("qemu: fatal: ");
qemu_log_vprintf(fmt, ap2);
qemu_log("\n");
log_cpu_state(env, CPU_DUMP_FPU | CPU_DUMP_CCOP);
log_cpu_state(cpu, CPU_DUMP_FPU | CPU_DUMP_CCOP);
qemu_log_flush();
qemu_log_close();
}
Expand Down
26 changes: 21 additions & 5 deletions include/qemu/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <stdbool.h>
#include <stdio.h>
#include "qemu/compiler.h"
#include "qom/cpu.h"
#ifdef NEED_CPU_H
#include "disas/disas.h"
#endif
Expand Down Expand Up @@ -70,22 +71,37 @@ void GCC_FMT_ATTR(2, 3) qemu_log_mask(int mask, const char *fmt, ...);

/* Special cases: */

#ifdef NEED_CPU_H
/* cpu_dump_state() logging functions: */
static inline void log_cpu_state(CPUArchState *env1, int flags)
/**
* 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)
{
if (qemu_log_enabled()) {
cpu_dump_state(ENV_GET_CPU(env1), qemu_logfile, fprintf, flags);
cpu_dump_state(cpu, qemu_logfile, fprintf, flags);
}
}

static inline void log_cpu_state_mask(int mask, CPUArchState *env1, int flags)
/**
* 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(env1, flags);
log_cpu_state(cpu, flags);
}
}

#ifdef NEED_CPU_H
/* disas() and target_disas() to qemu_logfile: */
static inline void log_target_disas(CPUArchState *env, target_ulong start,
target_ulong len, int flags)
Expand Down
5 changes: 3 additions & 2 deletions linux-user/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1302,11 +1302,12 @@ int ppc_dcr_write (ppc_dcr_t *dcr_env, int dcrn, uint32_t val)

#define EXCP_DUMP(env, fmt, ...) \
do { \
CPUState *cs = ENV_GET_CPU(env); \
fprintf(stderr, fmt , ## __VA_ARGS__); \
cpu_dump_state(ENV_GET_CPU(env), stderr, fprintf, 0); \
cpu_dump_state(cs, stderr, fprintf, 0); \
qemu_log(fmt, ## __VA_ARGS__); \
if (qemu_log_enabled()) { \
log_cpu_state(env, 0); \
log_cpu_state(cs, 0); \
} \
} while (0)

Expand Down
2 changes: 1 addition & 1 deletion target-arm/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ static void arm_cpu_reset(CPUState *s)

if (qemu_loglevel_mask(CPU_LOG_RESET)) {
qemu_log("CPU Reset (CPU %d)\n", s->cpu_index);
log_cpu_state(env, 0);
log_cpu_state(s, 0);
}

acc->parent_reset(s);
Expand Down
2 changes: 1 addition & 1 deletion target-cris/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ static void cris_cpu_reset(CPUState *s)

if (qemu_loglevel_mask(CPU_LOG_RESET)) {
qemu_log("CPU Reset (CPU %d)\n", s->cpu_index);
log_cpu_state(env, 0);
log_cpu_state(s, 0);
}

ccc->parent_reset(s);
Expand Down
2 changes: 1 addition & 1 deletion target-i386/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -2177,7 +2177,7 @@ static void x86_cpu_reset(CPUState *s)

if (qemu_loglevel_mask(CPU_LOG_RESET)) {
qemu_log("CPU Reset (CPU %d)\n", s->cpu_index);
log_cpu_state(env, CPU_DUMP_FPU | CPU_DUMP_CCOP);
log_cpu_state(s, CPU_DUMP_FPU | CPU_DUMP_CCOP);
}

xcc->parent_reset(s);
Expand Down
4 changes: 2 additions & 2 deletions target-i386/seg_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#ifdef DEBUG_PCALL
# define LOG_PCALL(...) qemu_log_mask(CPU_LOG_PCALL, ## __VA_ARGS__)
# define LOG_PCALL_STATE(env) \
log_cpu_state_mask(CPU_LOG_PCALL, (env), CPU_DUMP_CCOP)
log_cpu_state_mask(CPU_LOG_PCALL, CPU(x86_env_get_cpu(env)), CPU_DUMP_CCOP)
#else
# define LOG_PCALL(...) do { } while (0)
# define LOG_PCALL_STATE(env) do { } while (0)
Expand Down Expand Up @@ -1182,7 +1182,7 @@ static void do_interrupt_all(X86CPU *cpu, int intno, int is_int,
qemu_log(" env->regs[R_EAX]=" TARGET_FMT_lx, env->regs[R_EAX]);
}
qemu_log("\n");
log_cpu_state(env, CPU_DUMP_CCOP);
log_cpu_state(CPU(cpu), CPU_DUMP_CCOP);
#if 0
{
int i;
Expand Down
5 changes: 3 additions & 2 deletions target-i386/smm_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void do_smm_enter(X86CPU *cpu)
int i, offset;

qemu_log_mask(CPU_LOG_INT, "SMM: enter\n");
log_cpu_state_mask(CPU_LOG_INT, env, CPU_DUMP_CCOP);
log_cpu_state_mask(CPU_LOG_INT, CPU(cpu), CPU_DUMP_CCOP);

env->hflags |= HF_SMM_MASK;
cpu_smm_update(env);
Expand Down Expand Up @@ -180,6 +180,7 @@ void do_smm_enter(X86CPU *cpu)

void helper_rsm(CPUX86State *env)
{
X86CPU *cpu = x86_env_get_cpu(env);
target_ulong sm_state;
int i, offset;
uint32_t val;
Expand Down Expand Up @@ -296,7 +297,7 @@ void helper_rsm(CPUX86State *env)
cpu_smm_update(env);

qemu_log_mask(CPU_LOG_INT, "SMM: after RSM\n");
log_cpu_state_mask(CPU_LOG_INT, env, CPU_DUMP_CCOP);
log_cpu_state_mask(CPU_LOG_INT, CPU(cpu), CPU_DUMP_CCOP);
}

#endif /* !CONFIG_USER_ONLY */
2 changes: 1 addition & 1 deletion target-lm32/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ static void lm32_cpu_reset(CPUState *s)

if (qemu_loglevel_mask(CPU_LOG_RESET)) {
qemu_log("CPU Reset (CPU %d)\n", s->cpu_index);
log_cpu_state(env, 0);
log_cpu_state(s, 0);
}

lcc->parent_reset(s);
Expand Down
4 changes: 2 additions & 2 deletions target-lm32/helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ void lm32_cpu_do_interrupt(CPUState *cs)
} else {
env->pc = env->eba + (env->exception_index * 32);
}
log_cpu_state_mask(CPU_LOG_INT, env, 0);
log_cpu_state_mask(CPU_LOG_INT, cs, 0);
break;
case EXCP_BREAKPOINT:
case EXCP_WATCHPOINT:
Expand All @@ -79,7 +79,7 @@ void lm32_cpu_do_interrupt(CPUState *cs)
env->ie |= (env->ie & IE_IE) ? IE_BIE : 0;
env->ie &= ~IE_IE;
env->pc = env->deba + (env->exception_index * 32);
log_cpu_state_mask(CPU_LOG_INT, env, 0);
log_cpu_state_mask(CPU_LOG_INT, cs, 0);
break;
default:
cpu_abort(env, "unhandled exception type=%d\n",
Expand Down
2 changes: 1 addition & 1 deletion target-m68k/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ static void m68k_cpu_reset(CPUState *s)

if (qemu_loglevel_mask(CPU_LOG_RESET)) {
qemu_log("CPU Reset (CPU %d)\n", s->cpu_index);
log_cpu_state(env, 0);
log_cpu_state(s, 0);
}

mcc->parent_reset(s);
Expand Down
2 changes: 1 addition & 1 deletion target-microblaze/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ static void mb_cpu_reset(CPUState *s)

if (qemu_loglevel_mask(CPU_LOG_RESET)) {
qemu_log("CPU Reset (CPU %d)\n", s->cpu_index);
log_cpu_state(env, 0);
log_cpu_state(s, 0);
}

mcc->parent_reset(s);
Expand Down
12 changes: 6 additions & 6 deletions target-microblaze/helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ void mb_cpu_do_interrupt(CPUState *cs)
"hw exception at pc=%x ear=%x esr=%x iflags=%x\n",
env->sregs[SR_PC], env->sregs[SR_EAR],
env->sregs[SR_ESR], env->iflags);
log_cpu_state_mask(CPU_LOG_INT, env, 0);
log_cpu_state_mask(CPU_LOG_INT, cs, 0);
env->iflags &= ~(IMM_FLAG | D_FLAG);
env->sregs[SR_PC] = cpu->base_vectors + 0x20;
break;
Expand All @@ -175,7 +175,7 @@ void mb_cpu_do_interrupt(CPUState *cs)
"bimm exception at pc=%x iflags=%x\n",
env->sregs[SR_PC], env->iflags);
env->regs[17] -= 4;
log_cpu_state_mask(CPU_LOG_INT, env, 0);
log_cpu_state_mask(CPU_LOG_INT, cs, 0);
}
} else if (env->iflags & IMM_FLAG) {
D(qemu_log("IMM_FLAG set at exception\n"));
Expand All @@ -192,7 +192,7 @@ void mb_cpu_do_interrupt(CPUState *cs)
qemu_log_mask(CPU_LOG_INT,
"exception at pc=%x ear=%x iflags=%x\n",
env->sregs[SR_PC], env->sregs[SR_EAR], env->iflags);
log_cpu_state_mask(CPU_LOG_INT, env, 0);
log_cpu_state_mask(CPU_LOG_INT, cs, 0);
env->iflags &= ~(IMM_FLAG | D_FLAG);
env->sregs[SR_PC] = cpu->base_vectors + 0x20;
break;
Expand Down Expand Up @@ -222,7 +222,7 @@ void mb_cpu_do_interrupt(CPUState *cs)
env->sregs[SR_PC], env->sregs[SR_MSR], t, env->iflags,
sym);

log_cpu_state(env, 0);
log_cpu_state(cs, 0);
}
}
#endif
Expand All @@ -236,7 +236,7 @@ void mb_cpu_do_interrupt(CPUState *cs)

env->regs[14] = env->sregs[SR_PC];
env->sregs[SR_PC] = cpu->base_vectors + 0x10;
//log_cpu_state_mask(CPU_LOG_INT, env, 0);
//log_cpu_state_mask(CPU_LOG_INT, cs, 0);
break;

case EXCP_BREAK:
Expand All @@ -247,7 +247,7 @@ void mb_cpu_do_interrupt(CPUState *cs)
qemu_log_mask(CPU_LOG_INT,
"break at pc=%x msr=%x %x iflags=%x\n",
env->sregs[SR_PC], env->sregs[SR_MSR], t, env->iflags);
log_cpu_state_mask(CPU_LOG_INT, env, 0);
log_cpu_state_mask(CPU_LOG_INT, cs, 0);
env->sregs[SR_MSR] &= ~(MSR_VMS | MSR_UMS | MSR_VM | MSR_UM);
env->sregs[SR_MSR] |= t;
env->sregs[SR_MSR] |= MSR_BIP;
Expand Down
2 changes: 1 addition & 1 deletion target-microblaze/translate.c
Original file line number Diff line number Diff line change
Expand Up @@ -1777,7 +1777,7 @@ gen_intermediate_code_internal(MicroBlazeCPU *cpu, TranslationBlock *tb,
if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) {
#if !SIM_COMPAT
qemu_log("--------------\n");
log_cpu_state(env, 0);
log_cpu_state(CPU(cpu), 0);
#endif
}

Expand Down
2 changes: 1 addition & 1 deletion target-mips/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ static void mips_cpu_reset(CPUState *s)

if (qemu_loglevel_mask(CPU_LOG_RESET)) {
qemu_log("CPU Reset (CPU %d)\n", s->cpu_index);
log_cpu_state(env, 0);
log_cpu_state(s, 0);
}

mcc->parent_reset(s);
Expand Down
2 changes: 1 addition & 1 deletion target-mips/helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ int cpu_mips_handle_mmu_fault (CPUMIPSState *env, target_ulong address, int rw,
int ret = 0;

#if 0
log_cpu_state(env, 0);
log_cpu_state(CPU(mips_env_get_cpu(env)), 0);
#endif
qemu_log("%s pc " TARGET_FMT_lx " ad " TARGET_FMT_lx " rw %d mmu_idx %d\n",
__func__, env->active_tc.PC, address, rw, mmu_idx);
Expand Down
2 changes: 1 addition & 1 deletion target-moxie/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ static void moxie_cpu_reset(CPUState *s)

if (qemu_loglevel_mask(CPU_LOG_RESET)) {
qemu_log("CPU Reset (CPU %d)\n", s->cpu_index);
log_cpu_state(env, 0);
log_cpu_state(s, 0);
}

mcc->parent_reset(s);
Expand Down
2 changes: 1 addition & 1 deletion target-openrisc/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ static void openrisc_cpu_reset(CPUState *s)

if (qemu_loglevel_mask(CPU_LOG_RESET)) {
qemu_log("CPU Reset (CPU %d)\n", s->cpu_index);
log_cpu_state(&cpu->env, 0);
log_cpu_state(s, 0);
}

occ->parent_reset(s);
Expand Down
2 changes: 1 addition & 1 deletion target-openrisc/translate.c
Original file line number Diff line number Diff line change
Expand Up @@ -1684,7 +1684,7 @@ static inline void gen_intermediate_code_internal(OpenRISCCPU *cpu,
dc->singlestep_enabled = cpu->env.singlestep_enabled;
if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) {
qemu_log("-----------------------------------------\n");
log_cpu_state(&cpu->env, 0);
log_cpu_state(CPU(cpu), 0);
}

next_page_start = (pc_start & TARGET_PAGE_MASK) + TARGET_PAGE_SIZE;
Expand Down
2 changes: 1 addition & 1 deletion target-ppc/mmu-hash32.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

#ifdef DEBUG_MMU
# define LOG_MMU(...) qemu_log(__VA_ARGS__)
# define LOG_MMU_STATE(env) log_cpu_state((env), 0)
# define LOG_MMU_STATE(env) log_cpu_state(CPU(ppc_env_get_cpu(env)), 0)
#else
# define LOG_MMU(...) do { } while (0)
# define LOG_MMU_STATE(...) do { } while (0)
Expand Down
2 changes: 1 addition & 1 deletion target-ppc/mmu-hash64.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

#ifdef DEBUG_MMU
# define LOG_MMU(...) qemu_log(__VA_ARGS__)
# define LOG_MMU_STATE(env) log_cpu_state((env), 0)
# define LOG_MMU_STATE(env) log_cpu_state(CPU(ppc_env_get_cpu(env)), 0)
#else
# define LOG_MMU(...) do { } while (0)
# define LOG_MMU_STATE(...) do { } while (0)
Expand Down
2 changes: 1 addition & 1 deletion target-ppc/mmu_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

#ifdef DEBUG_MMU
# define LOG_MMU(...) qemu_log(__VA_ARGS__)
# define LOG_MMU_STATE(env) log_cpu_state((env), 0)
# define LOG_MMU_STATE(env) log_cpu_state(CPU(ppc_env_get_cpu(env)), 0)
#else
# define LOG_MMU(...) do { } while (0)
# define LOG_MMU_STATE(...) do { } while (0)
Expand Down
2 changes: 1 addition & 1 deletion target-ppc/translate_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -8173,7 +8173,7 @@ static void ppc_cpu_reset(CPUState *s)

if (qemu_loglevel_mask(CPU_LOG_RESET)) {
qemu_log("CPU Reset (CPU %d)\n", s->cpu_index);
log_cpu_state(env, 0);
log_cpu_state(s, 0);
}

pcc->parent_reset(s);
Expand Down
2 changes: 1 addition & 1 deletion target-s390x/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ static void s390_cpu_reset(CPUState *s)

if (qemu_loglevel_mask(CPU_LOG_RESET)) {
qemu_log("CPU Reset (CPU %d)\n", s->cpu_index);
log_cpu_state(env, 0);
log_cpu_state(s, 0);
}

s390_del_running_cpu(cpu);
Expand Down
2 changes: 1 addition & 1 deletion target-sh4/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ static void superh_cpu_reset(CPUState *s)

if (qemu_loglevel_mask(CPU_LOG_RESET)) {
qemu_log("CPU Reset (CPU %d)\n", s->cpu_index);
log_cpu_state(env, 0);
log_cpu_state(s, 0);
}

scc->parent_reset(s);
Expand Down
2 changes: 1 addition & 1 deletion target-sh4/helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ void superh_cpu_do_interrupt(CPUState *cs)
}
qemu_log("exception 0x%03x [%s] raised\n",
irq_vector, expname);
log_cpu_state(env, 0);
log_cpu_state(cs, 0);
}

env->ssr = env->sr;
Expand Down
2 changes: 1 addition & 1 deletion target-sparc/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ static void sparc_cpu_reset(CPUState *s)

if (qemu_loglevel_mask(CPU_LOG_RESET)) {
qemu_log("CPU Reset (CPU %d)\n", s->cpu_index);
log_cpu_state(env, 0);
log_cpu_state(s, 0);
}

scc->parent_reset(s);
Expand Down
2 changes: 1 addition & 1 deletion target-sparc/int32_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ void sparc_cpu_do_interrupt(CPUState *cs)
}

qemu_log("%6d: %s (v=%02x)\n", count, name, intno);
log_cpu_state(env, 0);
log_cpu_state(cs, 0);
#if 0
{
int i;
Expand Down
Loading

0 comments on commit a076285

Please sign in to comment.