qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Anthony Liguori <anthony@codemonkey.ws>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [6718] monitor: Pass-through for gdbstub (Jan Kiszka)
Date: Thu, 05 Mar 2009 23:01:55 +0000	[thread overview]
Message-ID: <E1LfMZf-0002cz-Hc@cvs.savannah.gnu.org> (raw)

Revision: 6718
          http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=6718
Author:   aliguori
Date:     2009-03-05 23:01:55 +0000 (Thu, 05 Mar 2009)
Log Message:
-----------
monitor: Pass-through for gdbstub (Jan Kiszka)

Create a monitor terminal and pass it through the gdbstub. This allows
to use gdb's monitor command to access the QEMU monitor. Works for all
commands except for non-detached migration and password retrieval (user
will receive error messages instead).

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>

Modified Paths:
--------------
    trunk/gdbstub.c

Modified: trunk/gdbstub.c
===================================================================
--- trunk/gdbstub.c	2009-03-05 23:01:51 UTC (rev 6717)
+++ trunk/gdbstub.c	2009-03-05 23:01:55 UTC (rev 6718)
@@ -30,6 +30,7 @@
 
 #include "qemu.h"
 #else
+#include "monitor.h"
 #include "qemu-char.h"
 #include "sysemu.h"
 #include "gdbstub.h"
@@ -285,6 +286,7 @@
     int running_state;
 #else
     CharDriverState *chr;
+    CharDriverState *mon_chr;
 #endif
 } GDBState;
 
@@ -1819,7 +1821,22 @@
             put_packet(s, buf);
             break;
         }
-#endif
+#else /* !CONFIG_LINUX_USER */
+        else if (strncmp(p, "Rcmd,", 5) == 0) {
+            int len = strlen(p + 5);
+
+            if ((len % 2) != 0) {
+                put_packet(s, "E01");
+                break;
+            }
+            hextomem(mem_buf, p + 5, len);
+            len = len / 2;
+            mem_buf[len++] = 0;
+            qemu_chr_read(s->mon_chr, mem_buf, len);
+            put_packet(s, "OK");
+            break;
+        }
+#endif /* !CONFIG_LINUX_USER */
         if (strncmp(p, "Supported", 9) == 0) {
             snprintf(buf, sizeof(buf), "PacketSize=%x", MAX_PACKET_LENGTH);
 #ifdef GDB_CORE_XML
@@ -2282,6 +2299,35 @@
     }
 }
 
+static void gdb_monitor_output(GDBState *s, const char *msg, int len)
+{
+    char buf[MAX_PACKET_LENGTH];
+
+    buf[0] = 'O';
+    if (len > (MAX_PACKET_LENGTH/2) - 1)
+        len = (MAX_PACKET_LENGTH/2) - 1;
+    memtohex(buf + 1, (uint8_t *)msg, len);
+    put_packet(s, buf);
+}
+
+static int gdb_monitor_write(CharDriverState *chr, const uint8_t *buf, int len)
+{
+    const char *p = (const char *)buf;
+    int max_sz;
+
+    max_sz = (sizeof(gdbserver_state->last_packet) - 2) / 2;
+    for (;;) {
+        if (len <= max_sz) {
+            gdb_monitor_output(gdbserver_state, p, len);
+            break;
+        }
+        gdb_monitor_output(gdbserver_state, p, max_sz);
+        p += max_sz;
+        len -= max_sz;
+    }
+    return len;
+}
+
 int gdbserver_start(const char *port)
 {
     GDBState *s;
@@ -2313,6 +2359,12 @@
     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);
+
     return 0;
 }
 #endif

             reply	other threads:[~2009-03-05 23:01 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-03-05 23:01 Anthony Liguori [this message]
2009-03-06  0:35 ` [Qemu-devel] [6718] monitor: Pass-through for gdbstub (Jan Kiszka) Jun Koi
2009-03-06  2:27   ` [Qemu-devel] " Julian Stecklina

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=E1LfMZf-0002cz-Hc@cvs.savannah.gnu.org \
    --to=anthony@codemonkey.ws \
    --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).