From b89780722448007ac1168e77b6e803560a100365 Mon Sep 17 00:00:00 2001 From: Tim Newsome Date: Mon, 7 Aug 2017 13:55:37 -0700 Subject: [PATCH] When gdb_port is 0, don't increment it. Usually incrementing to get the next port is a good idea, but when set to 0 the idea is to find an arbitrary unallocated port. 1 is almost certainly not helpful. --- src/server/gdb_server.c | 8 +++++++- src/server/server.c | 3 ++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/server/gdb_server.c b/src/server/gdb_server.c index 6ad95bdfa..ecf46add3 100644 --- a/src/server/gdb_server.c +++ b/src/server/gdb_server.c @@ -3113,7 +3113,13 @@ static int gdb_target_add_one(struct target *target) if (!*end) { if (parse_long(gdb_port_next, &portnumber) == ERROR_OK) { free(gdb_port_next); - gdb_port_next = alloc_printf("%d", portnumber+1); + if (portnumber) { + gdb_port_next = alloc_printf("%d", portnumber+1); + } else { + /* Don't increment if gdb_port is 0, since we're just + * trying to allocate an unused port. */ + gdb_port_next = alloc_printf("0"); + } } } } diff --git a/src/server/server.c b/src/server/server.c index 65da53f6d..99bdc35ec 100644 --- a/src/server/server.c +++ b/src/server/server.c @@ -273,7 +273,8 @@ int add_service(char *name, c->sin.sin_port = htons(c->portnumber); if (bind(c->fd, (struct sockaddr *)&c->sin, sizeof(c->sin)) == -1) { - LOG_ERROR("couldn't bind %s to socket: %s", name, strerror(errno)); + LOG_ERROR("couldn't bind %s to socket on port %d: %s", name, + c->portnumber, strerror(errno)); close_socket(c->fd); free_service(c); return ERROR_FAIL;