aboutsummaryrefslogtreecommitdiff
path: root/src/rtos/rtos.c
diff options
context:
space:
mode:
authorBohdan Tymkiv <bhdt@cypress.com>2019-04-16 17:28:29 +0300
committerTomas Vanek <vanekt@fbl.cz>2019-06-04 21:37:41 +0100
commiteea508d9afa184684bf5a4e2788b6cd4b5fdc9ab (patch)
treeb5aaf19b1591bf78d69d90876449b0d528f83d1f /src/rtos/rtos.c
parent85ed41d2100ba2f451ba8ff3d75abbeb8cf10a29 (diff)
downloadriscv-openocd-eea508d9afa184684bf5a4e2788b6cd4b5fdc9ab.zip
riscv-openocd-eea508d9afa184684bf5a4e2788b6cd4b5fdc9ab.tar.gz
riscv-openocd-eea508d9afa184684bf5a4e2788b6cd4b5fdc9ab.tar.bz2
gdb_server: fix GDB_BUFFER_SIZE usage, fix unaligned access during bulk transfers
Currently size of the GDB buffer is 16384 bytes but it is treated as nul-terminated string in most of the code, so effective size of the buffer is actually 16383 bytes. OpenOCD responds with `PacketSize=3fff` to qSupported request. Result of GDB's `m` command is encoded in hex so each data byte uses two bytes in the buffer. As a result GDB will split bulk read requests into chunks 0x1fff bytes each. This causes troubles on targets (or memory regions) which support only aligned, word-sized access (such as MMIO buffers). Steps to reproduce (psoc6 target): gdb> dump binary memory dump.bin 0x040320000 (0x040320000 + 65536) OpenOCD: Error: Failed to read memory at 0x40321ffe Error: Failed to read memory at 0x40321000 Error: Failed to read memory at 0x40323000 Error: Failed to read memory at 0x40325ffe Error: Failed to read memory at 0x40329ffa Error: Failed to read memory at 0x40329ffc Error: Failed to read memory at 0x4032bffc Error: Failed to read memory at 0x4032dffa Consolidate GDB_BUFFER_SIZE usage: ensure size of each buffer is (GDB_BUFFER_SIZE + 1), add explicit comment that additional byte is used for nul-termination. Report correct size of the buffer to GDB (0x4000) as recommended in GDB's docummentation: `if the stub stores packets in a NUL-terminated format, it should allow an extra byte in its buffer for the NUL` Checked with clang-asan, clang-analyzer, valgrind - no new errors. Change-Id: I909e8a2c6b010c5d4a304641808d4a807a4ec18d Signed-off-by: Bohdan Tymkiv <bhdt@cypress.com> Reviewed-on: http://openocd.zylin.com/5109 Tested-by: jenkins Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
Diffstat (limited to 'src/rtos/rtos.c')
-rw-r--r--src/rtos/rtos.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/rtos/rtos.c b/src/rtos/rtos.c
index da0a503..20e875d 100644
--- a/src/rtos/rtos.c
+++ b/src/rtos/rtos.c
@@ -223,7 +223,7 @@ int rtos_qsymbol(struct connection *connection, char const *packet, int packet_s
int rtos_detected = 0;
uint64_t addr = 0;
size_t reply_len;
- char reply[GDB_BUFFER_SIZE], cur_sym[GDB_BUFFER_SIZE / 2] = "";
+ char reply[GDB_BUFFER_SIZE + 1], cur_sym[GDB_BUFFER_SIZE / 2 + 1] = ""; /* Extra byte for nul-termination */
symbol_table_elem_t *next_sym = NULL;
struct target *target = get_target_from_connection(connection);
struct rtos *os = target->rtos;