From d5c177cd3def7002f18270742ff3b1380feb45c5 Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Sat, 6 May 2023 21:59:31 +0200 Subject: [PATCH] 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/helper/log.c | 5 ++--- src/server/gdb_server.c | 7 ++++++- src/server/gdb_server.h | 3 +++ src/target/semihosting_common.c | 14 ++++++-------- 4 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/helper/log.c b/src/helper/log.c index e6a70a3f5..a4fc53d4b 100644 --- a/src/helper/log.c +++ b/src/helper/log.c @@ -19,6 +19,7 @@ #include "command.h" #include "replacements.h" #include "time_support.h" +#include #include #include @@ -399,9 +400,7 @@ char *alloc_printf(const char *format, ...) static void gdb_timeout_warning(int64_t delta_time) { - extern int gdb_actual_connections; - - if (gdb_actual_connections) + if (gdb_get_actual_connections()) LOG_WARNING("keep_alive() was not invoked in the " "%d ms timelimit. GDB alive packet not " "sent! (%" PRId64 " ms). Workaround: increase " diff --git a/src/server/gdb_server.c b/src/server/gdb_server.c index 4fdbc9fbb..943fe4008 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; +} diff --git a/src/server/gdb_server.h b/src/server/gdb_server.h index e27aad7cf..4288ceb87 100644 --- a/src/server/gdb_server.h +++ b/src/server/gdb_server.h @@ -20,6 +20,7 @@ struct image; struct reg; #include +#include #define GDB_BUFFER_SIZE 16384 @@ -29,6 +30,8 @@ void gdb_service_free(void); int gdb_put_packet(struct connection *connection, char *buffer, int len); +int gdb_get_actual_connections(void); + static inline struct target *get_target_from_connection(struct connection *connection) { struct gdb_service *gdb_service = connection->service->priv; diff --git a/src/target/semihosting_common.c b/src/target/semihosting_common.c index dc0dae2c8..3ed112ba9 100644 --- a/src/target/semihosting_common.c +++ b/src/target/semihosting_common.c @@ -39,6 +39,7 @@ #include #include +#include #include /** @@ -92,9 +93,6 @@ static int semihosting_common_fileio_info(struct target *target, static int semihosting_common_fileio_end(struct target *target, int result, int fileio_errno, bool ctrl_c); -/* Attempts to include gdb_server.h failed. */ -extern int gdb_actual_connections; - /** * Initialize common semihosting support. * @@ -493,7 +491,7 @@ int semihosting_common(struct target *target) int code = semihosting_get_field(target, 1, fields); if (type == ADP_STOPPED_APPLICATION_EXIT) { - if (!gdb_actual_connections) + if (!gdb_get_actual_connections()) exit(code); else { fprintf(stderr, @@ -508,7 +506,7 @@ int semihosting_common(struct target *target) } } else { if (semihosting->param == ADP_STOPPED_APPLICATION_EXIT) { - if (!gdb_actual_connections) + if (!gdb_get_actual_connections()) exit(0); else { fprintf(stderr, @@ -517,14 +515,14 @@ int semihosting_common(struct target *target) } else if (semihosting->param == ADP_STOPPED_RUN_TIME_ERROR) { /* Chosen more or less arbitrarily to have a nicer message, * otherwise all other return the same exit code 1. */ - if (!gdb_actual_connections) + if (!gdb_get_actual_connections()) exit(1); else { fprintf(stderr, "semihosting: *** application exited with error ***\n"); } } else { - if (!gdb_actual_connections) + if (!gdb_get_actual_connections()) exit(1); else { fprintf(stderr, @@ -584,7 +582,7 @@ int semihosting_common(struct target *target) int code = semihosting_get_field(target, 1, fields); if (type == ADP_STOPPED_APPLICATION_EXIT) { - if (!gdb_actual_connections) + if (!gdb_get_actual_connections()) exit(code); else { fprintf(stderr,