|
From: openocd-gerrit <ope...@us...> - 2025-11-12 20:31:36
|
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Main OpenOCD repository".
The branch, master has been updated
via 31b26601521e14bdf5e4997379a473d4f7611e02 (commit)
from 2913dff98ae81d50a1baa9af944080f02ad91708 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 31b26601521e14bdf5e4997379a473d4f7611e02
Author: Tomas Vanek <va...@fb...>
Date: Thu Sep 18 08:04:44 2025 +0200
rtos: introduce rtos_put_gdb_reg()
and use it in rtos_get_gdb_reg() after get_thread_reg_value()
to allow passing long register value without hackish use of
struct rtos_reg.
Fixes: 9123: rtos: Dynamically allocate memory for RTOS registers
Link: https://review.openocd.org/c/openocd/+/9123
Change-Id: I30a51dcca60d67a0f01aa957c9c6076f266b5758
Signed-off-by: Tomas Vanek <va...@fb...>
Reviewed-on: https://review.openocd.org/c/openocd/+/9135
Tested-by: jenkins
Reviewed-by: Evgeniy Naydanov <evg...@sy...>
diff --git a/src/rtos/rtos.c b/src/rtos/rtos.c
index 45366268d..6a5d7b32c 100644
--- a/src/rtos/rtos.c
+++ b/src/rtos/rtos.c
@@ -503,6 +503,26 @@ int rtos_thread_packet(struct connection *connection, char const *packet, int pa
return GDB_THREAD_PACKET_NOT_CONSUMED;
}
+static int rtos_put_gdb_reg(struct connection *connection,
+ uint8_t *reg_value, unsigned int reg_size)
+{
+ unsigned int reg_bytes = DIV_ROUND_UP(reg_size, 8);
+ unsigned int num_bytes = reg_bytes * 2 + 1; // for '\0'
+
+ char *hex = malloc(num_bytes);
+ if (!hex) {
+ LOG_ERROR("Out of memory");
+ return ERROR_FAIL;
+ }
+
+ size_t len = hexify(hex, reg_value, reg_bytes, num_bytes);
+
+ gdb_put_packet(connection, hex, len);
+ free(hex);
+
+ return ERROR_OK;
+}
+
static int rtos_put_gdb_reg_list(struct connection *connection,
struct rtos_reg *reg_list, int num_regs)
{
@@ -555,32 +575,19 @@ int rtos_get_gdb_reg(struct connection *connection, int reg_num)
return retval;
}
- /* Create a reg_list with one register that can
- * accommodate the full size of the one we just got the
- * value for. To do that we allocate extra space off the
- * end of the struct, relying on the fact that
- * rtos_reg.value is the last element in the struct. */
- reg_list = calloc(1, sizeof(*reg_list) + DIV_ROUND_UP(reg_size, 8));
- if (!reg_list) {
- free(reg_value);
- LOG_ERROR("Failed to allocated reg_list for %d-byte register.",
- reg_size);
- return ERROR_FAIL;
- }
- reg_list[0].number = reg_num;
- reg_list[0].size = reg_size;
- memcpy(®_list[0].value, reg_value, DIV_ROUND_UP(reg_size, 8));
+ retval = rtos_put_gdb_reg(connection, reg_value, reg_size);
+
free(reg_value);
- num_regs = 1;
- } else {
- retval = target->rtos->type->get_thread_reg_list(target->rtos,
+ return retval;
+ }
+
+ retval = target->rtos->type->get_thread_reg_list(target->rtos,
current_threadid,
®_list,
&num_regs);
- if (retval != ERROR_OK) {
- LOG_ERROR("RTOS: failed to get register list");
- return retval;
- }
+ if (retval != ERROR_OK) {
+ LOG_ERROR("RTOS: failed to get register list");
+ return retval;
}
for (int i = 0; i < num_regs; ++i) {
diff --git a/src/rtos/rtos.h b/src/rtos/rtos.h
index 3077acc9d..ca6d7518d 100644
--- a/src/rtos/rtos.h
+++ b/src/rtos/rtos.h
@@ -53,8 +53,6 @@ struct rtos_reg {
uint32_t number;
uint32_t size;
uint8_t value[16];
- /* WARNING: rtos_get_gdb_reg() relies on the fact that value is the last
- * element of this struct. Any new fields should be added *before* value. */
};
struct rtos_type {
-----------------------------------------------------------------------
Summary of changes:
src/rtos/rtos.c | 51 +++++++++++++++++++++++++++++----------------------
src/rtos/rtos.h | 2 --
2 files changed, 29 insertions(+), 24 deletions(-)
hooks/post-receive
--
Main OpenOCD repository
|