[Pdbg] [PATCH 03/14] gdbserver: print some client/server info
Joel Stanley
joel at jms.id.au
Wed Mar 16 10:13:37 AEDT 2022
On Mon, 14 Mar 2022 at 04:18, Nicholas Piggin <npiggin at gmail.com> wrote:
>
> Rather than silently listening this gives some idea things are working.
>
> Signed-off-by: Nicholas Piggin <npiggin at gmail.com>
Reviewed-by: Joel Stanley <joel at 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 at lists.ozlabs.org
> https://lists.ozlabs.org/listinfo/pdbg
More information about the Pdbg
mailing list