qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] gdbstub user mode : local/unix socket (cf remote pipe connexion addition)
@ 2009-04-02 13:53 Philippe Waille
  2009-04-03  9:31 ` [Qemu-devel] " Philippe Waille
  0 siblings, 1 reply; 3+ messages in thread
From: Philippe Waille @ 2009-04-02 13:53 UTC (permalink / raw)
  To: qemu-devel

[-- Attachment #1: Type: text/plain, Size: 7519 bytes --]

Hi

  I failed to add stdio remote pipe connection method to the linux-user gdbstub
mode. But adding local/unix sockets instead solves the main part of my 
problem.

GDB options :
-g trcp_portnumber (deprecated, for compatibility)
-gdb tcp::portnumber
-gdb local::portname


  Local/unix sockets allow for instance 

  > qemu-arm -gdb /tmp/my_private_socket_name  executable_file
  gdb>  target remote | socat stdio unix-connect:/tmp/my_private_socket_name

Files modified : gdbstub.c gdbstub.h linux-user/main.c  (tar file attached)

Diff from latest stable release (patch "Rework configuration via
command line not applied).

Best regards
Ph. Waille

--- qemu-0.10.1_modifie/gdbstub.c	2009-04-02 13:04:08.000000000 +0200
+++ qemu-0.10.1_orig/gdbstub.c	2009-03-22 00:05:48.000000000 +0100
@@ -27,7 +27,6 @@
 #include <errno.h>
 #include <unistd.h>
 #include <fcntl.h>
-#include <sys/socket.h>
 
 #include "qemu.h"
 #else
@@ -304,7 +303,6 @@
 #ifdef CONFIG_USER_ONLY
 /* XXX: This is not thread safe.  Do we care?  */
 static int gdbserver_fd = -1;
-static int gdbserver_family;
 
 static int get_char(GDBState *s)
 {
@@ -2171,23 +2169,13 @@
 static void gdb_accept(void)
 {
     GDBState *s;
-    struct sockaddr_in addr_in;
-    struct sockaddr_un addr_un;
-    struct sockaddr *addr;
+    struct sockaddr_in sockaddr;
     socklen_t len;
     int val, fd;
 
-    switch (gdbserver_family)
-      {
-      case  AF_LOCAL : 
-         addr = (struct sockaddr *) &addr_un; len = sizeof(addr_un); break;
-
-      default : /* AF_INET by default */ 
-          addr = (struct sockaddr *) &addr_in; len = sizeof(addr_in); break;
-      } 
-
     for(;;) {
-        fd = accept(gdbserver_fd, addr, &len);
+        len = sizeof(sockaddr);
+        fd = accept(gdbserver_fd, (struct sockaddr *)&sockaddr, &len);
         if (fd < 0 && errno != EINTR) {
             perror("accept");
             return;
@@ -2196,12 +2184,9 @@
         }
     }
 
-    if (gdbserver_family == AF_INET)
-      {
-      /* set short latency */
-      val = 1;
-      setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (char *)&val, sizeof(val));
-      }
+    /* set short latency */
+    val = 1;
+    setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (char *)&val, sizeof(val));
 
     s = qemu_mallocz(sizeof(GDBState));
 
@@ -2216,59 +2201,29 @@
     fcntl(fd, F_SETFL, O_NONBLOCK);
 }
 
-static int string_start_with (char **name, const char *prefix)
-    {
-    int res = 0;
-    if ((strlen(*name) > strlen(prefix)) && 
-        !strncmp (*name, prefix,strlen(prefix)))
-      {*name += strlen(prefix); res=1;}
-    return res;
-    }
-
-static int gdbserver_open(char *portname)
+static int gdbserver_open(int port)
 {
-  /*  local::port_filename or tcp::port_number or port_number */
+    struct sockaddr_in sockaddr;
+    int fd, val, ret;
 
-    struct sockaddr_in sockaddr_in;
-    struct sockaddr_un sockaddr_un;
-    int pnum,ret,val, fd;
-
-    sockaddr_in.sin_family = AF_INET;
-    sockaddr_in.sin_addr.s_addr = 0;
-    sockaddr_un.sun_family = AF_LOCAL;
-   
-    gdbserver_family=0;
-    ret = -1; 
+    fd = socket(PF_INET, SOCK_STREAM, 0);
+    if (fd < 0) {
+        perror("socket");
+        return -1;
+    }
 
-    if (string_start_with (&portname,"local::"))
-        {
-        gdbserver_family = AF_LOCAL;
-        strcpy (sockaddr_un.sun_path,portname);
-        fd = socket(gdbserver_family, SOCK_STREAM, 0);
-        if  (fd < 0)         { perror("socket"); return -1;}
-        ret = bind(fd, &sockaddr_un, sizeof(sockaddr_un));
-        }
-    else
-        {
-        gdbserver_family = AF_INET;
-        /* remove optinal tcp:: prefix */
-        val = string_start_with (&portname,"tcp::");
-        /* portname should be a valid port number */
-        if (sscanf (portname,"%d", &pnum) ==1)
-           {
-           fd = socket(gdbserver_family, SOCK_STREAM, 0);
-           if  (fd < 0)         { perror("socket"); return -1;}
-           setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, 
-                      (char *) "1", 1);
-           sockaddr_in.sin_port = htons(pnum);
-           ret = bind(fd, &sockaddr_in, sizeof(sockaddr_in));
-           } 
-        }
-     
+    /* allow fast reuse */
+    val = 1;
+    setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char *)&val, sizeof(val));
+
+    sockaddr.sin_family = AF_INET;
+    sockaddr.sin_port = htons(port);
+    sockaddr.sin_addr.s_addr = 0;
+    ret = bind(fd, (struct sockaddr *)&sockaddr, sizeof(sockaddr));
     if (ret < 0) {
         perror("bind");
         return -1;
-      }
+    }
     ret = listen(fd, 0);
     if (ret < 0) {
         perror("listen");
@@ -2277,12 +2232,9 @@
     return fd;
 }
 
-int gdbserver_start(char *portname)
+int gdbserver_start(int port)
 {
-    if (!portname || !*portname)
-      return -1;
-
-    gdbserver_fd = gdbserver_open(portname);
+    gdbserver_fd = gdbserver_open(port);
     if (gdbserver_fd < 0)
         return -1;
     /* accept connections */





--- qemu-0.10.1_modifie/gdbstub.h	2009-03-30 15:09:04.000000000 +0200
+++ qemu-0.10.1_orig/gdbstub.h	2009-03-22 00:05:48.000000000 +0100
@@ -14,7 +14,7 @@
 int gdb_handlesig (CPUState *, int);
 void gdb_exit(CPUState *, int);
 void gdb_signalled(CPUState *, int);
-int gdbserver_start(char *);
+int gdbserver_start(int);
 void gdbserver_fork(CPUState *);
 #else
 int gdbserver_start(const char *port);






--- qemu-0.10.1_modifie/linux-user/main.c	2009-04-02 13:43:03.000000000 +0200
+++ qemu-0.10.1_orig/linux-user/main.c	2009-03-22 00:05:42.000000000 +0100
@@ -2186,9 +2186,7 @@
            "\n"
            "Standard options:\n"
            "-h                print this help\n"
-           "-g port           (deprecated : use -gdb tcp::port)\n"
-           "-gdb tcp::port    wait gdb connection to TCP socket port\n"
-           "-gdb local::name  wait gdb connection to local (unix) socket name\n"
+           "-g port           wait gdb connection to port\n"
            "-L path           set the elf interpreter prefix (default=%s)\n"
            "-s size           set the stack size in bytes (default=%ld)\n"
            "-cpu model        select CPU (-cpu ? for list)\n"
@@ -2243,7 +2241,7 @@
     CPUState *env;
     int optind;
     const char *r;
-    char *gdbstub_portname = NULL;
+    int gdbstub_port = 0;
     char **target_environ, **wrk;
     envlist_t *envlist = NULL;
 
@@ -2324,10 +2322,10 @@
                 fprintf(stderr, "page size must be a power of two\n");
                 exit(1);
             }
-        } else if (!strcmp(r, "gdb") || !strcmp(r, "g")) {
+        } else if (!strcmp(r, "g")) {
             if (optind >= argc)
                 break;
-            gdbstub_portname = argv[optind++];
+            gdbstub_port = atoi(argv[optind++]);
 	} else if (!strcmp(r, "r")) {
 	    qemu_uname_release = argv[optind++];
         } else if (!strcmp(r, "cpu")) {
@@ -2683,8 +2681,8 @@
     ts->heap_limit = 0;
 #endif
 
-    if (gdbstub_portname != NULL) {
-        gdbserver_start (gdbstub_portname);
+    if (gdbstub_port) {
+        gdbserver_start (gdbstub_port);
         gdb_handlesig(env, 0);
     }
     cpu_loop(env);
-- 
-----------------------------------------------------------------------------
Philippe WAILLE                            email :    Philippe.Waille@imag.fr
IMAG ID (Informatique et distribution)       Tel :    04 76 61 20 13
ENSIMAG - antenne de Montbonnot          Foreign :  33 4 76 61 20 13
INOVALLEE					     Fax :    04 76 61 20 99
51, avenue Jean Kuntzmann
38330 MONTBONNOT SAINT MARTIN


[-- Attachment #2: modified.tar --]
[-- Type: application/x-tar, Size: 158687 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Qemu-devel] Re: gdbstub user mode : local/unix socket (cf remote pipe connexion addition)
  2009-04-02 13:53 [Qemu-devel] gdbstub user mode : local/unix socket (cf remote pipe connexion addition) Philippe Waille
@ 2009-04-03  9:31 ` Philippe Waille
  2009-04-03 16:35   ` Jan Kiszka
  0 siblings, 1 reply; 3+ messages in thread
From: Philippe Waille @ 2009-04-03  9:31 UTC (permalink / raw)
  To: Philippe Waille

[-- Attachment #1: Type: text/plain, Size: 7436 bytes --]

On Thu, Apr 02, 2009 at 03:53:12PM +0200, Philippe Waille wrote:

I suggest this patch :

allow unix-domain socket gdb connection in user-mode gdbstub
(updated version : fix socket address reuse error in my previous patch)

-------------------------------------------------------------------------
diff -u -r qemu-0.10.1_modified/gdbstub.c qemu-0.10.1_orig/gdbstub.c
--- qemu-0.10.1_modified/gdbstub.c	2009-04-03 10:16:11.000000000 +0200
+++ qemu-0.10.1_orig/gdbstub.c	2009-03-22 00:05:48.000000000 +0100
@@ -27,7 +27,6 @@
 #include <errno.h>
 #include <unistd.h>
 #include <fcntl.h>
-#include <sys/socket.h>
 
 #include "qemu.h"
 #else
@@ -304,7 +303,6 @@
 #ifdef CONFIG_USER_ONLY
 /* XXX: This is not thread safe.  Do we care?  */
 static int gdbserver_fd = -1;
-static int gdbserver_family;
 
 static int get_char(GDBState *s)
 {
@@ -2171,23 +2169,13 @@
 static void gdb_accept(void)
 {
     GDBState *s;
-    struct sockaddr_in addr_in;
-    struct sockaddr_un addr_un;
-    struct sockaddr *addr;
+    struct sockaddr_in sockaddr;
     socklen_t len;
-    int fd;
-
-    switch (gdbserver_family)
-      {
-      case  AF_LOCAL : 
-         addr = (struct sockaddr *) &addr_un; len = sizeof(addr_un); break;
-
-      default : /* AF_INET by default */ 
-          addr = (struct sockaddr *) &addr_in; len = sizeof(addr_in); break;
-      } 
+    int val, fd;
 
     for(;;) {
-        fd = accept(gdbserver_fd, addr, &len);
+        len = sizeof(sockaddr);
+        fd = accept(gdbserver_fd, (struct sockaddr *)&sockaddr, &len);
         if (fd < 0 && errno != EINTR) {
             perror("accept");
             return;
@@ -2196,6 +2184,10 @@
         }
     }
 
+    /* set short latency */
+    val = 1;
+    setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (char *)&val, sizeof(val));
+
     s = qemu_mallocz(sizeof(GDBState));
 
     memset (s, 0, sizeof (GDBState));
@@ -2209,63 +2201,29 @@
     fcntl(fd, F_SETFL, O_NONBLOCK);
 }
 
-static int string_start_with (char **name, const char *prefix)
-    {
-    int res = 0;
-    if ((strlen(*name) > strlen(prefix)) && 
-        !strncmp (*name, prefix,strlen(prefix)))
-      {*name += strlen(prefix); res=1;}
-    return res;
-    }
-
-static int gdbserver_open(char *portname)
+static int gdbserver_open(int port)
 {
-  /*  local::port_filename or tcp::port_number or port_number */
-
-    struct sockaddr_in sockaddr_in;
-    struct sockaddr_un sockaddr_un;
-    int pnum,ret,val, fd;
+    struct sockaddr_in sockaddr;
+    int fd, val, ret;
 
-    sockaddr_in.sin_family = AF_INET;
-    sockaddr_in.sin_addr.s_addr = 0;
-    sockaddr_un.sun_family = AF_LOCAL;
-   
-    gdbserver_family=0;
-    ret = -1; 
+    fd = socket(PF_INET, SOCK_STREAM, 0);
+    if (fd < 0) {
+        perror("socket");
+        return -1;
+    }
 
-    if (string_start_with (&portname,"local::"))
-        {
-        gdbserver_family = AF_LOCAL;
-        strcpy (sockaddr_un.sun_path,portname);
-        fd = socket(gdbserver_family, SOCK_STREAM, 0);
-        if  (fd < 0)         { perror("socket"); return -1;}
-        val = 1;
-        setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, 
-                      &val, sizeof(val));
-        ret = bind(fd, &sockaddr_un, sizeof(sockaddr_un));
-        }
-    else
-        {
-        gdbserver_family = AF_INET;
-        /* remove optinal tcp:: prefix */
-        val = string_start_with (&portname,"tcp::");
-        /* portname should be a valid port number */
-        if (sscanf (portname,"%d", &pnum) ==1)
-           {
-           sockaddr_in.sin_port = htons(pnum);
-           fd = socket(gdbserver_family, SOCK_STREAM, 0);
-           if  (fd < 0)         { perror("socket"); return -1;}
-           val = 1;
-           setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, 
-                      &val, sizeof(val));
-           ret = bind(fd, &sockaddr_in, sizeof(sockaddr_in));
-           } 
-        }
-     
+    /* allow fast reuse */
+    val = 1;
+    setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char *)&val, sizeof(val));
+
+    sockaddr.sin_family = AF_INET;
+    sockaddr.sin_port = htons(port);
+    sockaddr.sin_addr.s_addr = 0;
+    ret = bind(fd, (struct sockaddr *)&sockaddr, sizeof(sockaddr));
     if (ret < 0) {
         perror("bind");
         return -1;
-      }
+    }
     ret = listen(fd, 0);
     if (ret < 0) {
         perror("listen");
@@ -2274,12 +2232,9 @@
     return fd;
 }
 
-int gdbserver_start(char *portname)
+int gdbserver_start(int port)
 {
-    if (!portname || !*portname)
-      return -1;
-
-    gdbserver_fd = gdbserver_open(portname);
+    gdbserver_fd = gdbserver_open(port);
     if (gdbserver_fd < 0)
         return -1;
     /* accept connections */
diff -u -r qemu-0.10.1_modified/gdbstub.h qemu-0.10.1_orig/gdbstub.h
--- qemu-0.10.1_modified/gdbstub.h	2009-04-02 20:13:52.000000000 +0200
+++ qemu-0.10.1_orig/gdbstub.h	2009-04-02 19:48:49.000000000 +0200
@@ -14,7 +14,7 @@
 int gdb_handlesig (CPUState *, int);
 void gdb_exit(CPUState *, int);
 void gdb_signalled(CPUState *, int);
-int gdbserver_start(char *);
+int gdbserver_start(int);
 void gdbserver_fork(CPUState *);
 #else
 int gdbserver_start(const char *port);
Seulement dans qemu-0.10.1_modified: gdbstub_orig.c
diff -u -r qemu-0.10.1_modified/linux-user/main.c qemu-0.10.1_orig/linux-user/main.c
--- qemu-0.10.1_modified/linux-user/main.c	2009-04-02 13:43:03.000000000 +0200
+++ qemu-0.10.1_orig/linux-user/main.c	2009-03-22 00:05:42.000000000 +0100
@@ -2186,9 +2186,7 @@
            "\n"
            "Standard options:\n"
            "-h                print this help\n"
-           "-g port           (deprecated : use -gdb tcp::port)\n"
-           "-gdb tcp::port    wait gdb connection to TCP socket port\n"
-           "-gdb local::name  wait gdb connection to local (unix) socket name\n"
+           "-g port           wait gdb connection to port\n"
            "-L path           set the elf interpreter prefix (default=%s)\n"
            "-s size           set the stack size in bytes (default=%ld)\n"
            "-cpu model        select CPU (-cpu ? for list)\n"
@@ -2243,7 +2241,7 @@
     CPUState *env;
     int optind;
     const char *r;
-    char *gdbstub_portname = NULL;
+    int gdbstub_port = 0;
     char **target_environ, **wrk;
     envlist_t *envlist = NULL;
 
@@ -2324,10 +2322,10 @@
                 fprintf(stderr, "page size must be a power of two\n");
                 exit(1);
             }
-        } else if (!strcmp(r, "gdb") || !strcmp(r, "g")) {
+        } else if (!strcmp(r, "g")) {
             if (optind >= argc)
                 break;
-            gdbstub_portname = argv[optind++];
+            gdbstub_port = atoi(argv[optind++]);
 	} else if (!strcmp(r, "r")) {
 	    qemu_uname_release = argv[optind++];
         } else if (!strcmp(r, "cpu")) {
@@ -2683,8 +2681,8 @@
     ts->heap_limit = 0;
 #endif
 
-    if (gdbstub_portname != NULL) {
-        gdbserver_start (gdbstub_portname);
+    if (gdbstub_port) {
+        gdbserver_start (gdbstub_port);
         gdb_handlesig(env, 0);
     }
     cpu_loop(env);

-----------------------------------------------------------------------------
Philippe WAILLE                            email :    Philippe.Waille@imag.fr
IMAG ID (Informatique et distribution)       Tel :    04 76 61 20 13
ENSIMAG - antenne de Montbonnot          Foreign :  33 4 76 61 20 13
INOVALLEE					     Fax :    04 76 61 20 99
51, avenue Jean Kuntzmann
38330 MONTBONNOT SAINT MARTIN


[-- Attachment #2: files.tar --]
[-- Type: application/x-tar, Size: 169138 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Qemu-devel] Re: gdbstub user mode : local/unix socket (cf remote pipe connexion addition)
  2009-04-03  9:31 ` [Qemu-devel] " Philippe Waille
@ 2009-04-03 16:35   ` Jan Kiszka
  0 siblings, 0 replies; 3+ messages in thread
From: Jan Kiszka @ 2009-04-03 16:35 UTC (permalink / raw)
  To: qemu-devel; +Cc: Philippe Waille

Philippe Waille wrote:
> On Thu, Apr 02, 2009 at 03:53:12PM +0200, Philippe Waille wrote:
> 
> I suggest this patch :
> 
> allow unix-domain socket gdb connection in user-mode gdbstub
> (updated version : fix socket address reuse error in my previous patch)

For unknown reasons my comments on the first version didn't made it to the list. Find them below, I think they still apply.

Jan

----------

Philippe Waille wrote:
> Hi
> 
>   I failed to add stdio remote pipe connection method to the linux-user gdbstub
> mode. But adding local/unix sockets instead solves the main part of my 
> problem.

Great. Thanks for working on this!

> 
> GDB options :
> -g trcp_portnumber (deprecated, for compatibility)

IMHO we should rather drop with a hard cut this instead of keeping
(potentially) confusing legacy around.

> -gdb tcp::portnumber
> -gdb local::portname

Why not using the standard syntax from the system emulation instead
inventing a new one? Even if you do not support all variations of
qemu-char, at least the corresponding ones should be compatible.

> 
> 
>   Local/unix sockets allow for instance 
> 
>   > qemu-arm -gdb /tmp/my_private_socket_name  executable_file
>   gdb>  target remote | socat stdio unix-connect:/tmp/my_private_socket_name
> 
> Files modified : gdbstub.c gdbstub.h linux-user/main.c  (tar file attached)
> 
> Diff from latest stable release (patch "Rework configuration via
> command line not applied).

If the patches have conflicts, maybe we can stack them. They logically
belong together (at least once we align the syntax :->), so they should
come as a pair.

> 
> Best regards
> Ph. Waille
> 
> --- qemu-0.10.1_modifie/gdbstub.c	2009-04-02 13:04:08.000000000 +0200
> +++ qemu-0.10.1_orig/gdbstub.c	2009-03-22 00:05:48.000000000 +0100

Reversed patch. A simple svn diff (or git diff, whatever you use) might
be a better idea than manual diffing.

Jan


-- 
Siemens AG, Corporate Technology, CT SE 2
Corporate Competence Center Embedded Linux

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-04-03 16:36 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-04-02 13:53 [Qemu-devel] gdbstub user mode : local/unix socket (cf remote pipe connexion addition) Philippe Waille
2009-04-03  9:31 ` [Qemu-devel] " Philippe Waille
2009-04-03 16:35   ` Jan Kiszka

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).