From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KERIp-0006N8-29 for qemu-devel@nongnu.org; Thu, 03 Jul 2008 12:04:59 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KERIm-0006LO-4P for qemu-devel@nongnu.org; Thu, 03 Jul 2008 12:04:57 -0400 Received: from [199.232.76.173] (port=33011 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KERIl-0006L7-TU for qemu-devel@nongnu.org; Thu, 03 Jul 2008 12:04:55 -0400 Received: from lizzard.sbs.de ([194.138.37.39]:19224) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1KERIk-0002F6-AZ for qemu-devel@nongnu.org; Thu, 03 Jul 2008 12:04:55 -0400 Received: from mail2.sbs.de (localhost [127.0.0.1]) by lizzard.sbs.de (8.12.11.20060308/8.12.11) with ESMTP id m63G4nBX005367 for ; Thu, 3 Jul 2008 18:04:49 +0200 Received: from [139.25.109.167] (mchn012c.mchp.siemens.de [139.25.109.167] (may be forged)) by mail2.sbs.de (8.12.11.20060308/8.12.11) with ESMTP id m63G4nSd022036 for ; Thu, 3 Jul 2008 18:04:49 +0200 Resent-To: qemu-devel@nongnu.org Resent-Message-Id: <486CF8A1.7030806@siemens.com> Message-ID: <486CF83F.9010604@siemens.com> Date: Thu, 03 Jul 2008 18:03:11 +0200 From: Jan Kiszka MIME-Version: 1.0 References: <486CF559.5090805@siemens.com> In-Reply-To: <486CF559.5090805@siemens.com> Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: 7bit Subject: [Qemu-devel] [PATCH 12/13] Introduce BP_CPU as a breakpoint type 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 Add another breakpoint/watchpoint type to BP_GDB: BP_CPU. This type is intended for hardware-assisted break/watchpoint emulations like the x86 architecture requires. To keep the highest priority for BP_GDB breakpoints, this type is always inserted at the head of break/watchpoint lists, thus is found first when looking up the origin of a debug interruption. Signed-off-by: Jan Kiszka --- cpu-all.h | 1 + exec.c | 46 ++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 39 insertions(+), 8 deletions(-) Index: b/cpu-all.h =================================================================== --- a/cpu-all.h +++ b/cpu-all.h @@ -806,6 +806,7 @@ void cpu_reset_interrupt(CPUState *env, #define BP_STOP_BEFORE_ACCESS 0x04 #define BP_WATCHPOINT_HIT 0x08 #define BP_GDB 0x10 +#define BP_CPU 0x20 int cpu_breakpoint_insert(CPUState *env, target_ulong pc, int flags, CPUBreakpoint **breakpoint); Index: b/exec.c =================================================================== --- a/exec.c +++ b/exec.c @@ -1236,7 +1236,7 @@ int cpu_watchpoint_insert(CPUState *env, int flags, CPUWatchpoint **watchpoint) { target_ulong len_mask = ~(len - 1); - CPUWatchpoint *wp; + CPUWatchpoint *wp, *prev_wp; /* sanity checks: allow power-of-2 lengths, deny unaligned watchpoints */ if ((len != 1 && len != 2 && len != 4) || (addr & ~len_mask)) @@ -1250,11 +1250,26 @@ int cpu_watchpoint_insert(CPUState *env, wp->len_mask = len_mask; wp->flags = flags; - wp->next = env->watchpoints; - wp->prev = NULL; + /* 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; + } + + /* 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; - env->watchpoints = wp; + wp->prev = prev_wp; tlb_flush_page(env, addr); @@ -1310,7 +1325,7 @@ int cpu_breakpoint_insert(CPUState *env, CPUBreakpoint **breakpoint) { #if defined(TARGET_HAS_ICE) - CPUBreakpoint *bp; + CPUBreakpoint *bp, *prev_bp; bp = qemu_malloc(sizeof(*bp)); if (!bp) @@ -1319,11 +1334,26 @@ int cpu_breakpoint_insert(CPUState *env, bp->pc = pc; bp->flags = flags; - bp->next = env->breakpoints; - bp->prev = NULL; + /* 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; + } + + /* 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; - env->breakpoints = bp; + bp->prev = prev_bp; breakpoint_invalidate(env, pc);