exec: Change cpu_breakpoint_{insert,remove{,_by_ref,_all}} argument

Use CPUState. Allows to clean up CPUArchState in gdbstub.

Signed-off-by: Andreas Färber <afaerber@suse.de>
This commit is contained in:
Andreas Färber 2013-09-02 17:26:20 +02:00
parent 75a34036d4
commit b3310ab338
9 changed files with 43 additions and 46 deletions

20
exec.c
View file

@ -617,11 +617,10 @@ void cpu_watchpoint_remove_all(CPUState *cpu, int mask)
#endif #endif
/* Add a breakpoint. */ /* Add a breakpoint. */
int cpu_breakpoint_insert(CPUArchState *env, target_ulong pc, int flags, int cpu_breakpoint_insert(CPUState *cpu, vaddr pc, int flags,
CPUBreakpoint **breakpoint) CPUBreakpoint **breakpoint)
{ {
#if defined(TARGET_HAS_ICE) #if defined(TARGET_HAS_ICE)
CPUState *cpu = ENV_GET_CPU(env);
CPUBreakpoint *bp; CPUBreakpoint *bp;
bp = g_malloc(sizeof(*bp)); bp = g_malloc(sizeof(*bp));
@ -648,15 +647,14 @@ int cpu_breakpoint_insert(CPUArchState *env, target_ulong pc, int flags,
} }
/* Remove a specific breakpoint. */ /* Remove a specific breakpoint. */
int cpu_breakpoint_remove(CPUArchState *env, target_ulong pc, int flags) int cpu_breakpoint_remove(CPUState *cpu, vaddr pc, int flags)
{ {
#if defined(TARGET_HAS_ICE) #if defined(TARGET_HAS_ICE)
CPUState *cpu = ENV_GET_CPU(env);
CPUBreakpoint *bp; CPUBreakpoint *bp;
QTAILQ_FOREACH(bp, &cpu->breakpoints, entry) { QTAILQ_FOREACH(bp, &cpu->breakpoints, entry) {
if (bp->pc == pc && bp->flags == flags) { if (bp->pc == pc && bp->flags == flags) {
cpu_breakpoint_remove_by_ref(env, bp); cpu_breakpoint_remove_by_ref(cpu, bp);
return 0; return 0;
} }
} }
@ -667,11 +665,9 @@ int cpu_breakpoint_remove(CPUArchState *env, target_ulong pc, int flags)
} }
/* Remove a specific breakpoint by reference. */ /* Remove a specific breakpoint by reference. */
void cpu_breakpoint_remove_by_ref(CPUArchState *env, CPUBreakpoint *breakpoint) void cpu_breakpoint_remove_by_ref(CPUState *cpu, CPUBreakpoint *breakpoint)
{ {
#if defined(TARGET_HAS_ICE) #if defined(TARGET_HAS_ICE)
CPUState *cpu = ENV_GET_CPU(env);
QTAILQ_REMOVE(&cpu->breakpoints, breakpoint, entry); QTAILQ_REMOVE(&cpu->breakpoints, breakpoint, entry);
breakpoint_invalidate(cpu, breakpoint->pc); breakpoint_invalidate(cpu, breakpoint->pc);
@ -681,15 +677,15 @@ void cpu_breakpoint_remove_by_ref(CPUArchState *env, CPUBreakpoint *breakpoint)
} }
/* Remove all matching breakpoints. */ /* Remove all matching breakpoints. */
void cpu_breakpoint_remove_all(CPUArchState *env, int mask) void cpu_breakpoint_remove_all(CPUState *cpu, int mask)
{ {
#if defined(TARGET_HAS_ICE) #if defined(TARGET_HAS_ICE)
CPUState *cpu = ENV_GET_CPU(env);
CPUBreakpoint *bp, *next; CPUBreakpoint *bp, *next;
QTAILQ_FOREACH_SAFE(bp, &cpu->breakpoints, entry, next) { QTAILQ_FOREACH_SAFE(bp, &cpu->breakpoints, entry, next) {
if (bp->flags & mask) if (bp->flags & mask) {
cpu_breakpoint_remove_by_ref(env, bp); cpu_breakpoint_remove_by_ref(cpu, bp);
}
} }
#endif #endif
} }

View file

@ -635,7 +635,6 @@ static const int xlat_gdb_type[] = {
static int gdb_breakpoint_insert(target_ulong addr, target_ulong len, int type) static int gdb_breakpoint_insert(target_ulong addr, target_ulong len, int type)
{ {
CPUState *cpu; CPUState *cpu;
CPUArchState *env;
int err = 0; int err = 0;
if (kvm_enabled()) { if (kvm_enabled()) {
@ -646,10 +645,10 @@ static int gdb_breakpoint_insert(target_ulong addr, target_ulong len, int type)
case GDB_BREAKPOINT_SW: case GDB_BREAKPOINT_SW:
case GDB_BREAKPOINT_HW: case GDB_BREAKPOINT_HW:
CPU_FOREACH(cpu) { CPU_FOREACH(cpu) {
env = cpu->env_ptr; err = cpu_breakpoint_insert(cpu, addr, BP_GDB, NULL);
err = cpu_breakpoint_insert(env, addr, BP_GDB, NULL); if (err) {
if (err)
break; break;
}
} }
return err; return err;
#ifndef CONFIG_USER_ONLY #ifndef CONFIG_USER_ONLY
@ -672,7 +671,6 @@ static int gdb_breakpoint_insert(target_ulong addr, target_ulong len, int type)
static int gdb_breakpoint_remove(target_ulong addr, target_ulong len, int type) static int gdb_breakpoint_remove(target_ulong addr, target_ulong len, int type)
{ {
CPUState *cpu; CPUState *cpu;
CPUArchState *env;
int err = 0; int err = 0;
if (kvm_enabled()) { if (kvm_enabled()) {
@ -683,10 +681,10 @@ static int gdb_breakpoint_remove(target_ulong addr, target_ulong len, int type)
case GDB_BREAKPOINT_SW: case GDB_BREAKPOINT_SW:
case GDB_BREAKPOINT_HW: case GDB_BREAKPOINT_HW:
CPU_FOREACH(cpu) { CPU_FOREACH(cpu) {
env = cpu->env_ptr; err = cpu_breakpoint_remove(cpu, addr, BP_GDB);
err = cpu_breakpoint_remove(env, addr, BP_GDB); if (err) {
if (err)
break; break;
}
} }
return err; return err;
#ifndef CONFIG_USER_ONLY #ifndef CONFIG_USER_ONLY
@ -708,7 +706,6 @@ static int gdb_breakpoint_remove(target_ulong addr, target_ulong len, int type)
static void gdb_breakpoint_remove_all(void) static void gdb_breakpoint_remove_all(void)
{ {
CPUState *cpu; CPUState *cpu;
CPUArchState *env;
if (kvm_enabled()) { if (kvm_enabled()) {
kvm_remove_all_breakpoints(gdbserver_state->c_cpu); kvm_remove_all_breakpoints(gdbserver_state->c_cpu);
@ -716,8 +713,7 @@ static void gdb_breakpoint_remove_all(void)
} }
CPU_FOREACH(cpu) { CPU_FOREACH(cpu) {
env = cpu->env_ptr; cpu_breakpoint_remove_all(cpu, BP_GDB);
cpu_breakpoint_remove_all(env, BP_GDB);
#ifndef CONFIG_USER_ONLY #ifndef CONFIG_USER_ONLY
cpu_watchpoint_remove_all(cpu, BP_GDB); cpu_watchpoint_remove_all(cpu, BP_GDB);
#endif #endif
@ -1599,7 +1595,7 @@ void gdbserver_fork(CPUArchState *env)
} }
close(s->fd); close(s->fd);
s->fd = -1; s->fd = -1;
cpu_breakpoint_remove_all(env, BP_GDB); cpu_breakpoint_remove_all(cpu, BP_GDB);
cpu_watchpoint_remove_all(cpu, BP_GDB); cpu_watchpoint_remove_all(cpu, BP_GDB);
} }
#else #else

View file

@ -413,21 +413,6 @@ void QEMU_NORETURN cpu_abort(CPUArchState *env, const char *fmt, ...)
| CPU_INTERRUPT_TGT_EXT_3 \ | CPU_INTERRUPT_TGT_EXT_3 \
| CPU_INTERRUPT_TGT_EXT_4) | CPU_INTERRUPT_TGT_EXT_4)
/* Breakpoint/watchpoint flags */
#define BP_MEM_READ 0x01
#define BP_MEM_WRITE 0x02
#define BP_MEM_ACCESS (BP_MEM_READ | BP_MEM_WRITE)
#define BP_STOP_BEFORE_ACCESS 0x04
#define BP_WATCHPOINT_HIT 0x08
#define BP_GDB 0x10
#define BP_CPU 0x20
int cpu_breakpoint_insert(CPUArchState *env, target_ulong pc, int flags,
CPUBreakpoint **breakpoint);
int cpu_breakpoint_remove(CPUArchState *env, target_ulong pc, int flags);
void cpu_breakpoint_remove_by_ref(CPUArchState *env, CPUBreakpoint *breakpoint);
void cpu_breakpoint_remove_all(CPUArchState *env, int mask);
#if !defined(CONFIG_USER_ONLY) #if !defined(CONFIG_USER_ONLY)
/* memory API */ /* memory API */

View file

@ -595,6 +595,21 @@ void qemu_init_vcpu(CPUState *cpu);
*/ */
void cpu_single_step(CPUState *cpu, int enabled); void cpu_single_step(CPUState *cpu, int enabled);
/* Breakpoint/watchpoint flags */
#define BP_MEM_READ 0x01
#define BP_MEM_WRITE 0x02
#define BP_MEM_ACCESS (BP_MEM_READ | BP_MEM_WRITE)
#define BP_STOP_BEFORE_ACCESS 0x04
#define BP_WATCHPOINT_HIT 0x08
#define BP_GDB 0x10
#define BP_CPU 0x20
int cpu_breakpoint_insert(CPUState *cpu, vaddr pc, int flags,
CPUBreakpoint **breakpoint);
int cpu_breakpoint_remove(CPUState *cpu, vaddr pc, int flags);
void cpu_breakpoint_remove_by_ref(CPUState *cpu, CPUBreakpoint *breakpoint);
void cpu_breakpoint_remove_all(CPUState *cpu, int mask);
int cpu_watchpoint_insert(CPUState *cpu, vaddr addr, vaddr len, int cpu_watchpoint_insert(CPUState *cpu, vaddr addr, vaddr len,
int flags, CPUWatchpoint **watchpoint); int flags, CPUWatchpoint **watchpoint);
int cpu_watchpoint_remove(CPUState *cpu, vaddr addr, int cpu_watchpoint_remove(CPUState *cpu, vaddr addr,

View file

@ -3455,7 +3455,7 @@ CPUArchState *cpu_copy(CPUArchState *env)
QTAILQ_INIT(&cpu->watchpoints); QTAILQ_INIT(&cpu->watchpoints);
#if defined(TARGET_HAS_ICE) #if defined(TARGET_HAS_ICE)
QTAILQ_FOREACH(bp, &cpu->breakpoints, entry) { QTAILQ_FOREACH(bp, &cpu->breakpoints, entry) {
cpu_breakpoint_insert(new_env, bp->pc, bp->flags, NULL); cpu_breakpoint_insert(new_cpu, bp->pc, bp->flags, NULL);
} }
QTAILQ_FOREACH(wp, &cpu->watchpoints, entry) { QTAILQ_FOREACH(wp, &cpu->watchpoints, entry) {
cpu_watchpoint_insert(new_cpu, wp->vaddr, (~wp->len_mask) + 1, cpu_watchpoint_insert(new_cpu, wp->vaddr, (~wp->len_mask) + 1,

View file

@ -2473,7 +2473,7 @@ static void x86_cpu_reset(CPUState *s)
memset(env->dr, 0, sizeof(env->dr)); memset(env->dr, 0, sizeof(env->dr));
env->dr[6] = DR6_FIXED_1; env->dr[6] = DR6_FIXED_1;
env->dr[7] = DR7_FIXED_1; env->dr[7] = DR7_FIXED_1;
cpu_breakpoint_remove_all(env, BP_CPU); cpu_breakpoint_remove_all(s, BP_CPU);
cpu_watchpoint_remove_all(s, BP_CPU); cpu_watchpoint_remove_all(s, BP_CPU);
env->tsc_adjust = 0; env->tsc_adjust = 0;

View file

@ -999,7 +999,7 @@ void hw_breakpoint_insert(CPUX86State *env, int index)
switch (hw_breakpoint_type(env->dr[7], index)) { switch (hw_breakpoint_type(env->dr[7], index)) {
case DR7_TYPE_BP_INST: case DR7_TYPE_BP_INST:
if (hw_breakpoint_enabled(env->dr[7], index)) { if (hw_breakpoint_enabled(env->dr[7], index)) {
err = cpu_breakpoint_insert(env, env->dr[index], BP_CPU, err = cpu_breakpoint_insert(cs, env->dr[index], BP_CPU,
&env->cpu_breakpoint[index]); &env->cpu_breakpoint[index]);
} }
break; break;
@ -1036,7 +1036,7 @@ void hw_breakpoint_remove(CPUX86State *env, int index)
switch (hw_breakpoint_type(env->dr[7], index)) { switch (hw_breakpoint_type(env->dr[7], index)) {
case DR7_TYPE_BP_INST: case DR7_TYPE_BP_INST:
if (hw_breakpoint_enabled(env->dr[7], index)) { if (hw_breakpoint_enabled(env->dr[7], index)) {
cpu_breakpoint_remove_by_ref(env, env->cpu_breakpoint[index]); cpu_breakpoint_remove_by_ref(cs, env->cpu_breakpoint[index]);
} }
break; break;
case DR7_TYPE_DATA_WR: case DR7_TYPE_DATA_WR:

View file

@ -320,7 +320,7 @@ static int cpu_post_load(void *opaque, int version_id)
env->fptags[i] = (env->fptag_vmstate >> i) & 1; env->fptags[i] = (env->fptag_vmstate >> i) & 1;
} }
cpu_breakpoint_remove_all(env, BP_CPU); cpu_breakpoint_remove_all(cs, BP_CPU);
cpu_watchpoint_remove_all(cs, BP_CPU); cpu_watchpoint_remove_all(cs, BP_CPU);
for (i = 0; i < DR7_MAX_BP; i++) { for (i = 0; i < DR7_MAX_BP; i++) {
hw_breakpoint_insert(env, i); hw_breakpoint_insert(env, i);

View file

@ -53,16 +53,21 @@ hwaddr lm32_cpu_get_phys_page_debug(CPUState *cs, vaddr addr)
void lm32_breakpoint_insert(CPULM32State *env, int idx, target_ulong address) void lm32_breakpoint_insert(CPULM32State *env, int idx, target_ulong address)
{ {
cpu_breakpoint_insert(env, address, BP_CPU, &env->cpu_breakpoint[idx]); LM32CPU *cpu = lm32_env_get_cpu(env);
cpu_breakpoint_insert(CPU(cpu), address, BP_CPU,
&env->cpu_breakpoint[idx]);
} }
void lm32_breakpoint_remove(CPULM32State *env, int idx) void lm32_breakpoint_remove(CPULM32State *env, int idx)
{ {
LM32CPU *cpu = lm32_env_get_cpu(env);
if (!env->cpu_breakpoint[idx]) { if (!env->cpu_breakpoint[idx]) {
return; return;
} }
cpu_breakpoint_remove_by_ref(env, env->cpu_breakpoint[idx]); cpu_breakpoint_remove_by_ref(CPU(cpu), env->cpu_breakpoint[idx]);
env->cpu_breakpoint[idx] = NULL; env->cpu_breakpoint[idx] = NULL;
} }