From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LNs5Z-0003gg-5y for qemu-devel@nongnu.org; Fri, 16 Jan 2009 12:02:33 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LNs5X-0003g6-KD for qemu-devel@nongnu.org; Fri, 16 Jan 2009 12:02:32 -0500 Received: from [199.232.76.173] (port=47874 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LNs5X-0003g0-9N for qemu-devel@nongnu.org; Fri, 16 Jan 2009 12:02:31 -0500 Received: from lizzard.sbs.de ([194.138.37.39]:16845) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1LNs5W-0007bD-EL for qemu-devel@nongnu.org; Fri, 16 Jan 2009 12:02:30 -0500 Received: from mail2.sbs.de (localhost [127.0.0.1]) by lizzard.sbs.de (8.12.11.20060308/8.12.11) with ESMTP id n0GH2Sbq002281 for ; Fri, 16 Jan 2009 18:02:28 +0100 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 n0GH2S3O029175 for ; Fri, 16 Jan 2009 18:02:28 +0100 Message-ID: <4970BDA6.8080209@siemens.com> Date: Fri, 16 Jan 2009 18:02:30 +0100 From: Jan Kiszka MIME-Version: 1.0 References: <20090115103733.GA11299@redhat.com> <496FA08E.4060806@codemonkey.ws> <20090116071437.GB27165@redhat.com> <4970A715.7020009@codemonkey.ws> <4970B4A1.3000106@siemens.com> <4970B582.7040009@codemonkey.ws> <4970B78B.8070900@siemens.com> <4970B9B9.1030101@siemens.com> In-Reply-To: <4970B9B9.1030101@siemens.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: [Qemu-devel] Re: [PATCH] optionally specify vm stop message 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 Jan Kiszka wrote: > Jan Kiszka wrote: >> Anthony Liguori wrote: >>> Jan Kiszka wrote: >>>> Anthony Liguori wrote: >>>> >>>>>> Also non zero reasons a handled differently by vm_stop. Don't know >>>>>> why. >>>>>> >>>>> It's an ugly hack for gdbstub. It notifies gdb when a breakpoint >>>>> occurs. We have far too many state tracking mechanisms. Anyway, gdb >>>>> can pass something like VM_STOP_BP and that can be used to trigger the >>>>> callback. >>>>> >>>> It's not only used for breakpoints but any stop condition that should be >>>> reported to the gdb frontend (so far: EXCP_DEBUG and EXCP_INTERRUPT). >>>> Not sure, though, how to deal with ENOSPC - it's not a guest fault, it's >>>> a host problem. From that POV, gdb should not receive it. >>>> >>> We already have a vm_change_state_handler that is invoked whenever a >>> guest starts running or stops running. gdb should be able to use that >>> and look at env->exception_index, no? >> I don't think env->exception_index is set when you issue "stop" from the >> monitor, e.g. Moreover, that would be an ugly (out-of-band) API as well. >> > > The point is that vm_stop can be issued from any context, not just from > a vcpu. So there may be no env channel at this point. But we could enhance the state-change callback interface.... WARNING, untested quick-hack to overcome vm_stop_cb follows! Jan --------> diff --git a/audio/audio.c b/audio/audio.c index 762c2e3..e2635c0 100644 --- a/audio/audio.c +++ b/audio/audio.c @@ -1622,7 +1622,8 @@ static int audio_driver_init (AudioState *s, struct audio_driver *drv) } } -static void audio_vm_change_state_handler (void *opaque, int running) +static void audio_vm_change_state_handler (void *opaque, int running, + int reason) { AudioState *s = opaque; HWVoiceOut *hwo = NULL; diff --git a/gdbstub.c b/gdbstub.c index 6db6d22..984acbd 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -1991,7 +1991,7 @@ void gdb_set_stop_cpu(CPUState *env) } #ifndef CONFIG_USER_ONLY -static void gdb_vm_stopped(void *opaque, int reason) +static void gdb_vm_state_change(void *opaque, int running, int reason) { GDBState *s = gdbserver_state; CPUState *env = s->c_cpu; @@ -1999,7 +1999,8 @@ static void gdb_vm_stopped(void *opaque, int reason) const char *type; int ret; - if (s->state == RS_SYSCALL) + if (running || (reason != EXCP_DEBUG && reason != EXCP_INTERRUPT) || + s->state == RS_SYSCALL) return; /* disable single step if it was enable */ @@ -2028,10 +2029,8 @@ static void gdb_vm_stopped(void *opaque, int reason) } tb_flush(env); ret = GDB_SIGNAL_TRAP; - } else if (reason == EXCP_INTERRUPT) { - ret = GDB_SIGNAL_INT; } else { - ret = 0; + ret = GDB_SIGNAL_INT; } snprintf(buf, sizeof(buf), "T%02xthread:%02x;", ret, env->cpu_index+1); put_packet(s, buf); @@ -2424,7 +2423,7 @@ int gdbserver_start(const char *port) gdbserver_state = s; qemu_chr_add_handlers(chr, gdb_chr_can_receive, gdb_chr_receive, gdb_chr_event, NULL); - qemu_add_vm_stop_handler(gdb_vm_stopped, NULL); + qemu_add_vm_change_state_handler(gdb_vm_state_change, NULL); return 0; } #endif diff --git a/sysemu.h b/sysemu.h index 55f8d79..d8df642 100644 --- a/sysemu.h +++ b/sysemu.h @@ -12,16 +12,12 @@ extern uint8_t qemu_uuid[]; #define UUID_FMT "%02hhx%02hhx%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx" typedef struct vm_change_state_entry VMChangeStateEntry; -typedef void VMChangeStateHandler(void *opaque, int running); -typedef void VMStopHandler(void *opaque, int reason); +typedef void VMChangeStateHandler(void *opaque, int running, int reason); VMChangeStateEntry *qemu_add_vm_change_state_handler(VMChangeStateHandler *cb, void *opaque); void qemu_del_vm_change_state_handler(VMChangeStateEntry *e); -int qemu_add_vm_stop_handler(VMStopHandler *cb, void *opaque); -void qemu_del_vm_stop_handler(VMStopHandler *cb, void *opaque); - void vm_start(void); void vm_stop(int reason); diff --git a/vl.c b/vl.c index be6819d..5192303 100644 --- a/vl.c +++ b/vl.c @@ -3404,37 +3404,21 @@ void qemu_del_vm_change_state_handler(VMChangeStateEntry *e) qemu_free (e); } -static void vm_state_notify(int running) +static void vm_state_notify(int running, int reason) { VMChangeStateEntry *e; for (e = vm_change_state_head.lh_first; e; e = e->entries.le_next) { - e->cb(e->opaque, running); + e->cb(e->opaque, running, reason); } } -/* XXX: support several handlers */ -static VMStopHandler *vm_stop_cb; -static void *vm_stop_opaque; - -int qemu_add_vm_stop_handler(VMStopHandler *cb, void *opaque) -{ - vm_stop_cb = cb; - vm_stop_opaque = opaque; - return 0; -} - -void qemu_del_vm_stop_handler(VMStopHandler *cb, void *opaque) -{ - vm_stop_cb = NULL; -} - void vm_start(void) { if (!vm_running) { cpu_enable_ticks(); vm_running = 1; - vm_state_notify(1); + vm_state_notify(1, 0); qemu_rearm_alarm_timer(alarm_timer); } } @@ -3444,12 +3428,7 @@ void vm_stop(int reason) if (vm_running) { cpu_disable_ticks(); vm_running = 0; - if (reason != 0) { - if (vm_stop_cb) { - vm_stop_cb(vm_stop_opaque, reason); - } - } - vm_state_notify(0); + vm_state_notify(0, reason); } } -- Siemens AG, Corporate Technology, CT SE 26 Corporate Competence Center Embedded Linux