Zebediah Figura : winedbg: Add support for starting on a user-supplied port.

Alexandre Julliard julliard at winehq.org
Thu Sep 13 03:49:13 CDT 2018


Module: wine
Branch: stable
Commit: f4247d03642042cefdb2497f8d050344819e4d72
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=f4247d03642042cefdb2497f8d050344819e4d72

Author: Zebediah Figura <z.figura12 at gmail.com>
Date:   Wed May  2 19:32:50 2018 -0500

winedbg: Add support for starting on a user-supplied port.

Signed-off-by: Zebediah Figura <z.figura12 at gmail.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
(cherry picked from commit 3849270aa74f4fdb47f09eeb3442e40ea4f44520)
Signed-off-by: Michael Stefaniuc <mstefani at winehq.org>

---

 programs/winedbg/gdbproxy.c     | 34 ++++++++++++++++++++++++++--------
 programs/winedbg/winedbg.man.in |  4 ++++
 2 files changed, 30 insertions(+), 8 deletions(-)

diff --git a/programs/winedbg/gdbproxy.c b/programs/winedbg/gdbproxy.c
index d80a4f8..1251490 100644
--- a/programs/winedbg/gdbproxy.c
+++ b/programs/winedbg/gdbproxy.c
@@ -2399,10 +2399,10 @@ static BOOL gdb_exec(const char* wine_path, unsigned port, unsigned flags)
     return TRUE;
 }
 
-static BOOL gdb_startup(struct gdb_context* gdbctx, DEBUG_EVENT* de, unsigned flags)
+static BOOL gdb_startup(struct gdb_context* gdbctx, DEBUG_EVENT* de, unsigned flags, unsigned port)
 {
     int                 sock;
-    struct sockaddr_in  s_addrs;
+    struct sockaddr_in  s_addrs = {0};
     socklen_t           s_len = sizeof(s_addrs);
     struct pollfd       pollfd;
     IMAGEHLP_MODULE64   imh_mod;
@@ -2416,6 +2416,12 @@ static BOOL gdb_startup(struct gdb_context* gdbctx, DEBUG_EVENT* de, unsigned fl
         return FALSE;
     }
 
+    s_addrs.sin_family = AF_INET;
+    s_addrs.sin_addr.s_addr = INADDR_ANY;
+    s_addrs.sin_port = htons(port);
+    if (bind(sock, (struct sockaddr *)&s_addrs, sizeof(s_addrs)) == -1)
+        goto cleanup;
+
     if (listen(sock, 1) == -1 || getsockname(sock, (struct sockaddr*)&s_addrs, &s_len) == -1)
         goto cleanup;
 
@@ -2484,7 +2490,7 @@ cleanup:
     return ret;
 }
 
-static BOOL gdb_init_context(struct gdb_context* gdbctx, unsigned flags)
+static BOOL gdb_init_context(struct gdb_context* gdbctx, unsigned flags, unsigned port)
 {
     DEBUG_EVENT         de;
     int                 i;
@@ -2517,7 +2523,7 @@ static BOOL gdb_init_context(struct gdb_context* gdbctx, unsigned flags)
              * and the only one of this type  */
             assert(gdbctx->process == NULL && de.dwProcessId == dbg_curr_pid);
             /* gdbctx->dwProcessId = pid; */
-            if (!gdb_startup(gdbctx, &de, flags)) return FALSE;
+            if (!gdb_startup(gdbctx, &de, flags, port)) return FALSE;
             assert(!gdbctx->in_trap);
         }
         else
@@ -2530,13 +2536,13 @@ static BOOL gdb_init_context(struct gdb_context* gdbctx, unsigned flags)
     return TRUE;
 }
 
-static int gdb_remote(unsigned flags)
+static int gdb_remote(unsigned flags, unsigned port)
 {
     struct pollfd       pollfd;
     struct gdb_context  gdbctx;
     BOOL                doLoop;
 
-    for (doLoop = gdb_init_context(&gdbctx, flags); doLoop;)
+    for (doLoop = gdb_init_context(&gdbctx, flags, port); doLoop;)
     {
         pollfd.fd = gdbctx.sock;
         pollfd.events = POLLIN;
@@ -2578,7 +2584,8 @@ static int gdb_remote(unsigned flags)
 int gdb_main(int argc, char* argv[])
 {
 #ifdef HAVE_POLL
-    unsigned gdb_flags = 0;
+    unsigned gdb_flags = 0, port = 0;
+    char *port_end;
 
     argc--; argv++;
     while (argc > 0 && argv[0][0] == '-')
@@ -2595,11 +2602,22 @@ int gdb_main(int argc, char* argv[])
             argc--; argv++;
             continue;
         }
+        if (strcmp(argv[0], "--port") == 0 && argc > 1)
+        {
+            port = strtoul(argv[1], &port_end, 10);
+            if (*port_end)
+            {
+                fprintf(stderr, "Invalid port: %s\n", argv[1]);
+                return -1;
+            }
+            argc -= 2; argv += 2;
+            continue;
+        }
         return -1;
     }
     if (dbg_active_attach(argc, argv) == start_ok ||
         dbg_active_launch(argc, argv) == start_ok)
-        return gdb_remote(gdb_flags);
+        return gdb_remote(gdb_flags, port);
 #else
     fprintf(stderr, "GdbProxy mode not supported on this platform\n");
 #endif
diff --git a/programs/winedbg/winedbg.man.in b/programs/winedbg/winedbg.man.in
index ea4dc28..6f38bc0 100644
--- a/programs/winedbg/winedbg.man.in
+++ b/programs/winedbg/winedbg.man.in
@@ -73,6 +73,10 @@ When in \fBgdb\fR proxy mode, the following options are available:
 started. Relevant information for starting \fBgdb\fR is printed on
 screen. This is somehow useful when not directly using \fBgdb\fR but
 some graphical front-ends, like \fBddd\fR or \fBkgbd\fR. 
+.IP \fB--port\fR\ \fIport\fR
+Start the \fBgdb\fR server on the given port. If this option is not
+specified, a randomly chosen port will be used. If \fB--no-start\fR is
+specified, the port used will be printed on startup.
 .IP \fB--with-xterm\fR
 This will run \fBgdb\fR in its own xterm instead of using the current
 Unix console for textual display.




More information about the wine-cvs mailing list