This is an automated email from Gerrit. Xiang W (wxj...@126.com) just uploaded a new patch set to Gerrit, which you can find at http://openocd.zylin.com/6264
-- gerrit commit 7b31aff20a0a007ead1fcdec8ea7f8fe03a9a5ac Author: Xiang W <wxj...@126.com> Date: Tue May 18 19:24:47 2021 +0800 riscv: Fix riscv_program to use dynamic memory for debug_buffer The previous code used a fixed size to buffer debug_buffer. This patch dynamically allocates memory through riscv_debug_buffer_size Change-Id: Iae0233045ff51ca59045e2f3fd0517886846a7c2 Signed-off-by: Xiang W <wxj...@126.com> diff --git a/src/target/riscv/program.c b/src/target/riscv/program.c index 8e2ce5d..56f1847 100644 --- a/src/target/riscv/program.c +++ b/src/target/riscv/program.c @@ -16,15 +16,19 @@ /* Program interface. */ int riscv_program_init(struct riscv_program *p, struct target *target) { - memset(p, 0, sizeof(*p)); p->target = target; p->instruction_count = 0; p->target_xlen = riscv_xlen(target); for (size_t i = 0; i < RISCV_REGISTER_COUNT; ++i) p->writes_xreg[i] = 0; - for (size_t i = 0; i < RISCV_MAX_DEBUG_BUFFER_SIZE; ++i) - p->debug_buffer[i] = -1; + uint32_t need_size = riscv_debug_buffer_size(target); + if (p->debug_buffer == NULL || p->debug_buffer_alloc_size < need_size) { + p->debug_buffer_alloc_size = need_size; + p->debug_buffer = realloc(p->debug_buffer, need_size * sizeof(uint32_t)); + } + for (size_t i = 0; i < p->debug_buffer_alloc_size; ++i) + p->debug_buffer[i] = -1; return ERROR_OK; } diff --git a/src/target/riscv/program.h b/src/target/riscv/program.h index 2fa925a..2432a81 100644 --- a/src/target/riscv/program.h +++ b/src/target/riscv/program.h @@ -5,7 +5,6 @@ #include "riscv.h" -#define RISCV_MAX_DEBUG_BUFFER_SIZE 32 #define RISCV_REGISTER_COUNT 32 #define RISCV_DSCRATCH_COUNT 2 @@ -15,7 +14,8 @@ struct riscv_program { struct target *target; - uint32_t debug_buffer[RISCV_MAX_DEBUG_BUFFER_SIZE]; + uint32_t* debug_buffer; + uint32_t debug_buffer_alloc_size; /* Number of 32-bit instructions in the program. */ size_t instruction_count; --