gdb-server: Allow multiple instance.
This commit is contained in:
parent
9075411c93
commit
3b75cb9a5a
|
@ -7,4 +7,5 @@ CFLAGS += -Wno-cast-function-type
|
|||
else ifneq (, $(findstring cygwin, $(SYS)))
|
||||
LDFLAGS += -lusb-1.0 -lws2_32
|
||||
endif
|
||||
VPATH += platforms/pc
|
||||
SRC += timing.c \
|
||||
|
|
|
@ -36,12 +36,16 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "general.h"
|
||||
#include "gdb_if.h"
|
||||
|
||||
static int gdb_if_serv, gdb_if_conn;
|
||||
|
||||
#define DEFAULT_PORT 2000
|
||||
#define NUM_GDB_SERVER 4
|
||||
int gdb_if_init(void)
|
||||
{
|
||||
#if defined(_WIN32) || defined(__CYGWIN__)
|
||||
|
@ -50,20 +54,40 @@ int gdb_if_init(void)
|
|||
#endif
|
||||
struct sockaddr_in addr;
|
||||
int opt;
|
||||
int port = DEFAULT_PORT - 1;
|
||||
|
||||
do {
|
||||
port ++;
|
||||
if (port > DEFAULT_PORT + NUM_GDB_SERVER)
|
||||
return - 1;
|
||||
addr.sin_family = AF_INET;
|
||||
addr.sin_port = htons(2000);
|
||||
addr.sin_port = htons(port);
|
||||
addr.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||
|
||||
assert((gdb_if_serv = socket(PF_INET, SOCK_STREAM, 0)) != -1);
|
||||
gdb_if_serv = socket(PF_INET, SOCK_STREAM, 0);
|
||||
if (gdb_if_serv == -1)
|
||||
continue;
|
||||
|
||||
opt = 1;
|
||||
assert(setsockopt(gdb_if_serv, SOL_SOCKET, SO_REUSEADDR, (void*)&opt, sizeof(opt)) != -1);
|
||||
assert(setsockopt(gdb_if_serv, IPPROTO_TCP, TCP_NODELAY, (void*)&opt, sizeof(opt)) != -1);
|
||||
|
||||
assert(bind(gdb_if_serv, (void*)&addr, sizeof(addr)) != -1);
|
||||
assert(listen(gdb_if_serv, 1) != -1);
|
||||
|
||||
DEBUG("Listening on TCP:2000\n");
|
||||
if (setsockopt(gdb_if_serv, SOL_SOCKET, SO_REUSEADDR, (void*)&opt, sizeof(opt)) == -1) {
|
||||
close(gdb_if_serv);
|
||||
continue;
|
||||
}
|
||||
if (setsockopt(gdb_if_serv, IPPROTO_TCP, TCP_NODELAY, (void*)&opt, sizeof(opt)) == -1) {
|
||||
close(gdb_if_serv);
|
||||
continue;
|
||||
}
|
||||
if (bind(gdb_if_serv, (void*)&addr, sizeof(addr)) == -1) {
|
||||
close(gdb_if_serv);
|
||||
continue;
|
||||
}
|
||||
if (listen(gdb_if_serv, 1) == -1) {
|
||||
close(gdb_if_serv);
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
} while(1);
|
||||
DEBUG("Listening on TCP: %4d\n", port);
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue