From patchwork Sun Jun 9 19:13:19 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Andreas_F=C3=A4rber?= X-Patchwork-Id: 250111 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 2024C2C02A9 for ; Mon, 10 Jun 2013 05:35:37 +1000 (EST) Received: from localhost ([::1]:60370 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UllOp-0000DX-7d for incoming@patchwork.ozlabs.org; Sun, 09 Jun 2013 15:35:35 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59383) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ull4h-0001At-PQ for qemu-devel@nongnu.org; Sun, 09 Jun 2013 15:14:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Ull4f-0000rW-SV for qemu-devel@nongnu.org; Sun, 09 Jun 2013 15:14:47 -0400 Received: from cantor2.suse.de ([195.135.220.15]:44467 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ull4f-0000rI-FQ for qemu-devel@nongnu.org; Sun, 09 Jun 2013 15:14:45 -0400 Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 1203CA398F for ; Sun, 9 Jun 2013 21:14:45 +0200 (CEST) From: =?UTF-8?q?Andreas=20F=C3=A4rber?= To: qemu-devel@nongnu.org Date: Sun, 9 Jun 2013 21:13:19 +0200 Message-Id: <1370805206-26574-53-git-send-email-afaerber@suse.de> X-Mailer: git-send-email 1.8.1.4 In-Reply-To: <1370805206-26574-1-git-send-email-afaerber@suse.de> References: <1370805206-26574-1-git-send-email-afaerber@suse.de> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x X-Received-From: 195.135.220.15 Cc: =?UTF-8?q?Andreas=20F=C3=A4rber?= Subject: [Qemu-devel] [PATCH qom-cpu 52/59] gdbstub: Abstract gdb_breakpoint_{insert, remove}() with qemu_for_each_cpu() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Andreas Färber --- gdbstub.c | 106 +++++++++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 77 insertions(+), 29 deletions(-) diff --git a/gdbstub.c b/gdbstub.c index e05cd66..eb47068 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -1944,10 +1944,46 @@ static const int xlat_gdb_type[] = { }; #endif +typedef struct GDBBreakpointAddRemoveData { + target_ulong addr; + target_ulong len; + int type; + int ret; +} GDBBreakpointAddRemoveData; + +static void gdb_breakpoint_insert_one(CPUState *cpu, void *data) +{ + GDBBreakpointAddRemoveData *s = data; + CPUArchState *env = cpu->env_ptr; + + if (s->ret) { + return; + } + s->ret = cpu_breakpoint_insert(env, s->addr, BP_GDB, NULL); +} + +#ifndef CONFIG_USER_ONLY +static void gdb_watchpoint_insert_one(CPUState *cpu, void *data) +{ + GDBBreakpointAddRemoveData *s = data; + CPUArchState *env = cpu->env_ptr; + + if (s->ret) { + return; + } + s->ret = cpu_watchpoint_insert(env, s->addr, s->len, + xlat_gdb_type[s->type], NULL); +} +#endif + static int gdb_breakpoint_insert(target_ulong addr, target_ulong len, int type) { - CPUArchState *env; - int err = 0; + GDBBreakpointAddRemoveData s = { + .addr = addr, + .len = len, + .type = type, + .ret = 0, + }; if (kvm_enabled()) return kvm_insert_breakpoint(gdbserver_state->c_cpu, addr, len, type); @@ -1955,33 +1991,53 @@ static int gdb_breakpoint_insert(target_ulong addr, target_ulong len, int type) switch (type) { case GDB_BREAKPOINT_SW: case GDB_BREAKPOINT_HW: - for (env = first_cpu; env != NULL; env = env->next_cpu) { - err = cpu_breakpoint_insert(env, addr, BP_GDB, NULL); - if (err) - break; - } - return err; + qemu_for_each_cpu(gdb_breakpoint_insert_one, &s); + return s.ret; #ifndef CONFIG_USER_ONLY case GDB_WATCHPOINT_WRITE: case GDB_WATCHPOINT_READ: case GDB_WATCHPOINT_ACCESS: - for (env = first_cpu; env != NULL; env = env->next_cpu) { - err = cpu_watchpoint_insert(env, addr, len, xlat_gdb_type[type], - NULL); - if (err) - break; - } - return err; + qemu_for_each_cpu(gdb_watchpoint_insert_one, &s); + return s.ret; #endif default: return -ENOSYS; } } +static void gdb_breakpoint_remove_one(CPUState *cpu, void *data) +{ + GDBBreakpointAddRemoveData *s = data; + CPUArchState *env = cpu->env_ptr; + + if (s->ret) { + return; + } + s->ret = cpu_breakpoint_remove(env, s->addr, BP_GDB); +} + +#ifndef CONFIG_USER_ONLY +static void gdb_watchpoint_remove_one(CPUState *cpu, void *data) +{ + GDBBreakpointAddRemoveData *s = data; + CPUArchState *env = cpu->env_ptr; + + if (s->ret) { + return; + } + s->ret = cpu_watchpoint_remove(env, s->addr, s->len, + xlat_gdb_type[s->type]); +} +#endif + static int gdb_breakpoint_remove(target_ulong addr, target_ulong len, int type) { - CPUArchState *env; - int err = 0; + GDBBreakpointAddRemoveData s = { + .addr = addr, + .len = len, + .type = type, + .ret = 0, + }; if (kvm_enabled()) return kvm_remove_breakpoint(gdbserver_state->c_cpu, addr, len, type); @@ -1989,22 +2045,14 @@ static int gdb_breakpoint_remove(target_ulong addr, target_ulong len, int type) switch (type) { case GDB_BREAKPOINT_SW: case GDB_BREAKPOINT_HW: - for (env = first_cpu; env != NULL; env = env->next_cpu) { - err = cpu_breakpoint_remove(env, addr, BP_GDB); - if (err) - break; - } - return err; + qemu_for_each_cpu(gdb_breakpoint_remove_one, &s); + return s.ret; #ifndef CONFIG_USER_ONLY case GDB_WATCHPOINT_WRITE: case GDB_WATCHPOINT_READ: case GDB_WATCHPOINT_ACCESS: - for (env = first_cpu; env != NULL; env = env->next_cpu) { - err = cpu_watchpoint_remove(env, addr, len, xlat_gdb_type[type]); - if (err) - break; - } - return err; + qemu_for_each_cpu(gdb_watchpoint_remove_one, &s); + return s.ret; #endif default: return -ENOSYS;