Fixes https://bugs.winehq.org/show_bug.cgi?id=21404.
Signed-off-by: Zebediah Figura z.figura12@gmail.com --- 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 cc2af5f..3ecf629 100644 --- a/programs/winedbg/gdbproxy.c +++ b/programs/winedbg/gdbproxy.c @@ -2345,10 +2345,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; @@ -2362,6 +2362,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;
@@ -2430,7 +2436,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; @@ -2461,7 +2467,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 @@ -2474,13 +2480,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; @@ -2522,7 +2528,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] == '-') @@ -2539,11 +2546,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.