server: gdb: export gdb_actual_connections through a function 73/7673/2
authorAntonio Borneo <borneo.antonio@gmail.com>
Sat, 6 May 2023 19:59:31 +0000 (21:59 +0200)
committerAntonio Borneo <borneo.antonio@gmail.com>
Thu, 18 May 2023 10:14:56 +0000 (10:14 +0000)
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 <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/7673
Tested-by: jenkins
src/helper/log.c
src/server/gdb_server.c
src/server/gdb_server.h
src/target/semihosting_common.c

index e6a70a3f581f6675848e015f93058381b9bdeb7f..a4fc53d4b51ef0f853e95ca3983ebe6beeb5ff73 100644 (file)
@@ -19,6 +19,7 @@
 #include "command.h"
 #include "replacements.h"
 #include "time_support.h"
+#include <server/gdb_server.h>
 #include <server/server.h>
 
 #include <stdarg.h>
@@ -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 "
index 4fdbc9fbbda562b88750e31bad0eca623510450e..943fe4008835bd303e31a31e807334963c8343d0 100644 (file)
@@ -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;
+}
index e27aad7cfcbf8cb42f26cae9ebb0792775a00ad8..4288ceb878e47015e63870e619160255abcd1cf0 100644 (file)
@@ -20,6 +20,7 @@
 struct image;
 struct reg;
 #include <target/target.h>
+#include <server/server.h>
 
 #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;
index dc0dae2c87c6cdcfcec0e5d82d6d72fc17140c00..3ed112ba94df80e7223d75026ca240876cace694 100644 (file)
@@ -39,6 +39,7 @@
 
 #include <helper/binarybuffer.h>
 #include <helper/log.h>
+#include <server/gdb_server.h>
 #include <sys/stat.h>
 
 /**
@@ -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,

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)