diff mbox series

[v2,06/38] gdbserver: print some client/server info

Message ID 20220329154931.493851-7-npiggin@gmail.com
State New
Headers show
Series gdbserver multi-threaded debugging and POWER9/10 support | expand

Commit Message

Nicholas Piggin March 29, 2022, 3:48 p.m. UTC
Rather than silently listening this gives some idea things are working.

Reviewed-by: Joel Stanley <joel@jms.id.au>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
 src/pdbgproxy.c | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/src/pdbgproxy.c b/src/pdbgproxy.c
index 3e27ba0..e32f518 100644
--- a/src/pdbgproxy.c
+++ b/src/pdbgproxy.c
@@ -448,6 +448,8 @@  int gdbserver_start(struct pdbg_target *thread, struct pdbg_target *adu, uint16_
 		return -1;
 	}
 
+	printf("gdbserver: listening on port %d\n", port);
+
 	FD_ZERO(&active_fd_set);
 	FD_SET(sock, &active_fd_set);
 
@@ -463,17 +465,29 @@  int gdbserver_start(struct pdbg_target *thread, struct pdbg_target *adu, uint16_
 		for (i = 0; i < FD_SETSIZE; i++) {
 			if (FD_ISSET(i, &read_fd_set)) {
 				if (i == sock) {
+					char host[NI_MAXHOST];
+					struct sockaddr saddr;
+					socklen_t slen;
 					int new;
-					new = accept(sock, NULL, NULL);
+
+					new = accept(sock, &saddr, &slen);
 					if (new < 0) {
 						perror(__FUNCTION__);
 						return -1;
 					}
 
-					if (fd > 0)
+					if (getnameinfo(&saddr, slen,
+							host, sizeof(host),
+							NULL, 0,
+							NI_NUMERICHOST) == 0) {
+						printf("gdbserver: connection from gdb client %s\n", host);
+					}
+
+					if (fd > 0) {
 						/* It only makes sense to accept a single client */
+						printf("gdbserver: another client already connected\n");
 						close(new);
-					else {
+					} else {
 						create_client(new);
 						FD_SET(new, &active_fd_set);
 					}
@@ -481,6 +495,7 @@  int gdbserver_start(struct pdbg_target *thread, struct pdbg_target *adu, uint16_
 					if (read_from_client(i) < 0) {
 						destroy_client(i);
 						FD_CLR(i, &active_fd_set);
+						printf("gdbserver: ended connection with gdb client\n");
 					}
 				}
 			}