gdb: move recv buffer to the heap to support fx-9860G III smaller .data

This commit is contained in:
redoste 2023-06-04 19:35:13 +02:00
parent 5087a91101
commit 6f53fa7842
No known key found for this signature in database

View file

@ -55,7 +55,8 @@ static void gdb_send(const char *data, size_t size)
usb_commit_sync(pipe);
}
static char gdb_recv_buffer[1024];
static char *gdb_recv_buffer = NULL;
static const size_t gdb_recv_buffer_capacity = 256;
static size_t gdb_recv_buffer_size = 0;
static ssize_t gdb_recv(char *buffer, size_t buffer_size)
{
@ -74,7 +75,7 @@ static ssize_t gdb_recv(char *buffer, size_t buffer_size)
// TODO : should we abort or find a way to gracefully shutdown the debugger ?
if (strncmp(header.application, "gdb", 16) == 0
&& strncmp(header.type, "remote", 16) == 0) {
if (header.size > sizeof(gdb_recv_buffer) - gdb_recv_buffer_size) {
if (header.size > gdb_recv_buffer_capacity - gdb_recv_buffer_size) {
abort();
}
usb_read_sync(usb_ff_bulk_input(), &gdb_recv_buffer[gdb_recv_buffer_size], header.size, false);
@ -620,6 +621,10 @@ int gdb_start(void)
return GDB_NO_INTERFACE;
}
if (!gdb_recv_buffer) {
gdb_recv_buffer = malloc(gdb_recv_buffer_capacity);
}
usb_interface_t const *interfaces[] = { &usb_ff_bulk, NULL };
if (usb_open(interfaces, GINT_CALL_NULL) < 0) {
return GDB_USB_ERROR;