Skip to contentSkip to conversation

Enable monitor commands in GDB stub

PATCH In review Julian Stecklina 2 participants 2 messages Dec 10, 2008 – Feb 3, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Enable monitor commands in GDB stub

Hello,

I have added support for the qRcmd packet to the GDB stub. This lets you issue "monitor foo" in GDB and have it executed in qemu's monitor.

A quick test suggests that it works fine, but I am quite new to the qemu codebase, so I don't know if calling 'monitor_handle_command' directly from the GDB stub violates any assumptions.

Please keep me CC'd.

Regards,

Signature · 5 lines
Julian Stecklina

Well, take it from an old hand: the only reason it would be easier to
program in C is that you can't easily express complex problems in C,
so you don't. - Erik Naggum (in comp.lang.lisp)
console.h +1 -0
index 6ee40cc..3ae4f86 100644
@@ -192,6 +192,7 @@ extern uint8_t _translate_keycode(const int key);
    does not need to include console.h  */
 /* monitor.c */
 void monitor_init(CharDriverState *hd, int show_banner);
+void monitor_handle_command(const char *cmdline);
 void term_puts(const char *str);
 void term_vprintf(const char *fmt, va_list ap);
 void term_printf(const char *fmt, ...) __attribute__ ((__format__ (__printf__, 1, 2)));
gdbstub.c +11 -1
index 72feac6..a1ad53d 100644
@@ -1290,6 +1290,7 @@ static int gdb_handle_packet(GDBState *s, const char *line_buf)
     char buf[MAX_PACKET_LENGTH];
     uint8_t mem_buf[MAX_PACKET_LENGTH];
     uint8_t *registers;
+    char *monitor_cmd;
     target_ulong addr, len;
 
 #ifdef DEBUG_GDB
@@ -1529,7 +1530,16 @@ static int gdb_handle_packet(GDBState *s, const char *line_buf)
     case 'q':
     case 'Q':
         /* parse any 'q' packets here */
-        if (!strcmp(p,"qemu.sstepbits")) {
+        if (strncmp(p, "Rcmd,", 5) == 0) {
+            p += 5;
+            len = strlen(p) / 2;
+            monitor_cmd = mem_buf;
+            hextomem((uint8_t *)monitor_cmd, p, len);
+            monitor_cmd[len] = 0;
+            monitor_handle_command(monitor_cmd);
+            put_packet(s, "OK");
+            break;
+        } else if (!strcmp(p,"qemu.sstepbits")) {
             /* Query Breakpoint bit definitions */
             snprintf(buf, sizeof(buf), "ENABLE=%x,NOIRQ=%x,NOTIMER=%x",
                      SSTEP_ENABLE,
monitor.c +1 -1
index 0d55433..fc21ae3 100644
@@ -2215,7 +2215,7 @@ static int default_fmt_size = 4;
 
 #define MAX_ARGS 16
 
-static void monitor_handle_command(const char *cmdline)
+void monitor_handle_command(const char *cmdline)
 {
     const char *p, *pstart, *typestr;
     char *q;
#1 lore raw
Quoted 8 lines · Julian Stecklina

Hello,

I have added support for the qRcmd packet to the GDB stub. This lets you issue "monitor foo" in GDB and have it executed in qemu's monitor.

A quick test suggests that it works fine, but I am quite new to the qemu codebase, so I don't know if calling 'monitor_handle_command' directly from the GDB stub violates any assumptions.

Any comments on the patch? I use it since I posted this patch in December without problems.

Regards,

Signature · 5 lines
Julian Stecklina

Well, take it from an old hand: the only reason it would be easier to
program in C is that you can't easily express complex problems in C,
so you don't. - Erik Naggum (in comp.lang.lisp)