]> git.proxmox.com Git - qemu.git/commitdiff
Allow gdbstub to connect over any serial device.
authorpbrook <pbrook@c046a42c-6fe2-441c-8c8c-71466251a162>
Thu, 22 Feb 2007 01:48:01 +0000 (01:48 +0000)
committerpbrook <pbrook@c046a42c-6fe2-441c-8c8c-71466251a162>
Thu, 22 Feb 2007 01:48:01 +0000 (01:48 +0000)
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@2448 c046a42c-6fe2-441c-8c8c-71466251a162

gdbstub.c
gdbstub.h
monitor.c
vl.c

index aeddc34745419ff3c482abbcf0443a7c94ab9ad3..324af4d194e7ba4dbaf37373531cdc3814b129ce 100644 (file)
--- a/gdbstub.c
+++ b/gdbstub.c
@@ -1216,10 +1216,26 @@ static void gdb_chr_event(void *opaque, int event)
     }
 }
 
-int gdbserver_start(CharDriverState *chr)
+int gdbserver_start(const char *port)
 {
     GDBState *s;
+    char gdbstub_port_name[128];
+    int port_num;
+    char *p;
+    CharDriverState *chr;
+
+    if (!port || !*port)
+      return -1;
 
+    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(port);
     if (!chr)
         return -1;
 
@@ -1234,18 +1250,4 @@ int gdbserver_start(CharDriverState *chr)
     qemu_add_vm_stop_handler(gdb_vm_stopped, s);
     return 0;
 }
-
-int gdbserver_start_port(int port)
-{
-    CharDriverState *chr;
-    char gdbstub_port_name[128];
-
-    snprintf(gdbstub_port_name, sizeof(gdbstub_port_name),
-             "tcp::%d,nowait,nodelay,server", port);
-    chr = qemu_chr_open(gdbstub_port_name);
-    if (!chr) 
-        return -EIO;
-    return gdbserver_start(chr);
-}
-
 #endif
index 41ffc6d089e1edcb9cfc6641d20cf2b82ef57cd1..e1c9efb80349ddf4c8112657dcacb6f25b570e7e 100644 (file)
--- a/gdbstub.h
+++ b/gdbstub.h
@@ -1,7 +1,7 @@
 #ifndef GDBSTUB_H
 #define GDBSTUB_H
 
-#define DEFAULT_GDBSTUB_PORT 1234
+#define DEFAULT_GDBSTUB_PORT "1234"
 
 typedef void (*gdb_syscall_complete_cb)(CPUState *env,
                                         target_ulong ret, target_ulong err);
@@ -13,8 +13,7 @@ int gdb_handlesig (CPUState *, int);
 void gdb_exit(CPUState *, int);
 int gdbserver_start(int);
 #else
-int gdbserver_start(CharDriverState *chr);
-int gdbserver_start_port(int port);
+int gdbserver_start(const char *port);
 #endif
 
 #endif
index cd0663e937af30f99f28654304fec56a3f4f00c5..43ebe01f3efcd97c18cda113ad894817b6dde427 100644 (file)
--- a/monitor.c
+++ b/monitor.c
@@ -423,14 +423,14 @@ static void do_cont(void)
 }
 
 #ifdef CONFIG_GDBSTUB
-static void do_gdbserver(int has_port, int port)
+static void do_gdbserver(const char *port)
 {
-    if (!has_port)
+    if (!port)
         port = DEFAULT_GDBSTUB_PORT;
-    if (gdbserver_start_port(port) < 0) {
-        qemu_printf("Could not open gdbserver socket on port %d\n", port);
+    if (gdbserver_start(port) < 0) {
+        qemu_printf("Could not open gdbserver socket on port '%s'\n", port);
     } else {
-        qemu_printf("Waiting gdb connection on port %d\n", port);
+        qemu_printf("Waiting gdb connection on port '%s'\n", port);
     }
 }
 #endif
@@ -1216,7 +1216,7 @@ static term_cmd_t term_cmds[] = {
     { "c|cont", "", do_cont, 
       "", "resume emulation", },
 #ifdef CONFIG_GDBSTUB
-    { "gdbserver", "i?", do_gdbserver, 
+    { "gdbserver", "s?", do_gdbserver, 
       "[port]", "start gdbserver session (default port=1234)", },
 #endif
     { "x", "/l", do_memory_dump, 
diff --git a/vl.c b/vl.c
index 5bbbf40a1e0e21f243850e080b5b0d8b4061d152..efa0d617233cf6c97a71aec21010374d375c5665 100644 (file)
--- a/vl.c
+++ b/vl.c
@@ -6422,8 +6422,8 @@ void help(void)
            "-parallel dev   redirect the parallel port to char device 'dev'\n"
            "-pidfile file   Write PID to 'file'\n"
            "-S              freeze CPU at startup (use 'c' to start execution)\n"
-           "-s              wait gdb connection to port %d\n"
-           "-p port         change gdb connection port\n"
+           "-s              wait gdb connection to port\n"
+           "-p port         set gdb connection port [default=%s]\n"
            "-d item1,...    output log to %s (use -d ? for a list of log items)\n"
            "-hdachs c,h,s[,t]  force hard disk 0 physical geometry and the optional BIOS\n"
            "                translation (t=none or lba) (usually qemu can guess them)\n"
@@ -6829,7 +6829,8 @@ static BOOL WINAPI qemu_ctrl_handler(DWORD type)
 int main(int argc, char **argv)
 {
 #ifdef CONFIG_GDBSTUB
-    int use_gdbstub, gdbstub_port;
+    int use_gdbstub;
+    const char *gdbstub_port;
 #endif
     int i, cdrom_index;
     int snapshot, linux_boot;
@@ -7143,7 +7144,7 @@ int main(int argc, char **argv)
                 use_gdbstub = 1;
                 break;
             case QEMU_OPTION_p:
-                gdbstub_port = atoi(optarg);
+                gdbstub_port = optarg;
                 break;
 #endif
             case QEMU_OPTION_L:
@@ -7571,8 +7572,8 @@ int main(int argc, char **argv)
     if (use_gdbstub) {
         /* XXX: use standard host:port notation and modify options
            accordingly. */
-        if (gdbserver_start_port(gdbstub_port) < 0) {
-            fprintf(stderr, "qemu: could not open gdbstub device on port '%d'\n",
+        if (gdbserver_start(gdbstub_port) < 0) {
+            fprintf(stderr, "qemu: could not open gdbstub device on port '%s'\n",
                     gdbstub_port);
             exit(1);
         }