qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Jan Kiszka <jan.kiszka@siemens.com>
To: qemu-devel <qemu-devel@nongnu.org>
Subject: [Qemu-devel] [PATCH 1/2] gdbstub: Allow re-instantiation
Date: Wed, 18 Mar 2009 12:10:10 +0100	[thread overview]
Message-ID: <49C0D692.6030106@siemens.com> (raw)

[ 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 <jan.kiszka@siemens.com>
---

 gdbstub.c |   57 ++++++++++++++++++++++++++++++++++++---------------------
 monitor.c |    2 ++
 2 files changed, 38 insertions(+), 21 deletions(-)

diff --git a/gdbstub.c b/gdbstub.c
index 935d864..e8ceaae 100644
--- a/gdbstub.c
+++ b/gdbstub.c
@@ -265,6 +265,7 @@ typedef struct GDBRegisterState {
 } GDBRegisterState;
 
 enum RSState {
+    RS_INACTIVE,
     RS_IDLE,
     RS_GETLINE,
     RS_CHKSUM1,
@@ -1982,7 +1983,7 @@ static void gdb_vm_state_change(void *opaque, int running, int reason)
     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 */
@@ -2400,36 +2401,50 @@ int gdbserver_start(const char *port)
     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);
-
-    /* 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);
+    s->state = chr ? RS_IDLE : RS_INACTIVE;
+    s->mon_chr = mon_chr;
 
     return 0;
 }
diff --git a/monitor.c b/monitor.c
index da106d8..c6fe968 100644
--- a/monitor.c
+++ b/monitor.c
@@ -577,6 +577,8 @@ static void do_gdbserver(Monitor *mon, const char *port)
     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);
     }

             reply	other threads:[~2009-03-18 11:10 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-03-18 11:10 Jan Kiszka [this message]
2009-03-28 18:06 ` [Qemu-devel] [PATCH 1/2] gdbstub: Allow re-instantiation Anthony Liguori

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=49C0D692.6030106@siemens.com \
    --to=jan.kiszka@siemens.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).