gdbstub: added REUSEADDR/PORT and socket closing
This commit is contained in:
parent
c3fa088a38
commit
44a917b398
@ -10,6 +10,8 @@
|
||||
#include <string.h>
|
||||
|
||||
/* Sockets */
|
||||
#include <unistd.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/types.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
@ -31,7 +33,6 @@ void gdbstub_thread_gdb();
|
||||
void gdbstub_cpu_watcher_thread();
|
||||
static void gdbstub_handle_ctrlc();
|
||||
|
||||
|
||||
/*
|
||||
* Receive a packet from client gdb
|
||||
* Ignores the ACK on the way, and only returns the packet (not initial '$' symbol)
|
||||
@ -120,6 +121,11 @@ static void gdbstub_send_unsupported()
|
||||
void gdbstub_start()
|
||||
{
|
||||
socket_t sock = socket(AF_INET, SOCK_STREAM, 0);
|
||||
|
||||
// Set REUSEADDRESS/PORT so that we dont get "port already in use" on close
|
||||
setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &(int){1}, sizeof(int));
|
||||
setsockopt(sock, SOL_SOCKET, SO_REUSEPORT, &(int){1}, sizeof(int));
|
||||
|
||||
if(sock == INVALID_SOCKET)
|
||||
{
|
||||
fprintf(stderr, "Could not create gdbstub server socket: %s\n", strerror(errno));
|
||||
@ -145,6 +151,15 @@ void gdbstub_start()
|
||||
gdbstub_server_socket = sock;
|
||||
}
|
||||
|
||||
/*
|
||||
* Gracefully close gdb socket
|
||||
*/
|
||||
void gdbstub_stop()
|
||||
{
|
||||
close(gdb_socket);
|
||||
close(gdbstub_server_socket);
|
||||
}
|
||||
|
||||
/*
|
||||
* Wait for a client (gdb) to connect to this server
|
||||
*/
|
||||
|
@ -2,6 +2,7 @@
|
||||
#define GDBSTUB_H
|
||||
|
||||
void gdbstub_start();
|
||||
void gdbstub_stop();
|
||||
void gdbstub_wait_for_connection();
|
||||
|
||||
#endif
|
||||
|
@ -36,6 +36,7 @@ int main(int argc, char** argv)
|
||||
if(gdbstub)
|
||||
{
|
||||
pthread_join(cpu0_thread, 0);
|
||||
gdbstub_stop();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user