From d5c177cd3def7002f18270742ff3b1380feb45c5 Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Sat, 6 May 2023 21:59:31 +0200 Subject: server: gdb: export gdb_actual_connections through a function The internal variable 'gdb_actual_connections' is used by log and by semihosting to determine if there are active GDB connections. Keep the variable local in server's code and only export its value through a dedicated function. This solves the issue detected by 'parse' of the variable defined as global but not declared in any include file. Change-Id: I6e14f4cb1097787404094636f8a2a291340222dd Signed-off-by: Antonio Borneo Reviewed-on: https://review.openocd.org/c/openocd/+/7673 Tested-by: jenkins --- src/server/gdb_server.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/server/gdb_server.c') diff --git a/src/server/gdb_server.c b/src/server/gdb_server.c index 4fdbc9f..943fe40 100644 --- a/src/server/gdb_server.c +++ b/src/server/gdb_server.c @@ -117,7 +117,7 @@ static void gdb_sig_halted(struct connection *connection); /* number of gdb connections, mainly to suppress gdb related debugging spam * in helper/log.c when no gdb connections are actually active */ -int gdb_actual_connections; +static int gdb_actual_connections; /* set if we are sending a memory map to gdb * via qXfer:memory-map:read packet */ @@ -4105,3 +4105,8 @@ void gdb_service_free(void) free(gdb_port); free(gdb_port_next); } + +int gdb_get_actual_connections(void) +{ + return gdb_actual_connections; +} -- cgit v1.1 From 0854c83076749196603bebdb47ec93f50a454f79 Mon Sep 17 00:00:00 2001 From: Marek Vrbka Date: Mon, 29 May 2023 14:41:34 +0200 Subject: gdb_server: add debug signal reason prints Added debug prints to show what is the target debug reason. Also added debug print for Ctrl-C response. This is useful for troubleshooting and log analysis. Change-Id: I055936257d989efe7255656198a8d73a367fcd15 Signed-off-by: Marek Vrbka Reviewed-on: https://review.openocd.org/c/openocd/+/7720 Reviewed-by: Antonio Borneo Tested-by: jenkins --- src/server/gdb_server.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src/server/gdb_server.c') diff --git a/src/server/gdb_server.c b/src/server/gdb_server.c index 943fe40..0baf755 100644 --- a/src/server/gdb_server.c +++ b/src/server/gdb_server.c @@ -145,6 +145,9 @@ static char gdb_running_type; static int gdb_last_signal(struct target *target) { + LOG_TARGET_DEBUG(target, "Debug reason is: %s", + target_debug_reason_str(target->debug_reason)); + switch (target->debug_reason) { case DBG_REASON_DBGRQ: return 0x2; /* SIGINT */ @@ -159,8 +162,9 @@ static int gdb_last_signal(struct target *target) case DBG_REASON_NOTHALTED: return 0x0; /* no signal... shouldn't happen */ default: - LOG_USER("undefined debug reason %d - target needs reset", - target->debug_reason); + LOG_USER("undefined debug reason %d (%s) - target needs reset", + target->debug_reason, + target_debug_reason_str(target->debug_reason)); return 0x0; } } @@ -798,6 +802,7 @@ static void gdb_signal_reply(struct target *target, struct connection *connectio } if (gdb_connection->ctrl_c) { + LOG_TARGET_DEBUG(target, "Responding with signal 2 (SIGINT) to debugger due to Ctrl-C"); signal_var = 0x2; } else signal_var = gdb_last_signal(ct); -- cgit v1.1 From 71180e67537117f841ff5dd7c359e3678d861e2b Mon Sep 17 00:00:00 2001 From: Marek Vrbka Date: Tue, 30 May 2023 10:07:18 +0200 Subject: gdb_server: refactor and unify function gdb_get_char_inner The old implementation of gdb socket error handling in the gdb_get_char_inner() differs between Windows and *nix platforms. This patch simplifies it by using an existing function log_socket_error() which handles most of the platform specific things. It also provides better error messages. Change-Id: Iec871c4965b116dc7cfb03c3565bab66c8b41958 Signed-off-by: Marek Vrbka Reviewed-on: https://review.openocd.org/c/openocd/+/7724 Tested-by: jenkins Reviewed-by: Antonio Borneo --- src/server/gdb_server.c | 43 ++++++++++++------------------------------- 1 file changed, 12 insertions(+), 31 deletions(-) (limited to 'src/server/gdb_server.c') diff --git a/src/server/gdb_server.c b/src/server/gdb_server.c index 0baf755..702dbef 100644 --- a/src/server/gdb_server.c +++ b/src/server/gdb_server.c @@ -235,39 +235,20 @@ static int gdb_get_char_inner(struct connection *connection, int *next_char) } #ifdef _WIN32 - errno = WSAGetLastError(); - - switch (errno) { - case WSAEWOULDBLOCK: - usleep(1000); - break; - case WSAECONNABORTED: - gdb_con->closed = true; - return ERROR_SERVER_REMOTE_CLOSED; - case WSAECONNRESET: - gdb_con->closed = true; - return ERROR_SERVER_REMOTE_CLOSED; - default: - LOG_ERROR("read: %d", errno); - exit(-1); - } + bool retry = (WSAGetLastError() == WSAEWOULDBLOCK); #else - switch (errno) { - case EAGAIN: - usleep(1000); - break; - case ECONNABORTED: - gdb_con->closed = true; - return ERROR_SERVER_REMOTE_CLOSED; - case ECONNRESET: - gdb_con->closed = true; - return ERROR_SERVER_REMOTE_CLOSED; - default: - LOG_ERROR("read: %s", strerror(errno)); - gdb_con->closed = true; - return ERROR_SERVER_REMOTE_CLOSED; - } + bool retry = (errno == EAGAIN); #endif + + if (retry) { + // Try again after a delay + usleep(1000); + } else { + // Print error and close the socket + log_socket_error("GDB"); + gdb_con->closed = true; + return ERROR_SERVER_REMOTE_CLOSED; + } } #ifdef _DEBUG_GDB_IO_ -- cgit v1.1