From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Lncuq-00051i-19 for qemu-devel@nongnu.org; Sat, 28 Mar 2009 14:05:56 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Lncup-000512-95 for qemu-devel@nongnu.org; Sat, 28 Mar 2009 14:05:55 -0400 Received: from [199.232.76.173] (port=50512 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Lncup-00050p-4U for qemu-devel@nongnu.org; Sat, 28 Mar 2009 14:05:55 -0400 Received: from savannah.gnu.org ([199.232.41.3]:44174 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 1Lncuo-000357-Kk for qemu-devel@nongnu.org; Sat, 28 Mar 2009 14:05:54 -0400 Received: from cvs.savannah.gnu.org ([199.232.41.69]) by sv.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Lncuo-0002mD-3m for qemu-devel@nongnu.org; Sat, 28 Mar 2009 18:05:54 +0000 Received: from aliguori by cvs.savannah.gnu.org with local (Exim 4.69) (envelope-from ) id 1Lncun-0002m9-RP for qemu-devel@nongnu.org; Sat, 28 Mar 2009 18:05:54 +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: Sat, 28 Mar 2009 18:05:53 +0000 Subject: [Qemu-devel] [6913] gdbstub: Allow re-instantiation (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: 6913 http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=6913 Author: aliguori Date: 2009-03-28 18:05:53 +0000 (Sat, 28 Mar 2009) Log Message: ----------- gdbstub: Allow re-instantiation (Jan Kiszka) [ Note: depends on char closing fixes ] Properly clean up the gdbstub when the user tries to re-open it (possibly under a different address). Moreover, allow to shut it down from the monitor via 'gdbserver none'. Signed-off-by: Jan Kiszka Signed-off-by: Anthony Liguori Modified Paths: -------------- trunk/gdbstub.c trunk/monitor.c Modified: trunk/gdbstub.c =================================================================== --- trunk/gdbstub.c 2009-03-28 18:01:29 UTC (rev 6912) +++ trunk/gdbstub.c 2009-03-28 18:05:53 UTC (rev 6913) @@ -265,6 +265,7 @@ } GDBRegisterState; enum RSState { + RS_INACTIVE, RS_IDLE, RS_GETLINE, RS_CHKSUM1, @@ -1924,7 +1925,7 @@ int ret; if (running || (reason != EXCP_DEBUG && reason != EXCP_INTERRUPT) || - s->state == RS_SYSCALL) + s->state == RS_INACTIVE || s->state == RS_SYSCALL) return; /* disable single step if it was enable */ @@ -2342,37 +2343,51 @@ char gdbstub_port_name[128]; int port_num; char *p; - CharDriverState *chr; + CharDriverState *chr = NULL; + CharDriverState *mon_chr; if (!port || !*port) return -1; + if (strcmp(port, "none") != 0) { + port_num = strtol(port, &p, 10); + if (*p == 0) { + /* A numeric value is interpreted as a port number. */ + snprintf(gdbstub_port_name, sizeof(gdbstub_port_name), + "tcp::%d,nowait,nodelay,server", port_num); + port = gdbstub_port_name; + } - port_num = strtol(port, &p, 10); - if (*p == 0) { - /* A numeric value is interpreted as a port number. */ - snprintf(gdbstub_port_name, sizeof(gdbstub_port_name), - "tcp::%d,nowait,nodelay,server", port_num); - port = gdbstub_port_name; + chr = qemu_chr_open("gdb", port, NULL); + if (!chr) + return -1; + + qemu_chr_add_handlers(chr, gdb_chr_can_receive, gdb_chr_receive, + gdb_chr_event, NULL); } - chr = qemu_chr_open("gdb", port, NULL); - if (!chr) - return -1; + s = gdbserver_state; + if (!s) { + s = qemu_mallocz(sizeof(GDBState)); + gdbserver_state = s; - s = qemu_mallocz(sizeof(GDBState)); + qemu_add_vm_change_state_handler(gdb_vm_state_change, NULL); + + /* Initialize a monitor terminal for gdb */ + mon_chr = qemu_mallocz(sizeof(*mon_chr)); + mon_chr->chr_write = gdb_monitor_write; + monitor_init(mon_chr, 0); + } else { + if (s->chr) + qemu_chr_close(s->chr); + mon_chr = s->mon_chr; + memset(s, 0, sizeof(GDBState)); + } s->c_cpu = first_cpu; s->g_cpu = first_cpu; s->chr = chr; - gdbserver_state = s; - qemu_chr_add_handlers(chr, gdb_chr_can_receive, gdb_chr_receive, - gdb_chr_event, NULL); - qemu_add_vm_change_state_handler(gdb_vm_state_change, NULL); + s->state = chr ? RS_IDLE : RS_INACTIVE; + s->mon_chr = mon_chr; - /* Initialize a monitor terminal for gdb */ - s->mon_chr = qemu_mallocz(sizeof(*s->mon_chr)); - s->mon_chr->chr_write = gdb_monitor_write; - monitor_init(s->mon_chr, 0); - return 0; } #endif Modified: trunk/monitor.c =================================================================== --- trunk/monitor.c 2009-03-28 18:01:29 UTC (rev 6912) +++ trunk/monitor.c 2009-03-28 18:05:53 UTC (rev 6913) @@ -577,6 +577,8 @@ if (gdbserver_start(port) < 0) { monitor_printf(mon, "Could not open gdbserver socket on port '%s'\n", port); + } else if (strcmp(port, "none") == 0) { + monitor_printf(mon, "Disabled gdbserver\n"); } else { monitor_printf(mon, "Waiting gdb connection on port '%s'\n", port); }