Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1L56AW-0002Wg-S7 for qemu-devel@nongnu.org; Tue, 25 Nov 2008 17:14:04 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1L56AU-0002QM-5E for qemu-devel@nongnu.org; Tue, 25 Nov 2008 17:14:03 -0500 Received: from [199.232.76.173] (port=50370 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1L56AT-0002Pr-W3 for qemu-devel@nongnu.org; Tue, 25 Nov 2008 17:14:02 -0500 Received: from savannah.gnu.org ([199.232.41.3]:50393 helo=sv.gnu.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1L56AT-0003cl-J5 for qemu-devel@nongnu.org; Tue, 25 Nov 2008 17:14:01 -0500 Received: from cvs.savannah.gnu.org ([199.232.41.69]) by sv.gnu.org with esmtp (Exim 4.63) (envelope-from ) id 1L56AR-00014E-Mv for qemu-devel@nongnu.org; Tue, 25 Nov 2008 22:14:00 +0000 Received: from aliguori by cvs.savannah.gnu.org with local (Exim 4.63) (envelope-from ) id 1L56AQ-000144-2B for qemu-devel@nongnu.org; Tue, 25 Nov 2008 22:13:59 +0000 MIME-Version: 1.0 Errors-To: aliguori Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Anthony Liguori Message-Id: Date: Tue, 25 Nov 2008 22:13:58 +0000 Subject: [Qemu-devel] [5799] Use sys-queue.h for break/watchpoint managment (Jan Kiszka) Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Revision: 5799 http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=5799 Author: aliguori Date: 2008-11-25 22:13:57 +0000 (Tue, 25 Nov 2008) Log Message: ----------- Use sys-queue.h for break/watchpoint managment (Jan Kiszka) This switches cpu_break/watchpoint_* to TAILQ wrappers, simplifying the code and also fixing a use after release issue in cpu_break/watchpoint_remove_all. Signed-off-by: Jan Kiszka Signed-off-by: Anthony Liguori Modified Paths: -------------- trunk/cpu-defs.h trunk/cpu-exec.c trunk/exec.c trunk/target-alpha/translate.c trunk/target-arm/translate.c trunk/target-cris/translate.c trunk/target-i386/helper.c trunk/target-i386/translate.c trunk/target-m68k/translate.c trunk/target-mips/translate.c trunk/target-ppc/translate.c trunk/target-sh4/translate.c trunk/target-sparc/translate.c Modified: trunk/cpu-defs.h =================================================================== --- trunk/cpu-defs.h 2008-11-25 22:05:37 UTC (rev 5798) +++ trunk/cpu-defs.h 2008-11-25 22:13:57 UTC (rev 5799) @@ -28,6 +28,7 @@ #include #include #include "osdep.h" +#include "sys-queue.h" #ifndef TARGET_LONG_BITS #error TARGET_LONG_BITS must be defined before including this header @@ -146,14 +147,14 @@ typedef struct CPUBreakpoint { target_ulong pc; int flags; /* BP_* */ - struct CPUBreakpoint *prev, *next; + TAILQ_ENTRY(CPUBreakpoint) entry; } CPUBreakpoint; typedef struct CPUWatchpoint { target_ulong vaddr; target_ulong len_mask; int flags; /* BP_* */ - struct CPUWatchpoint *prev, *next; + TAILQ_ENTRY(CPUWatchpoint) entry; } CPUWatchpoint; #define CPU_TEMP_BUF_NLONGS 128 @@ -188,10 +189,10 @@ \ /* from this point: preserved by CPU reset */ \ /* ice debug support */ \ - CPUBreakpoint *breakpoints; \ + TAILQ_HEAD(breakpoints_head, CPUBreakpoint) breakpoints; \ int singlestep_enabled; \ \ - CPUWatchpoint *watchpoints; \ + TAILQ_HEAD(watchpoints_head, CPUWatchpoint) watchpoints; \ CPUWatchpoint *watchpoint_hit; \ \ struct GDBRegisterState *gdb_regs; \ Modified: trunk/cpu-exec.c =================================================================== --- trunk/cpu-exec.c 2008-11-25 22:05:37 UTC (rev 5798) +++ trunk/cpu-exec.c 2008-11-25 22:13:57 UTC (rev 5799) @@ -198,7 +198,7 @@ CPUWatchpoint *wp; if (!env->watchpoint_hit) - for (wp = env->watchpoints; wp != NULL; wp = wp->next) + TAILQ_FOREACH(wp, &env->watchpoints, entry) wp->flags &= ~BP_WATCHPOINT_HIT; if (debug_excp_handler) Modified: trunk/exec.c =================================================================== --- trunk/exec.c 2008-11-25 22:05:37 UTC (rev 5798) +++ trunk/exec.c 2008-11-25 22:13:57 UTC (rev 5799) @@ -537,6 +537,8 @@ cpu_index++; } env->cpu_index = cpu_index; + TAILQ_INIT(&env->breakpoints); + TAILQ_INIT(&env->watchpoints); *penv = env; #if defined(CPU_SAVE_VERSION) && !defined(CONFIG_USER_ONLY) register_savevm("cpu_common", cpu_index, CPU_COMMON_SAVE_VERSION, @@ -1302,7 +1304,7 @@ int flags, CPUWatchpoint **watchpoint) { target_ulong len_mask = ~(len - 1); - CPUWatchpoint *wp, *prev_wp; + CPUWatchpoint *wp; /* sanity checks: allow power-of-2 lengths, deny unaligned watchpoints */ if ((len != 1 && len != 2 && len != 4 && len != 8) || (addr & ~len_mask)) { @@ -1319,26 +1321,11 @@ wp->flags = flags; /* keep all GDB-injected watchpoints in front */ - if (!(flags & BP_GDB) && env->watchpoints) { - prev_wp = env->watchpoints; - while (prev_wp->next != NULL && (prev_wp->next->flags & BP_GDB)) - prev_wp = prev_wp->next; - } else { - prev_wp = NULL; - } + if (flags & BP_GDB) + TAILQ_INSERT_HEAD(&env->watchpoints, wp, entry); + else + TAILQ_INSERT_TAIL(&env->watchpoints, wp, entry); - /* Insert new watchpoint */ - if (prev_wp) { - wp->next = prev_wp->next; - prev_wp->next = wp; - } else { - wp->next = env->watchpoints; - env->watchpoints = wp; - } - if (wp->next) - wp->next->prev = wp; - wp->prev = prev_wp; - tlb_flush_page(env, addr); if (watchpoint) @@ -1353,7 +1340,7 @@ target_ulong len_mask = ~(len - 1); CPUWatchpoint *wp; - for (wp = env->watchpoints; wp != NULL; wp = wp->next) { + TAILQ_FOREACH(wp, &env->watchpoints, entry) { if (addr == wp->vaddr && len_mask == wp->len_mask && flags == (wp->flags & ~BP_WATCHPOINT_HIT)) { cpu_watchpoint_remove_by_ref(env, wp); @@ -1366,12 +1353,7 @@ /* Remove a specific watchpoint by reference. */ void cpu_watchpoint_remove_by_ref(CPUState *env, CPUWatchpoint *watchpoint) { - if (watchpoint->next) - watchpoint->next->prev = watchpoint->prev; - if (watchpoint->prev) - watchpoint->prev->next = watchpoint->next; - else - env->watchpoints = watchpoint->next; + TAILQ_REMOVE(&env->watchpoints, watchpoint, entry); tlb_flush_page(env, watchpoint->vaddr); @@ -1381,11 +1363,12 @@ /* Remove all matching watchpoints. */ void cpu_watchpoint_remove_all(CPUState *env, int mask) { - CPUWatchpoint *wp; + CPUWatchpoint *wp, *next; - for (wp = env->watchpoints; wp != NULL; wp = wp->next) + TAILQ_FOREACH_SAFE(wp, &env->watchpoints, entry, next) { if (wp->flags & mask) cpu_watchpoint_remove_by_ref(env, wp); + } } /* Add a breakpoint. */ @@ -1393,7 +1376,7 @@ CPUBreakpoint **breakpoint) { #if defined(TARGET_HAS_ICE) - CPUBreakpoint *bp, *prev_bp; + CPUBreakpoint *bp; bp = qemu_malloc(sizeof(*bp)); if (!bp) @@ -1403,26 +1386,11 @@ bp->flags = flags; /* keep all GDB-injected breakpoints in front */ - if (!(flags & BP_GDB) && env->breakpoints) { - prev_bp = env->breakpoints; - while (prev_bp->next != NULL && (prev_bp->next->flags & BP_GDB)) - prev_bp = prev_bp->next; - } else { - prev_bp = NULL; - } + if (flags & BP_GDB) + TAILQ_INSERT_HEAD(&env->breakpoints, bp, entry); + else + TAILQ_INSERT_TAIL(&env->breakpoints, bp, entry); - /* Insert new breakpoint */ - if (prev_bp) { - bp->next = prev_bp->next; - prev_bp->next = bp; - } else { - bp->next = env->breakpoints; - env->breakpoints = bp; - } - if (bp->next) - bp->next->prev = bp; - bp->prev = prev_bp; - breakpoint_invalidate(env, pc); if (breakpoint) @@ -1439,7 +1407,7 @@ #if defined(TARGET_HAS_ICE) CPUBreakpoint *bp; - for (bp = env->breakpoints; bp != NULL; bp = bp->next) { + TAILQ_FOREACH(bp, &env->breakpoints, entry) { if (bp->pc == pc && bp->flags == flags) { cpu_breakpoint_remove_by_ref(env, bp); return 0; @@ -1455,12 +1423,7 @@ void cpu_breakpoint_remove_by_ref(CPUState *env, CPUBreakpoint *breakpoint) { #if defined(TARGET_HAS_ICE) - if (breakpoint->next) - breakpoint->next->prev = breakpoint->prev; - if (breakpoint->prev) - breakpoint->prev->next = breakpoint->next; - else - env->breakpoints = breakpoint->next; + TAILQ_REMOVE(&env->breakpoints, breakpoint, entry); breakpoint_invalidate(env, breakpoint->pc); @@ -1472,11 +1435,12 @@ void cpu_breakpoint_remove_all(CPUState *env, int mask) { #if defined(TARGET_HAS_ICE) - CPUBreakpoint *bp; + CPUBreakpoint *bp, *next; - for (bp = env->breakpoints; bp != NULL; bp = bp->next) + TAILQ_FOREACH_SAFE(bp, &env->breakpoints, entry, next) { if (bp->flags & mask) cpu_breakpoint_remove_by_ref(env, bp); + } #endif } @@ -2005,7 +1969,7 @@ code_address = address; /* Make accesses to pages with watchpoints go via the watchpoint trap routines. */ - for (wp = env->watchpoints; wp != NULL; wp = wp->next) { + TAILQ_FOREACH(wp, &env->watchpoints, entry) { if (vaddr == (wp->vaddr & TARGET_PAGE_MASK)) { iotlb = io_mem_watch + paddr; /* TODO: The memory case can be optimized by not trapping @@ -2552,7 +2516,7 @@ return; } vaddr = (env->mem_io_vaddr & TARGET_PAGE_MASK) + offset; - for (wp = env->watchpoints; wp != NULL; wp = wp->next) { + TAILQ_FOREACH(wp, &env->watchpoints, entry) { if ((vaddr == (wp->vaddr & len_mask) || (vaddr & wp->len_mask) == wp->vaddr) && (wp->flags & flags)) { wp->flags |= BP_WATCHPOINT_HIT; Modified: trunk/target-alpha/translate.c =================================================================== --- trunk/target-alpha/translate.c 2008-11-25 22:05:37 UTC (rev 5798) +++ trunk/target-alpha/translate.c 2008-11-25 22:13:57 UTC (rev 5799) @@ -2363,8 +2363,8 @@ gen_icount_start(); for (ret = 0; ret == 0;) { - if (unlikely(env->breakpoints)) { - for (bp = env->breakpoints; bp != NULL; bp = bp->next) { + if (unlikely(!TAILQ_EMPTY(&env->breakpoints))) { + TAILQ_FOREACH(bp, &env->breakpoints, entry) { if (bp->pc == ctx.pc) { gen_excp(&ctx, EXCP_DEBUG, 0); break; Modified: trunk/target-arm/translate.c =================================================================== --- trunk/target-arm/translate.c 2008-11-25 22:05:37 UTC (rev 5798) +++ trunk/target-arm/translate.c 2008-11-25 22:13:57 UTC (rev 5799) @@ -8677,8 +8677,8 @@ } #endif - if (unlikely(env->breakpoints)) { - for (bp = env->breakpoints; bp != NULL; bp = bp->next) { + if (unlikely(!TAILQ_EMPTY(&env->breakpoints))) { + TAILQ_FOREACH(bp, &env->breakpoints, entry) { if (bp->pc == dc->pc) { gen_set_condexec(dc); gen_set_pc_im(dc->pc); Modified: trunk/target-cris/translate.c =================================================================== --- trunk/target-cris/translate.c 2008-11-25 22:05:37 UTC (rev 5798) +++ trunk/target-cris/translate.c 2008-11-25 22:13:57 UTC (rev 5799) @@ -3189,8 +3189,8 @@ { CPUBreakpoint *bp; - if (unlikely(env->breakpoints)) { - for (bp = env->breakpoints; bp != NULL; bp = bp->next) { + if (unlikely(!TAILQ_EMPTY(&env->breakpoints))) { + TAILQ_FOREACH(bp, &env->breakpoints, entry) { if (bp->pc == dc->pc) { cris_evaluate_flags (dc); tcg_gen_movi_tl(env_pc, dc->pc); Modified: trunk/target-i386/helper.c =================================================================== --- trunk/target-i386/helper.c 2008-11-25 22:05:37 UTC (rev 5798) +++ trunk/target-i386/helper.c 2008-11-25 22:13:57 UTC (rev 5799) @@ -1364,7 +1364,7 @@ cpu_resume_from_signal(env, NULL); } } else { - for (bp = env->breakpoints; bp != NULL; bp = bp->next) + TAILQ_FOREACH(bp, &env->breakpoints, entry) if (bp->pc == env->eip) { if (bp->flags & BP_CPU) { check_hw_breakpoints(env, 1); Modified: trunk/target-i386/translate.c =================================================================== --- trunk/target-i386/translate.c 2008-11-25 22:05:37 UTC (rev 5798) +++ trunk/target-i386/translate.c 2008-11-25 22:13:57 UTC (rev 5799) @@ -7606,8 +7606,8 @@ gen_icount_start(); for(;;) { - if (unlikely(env->breakpoints)) { - for (bp = env->breakpoints; bp != NULL; bp = bp->next) { + if (unlikely(!TAILQ_EMPTY(&env->breakpoints))) { + TAILQ_FOREACH(bp, &env->breakpoints, entry) { if (bp->pc == pc_ptr) { gen_debug(dc, pc_ptr - dc->cs_base); break; Modified: trunk/target-m68k/translate.c =================================================================== --- trunk/target-m68k/translate.c 2008-11-25 22:05:37 UTC (rev 5798) +++ trunk/target-m68k/translate.c 2008-11-25 22:13:57 UTC (rev 5799) @@ -2999,8 +2999,8 @@ do { pc_offset = dc->pc - pc_start; gen_throws_exception = NULL; - if (unlikely(env->breakpoints)) { - for (bp = env->breakpoints; bp != NULL; bp = bp->next) { + if (unlikely(!TAILQ_EMPTY(&env->breakpoints))) { + TAILQ_FOREACH(bp, &env->breakpoints, entry) { if (bp->pc == dc->pc) { gen_exception(dc, dc->pc, EXCP_DEBUG); dc->is_jmp = DISAS_JUMP; Modified: trunk/target-mips/translate.c =================================================================== --- trunk/target-mips/translate.c 2008-11-25 22:05:37 UTC (rev 5798) +++ trunk/target-mips/translate.c 2008-11-25 22:13:57 UTC (rev 5799) @@ -8286,8 +8286,8 @@ #endif gen_icount_start(); while (ctx.bstate == BS_NONE) { - if (unlikely(env->breakpoints)) { - for (bp = env->breakpoints; bp != NULL; bp = bp->next) { + if (unlikely(!TAILQ_EMPTY(&env->breakpoints))) { + TAILQ_FOREACH(bp, &env->breakpoints, entry) { if (bp->pc == ctx.pc) { save_cpu_state(&ctx, 1); ctx.bstate = BS_BRANCH; Modified: trunk/target-ppc/translate.c =================================================================== --- trunk/target-ppc/translate.c 2008-11-25 22:05:37 UTC (rev 5798) +++ trunk/target-ppc/translate.c 2008-11-25 22:13:57 UTC (rev 5799) @@ -7562,8 +7562,8 @@ gen_icount_start(); /* Set env in case of segfault during code fetch */ while (ctx.exception == POWERPC_EXCP_NONE && gen_opc_ptr < gen_opc_end) { - if (unlikely(env->breakpoints)) { - for (bp = env->breakpoints; bp != NULL; bp = bp->next) { + if (unlikely(!TAILQ_EMPTY(&env->breakpoints))) { + TAILQ_FOREACH(bp, &env->breakpoints, entry) { if (bp->pc == ctx.nip) { gen_update_nip(&ctx, ctx.nip); gen_helper_raise_debug(); Modified: trunk/target-sh4/translate.c =================================================================== --- trunk/target-sh4/translate.c 2008-11-25 22:05:37 UTC (rev 5798) +++ trunk/target-sh4/translate.c 2008-11-25 22:13:57 UTC (rev 5799) @@ -1776,8 +1776,8 @@ max_insns = CF_COUNT_MASK; gen_icount_start(); while (ctx.bstate == BS_NONE && gen_opc_ptr < gen_opc_end) { - if (unlikely(env->breakpoints)) { - for (bp = env->breakpoints; bp != NULL; bp = bp->next) { + if (unlikely(!TAILQ_EMPTY(&env->breakpoints))) { + TAILQ_FOREACH(bp, &env->breakpoints, entry) { if (ctx.pc == bp->pc) { /* We have hit a breakpoint - make sure PC is up-to-date */ tcg_gen_movi_i32(cpu_pc, ctx.pc); Modified: trunk/target-sparc/translate.c =================================================================== --- trunk/target-sparc/translate.c 2008-11-25 22:05:37 UTC (rev 5798) +++ trunk/target-sparc/translate.c 2008-11-25 22:13:57 UTC (rev 5799) @@ -4816,8 +4816,8 @@ max_insns = CF_COUNT_MASK; gen_icount_start(); do { - if (unlikely(env->breakpoints)) { - for (bp = env->breakpoints; bp != NULL; bp = bp->next) { + if (unlikely(!TAILQ_EMPTY(&env->breakpoints))) { + TAILQ_FOREACH(bp, &env->breakpoints, entry) { if (bp->pc == dc->pc) { if (dc->pc != pc_start) save_state(dc, cpu_cond);