[Pdbg] [PATCH v2 06/38] gdbserver: print some client/server info
Nicholas Piggin
npiggin at gmail.com
Wed Mar 30 02:48:59 AEDT 2022
Rather than silently listening this gives some idea things are working.
Reviewed-by: Joel Stanley <joel at jms.id.au>
Signed-off-by: Nicholas Piggin <npiggin at gmail.com>
---
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
More information about the Pdbg
mailing list