diff mbox series

[03/14] gdbserver: print some client/server info

Message ID 20220314041735.542867-4-npiggin@gmail.com
State New
Headers show
Series gdbserver fixes and POWER10 support | expand

Commit Message

Nicholas Piggin March 14, 2022, 4:17 a.m. UTC
Rather than silently listening this gives some idea things are working.

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
 src/pdbgproxy.c | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)

Comments

Joel Stanley March 15, 2022, 11:13 p.m. UTC | #1
On Mon, 14 Mar 2022 at 04:18, Nicholas Piggin <npiggin@gmail.com> wrote:
>
> Rather than silently listening this gives some idea things are working.
>
> Signed-off-by: Nicholas Piggin <npiggin@gmail.com>

Reviewed-by: Joel Stanley <joel@jms.id.au>


> ---
>  src/pdbgproxy.c | 21 ++++++++++++++++++---
>  1 file changed, 18 insertions(+), 3 deletions(-)
>
> 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");
>                                         }
>                                 }
>                         }
> --
> 2.23.0
>
> --
> Pdbg mailing list
> Pdbg@lists.ozlabs.org
> https://lists.ozlabs.org/listinfo/pdbg
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");
 					}
 				}
 			}