From 48db36f436fe212fdda8d3fb7f79db43d9a2aa99 Mon Sep 17 00:00:00 2001 From: Ian Thompson Date: Sun, 10 Jul 2022 17:14:10 -0700 Subject: [PATCH] gdb_server: custom target-specific GDB queries Provide a customizable hook for handling target-specific GDB queries Valgrind-clean, no new Clang analyzer warnings Signed-off-by: Ian Thompson Change-Id: I684a259ed29f3651cbce668101cff421e522f79e Reviewed-on: https://review.openocd.org/c/openocd/+/7082 Tested-by: jenkins Reviewed-by: Antonio Borneo --- src/server/gdb_server.c | 5 +++++ src/target/target_type.h | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/src/server/gdb_server.c b/src/server/gdb_server.c index 3052d0a0e..1e50b43f3 100644 --- a/src/server/gdb_server.c +++ b/src/server/gdb_server.c @@ -2965,6 +2965,11 @@ static int gdb_query_packet(struct connection *connection, gdb_connection->noack_mode = 1; gdb_put_packet(connection, "OK", 2); return ERROR_OK; + } else if (target->type->gdb_query_custom) { + char *buffer = NULL; + int ret = target->type->gdb_query_custom(target, packet, &buffer); + gdb_put_packet(connection, buffer, strlen(buffer)); + return ret; } gdb_put_packet(connection, "", 0); diff --git a/src/target/target_type.h b/src/target/target_type.h index 1933e1cc7..947080381 100644 --- a/src/target/target_type.h +++ b/src/target/target_type.h @@ -286,6 +286,15 @@ struct target_type { */ int (*gdb_fileio_end)(struct target *target, int retcode, int fileio_errno, bool ctrl_c); + /* Parse target-specific GDB query commands. + * The string pointer "response_p" is always assigned by the called function + * to a pointer to a NULL-terminated string, even when the function returns + * an error. The string memory is not freed by the caller, so this function + * must pay attention for possible memory leaks if the string memory is + * dynamically allocated. + */ + int (*gdb_query_custom)(struct target *target, const char *packet, char **response_p); + /* do target profiling */ int (*profiling)(struct target *target, uint32_t *samples,