From 53d74f4cc31ecf5bb6499b886d8fcbc992a17920 Mon Sep 17 00:00:00 2001 From: Tim Newsome Date: Tue, 25 Oct 2016 13:17:40 -0700 Subject: [PATCH] Increase gdb receive buffer. Newer gdbs send larger memory write packets when downloading. Also improve error reporting when gdb sends packets that don't fit in the buffer. --- riscv/gdbserver.cc | 23 +++++++++++++++++++++-- riscv/gdbserver.h | 1 + 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/riscv/gdbserver.cc b/riscv/gdbserver.cc index ca567db..16f59b2 100644 --- a/riscv/gdbserver.cc +++ b/riscv/gdbserver.cc @@ -1244,7 +1244,8 @@ gdbserver_t::gdbserver_t(uint16_t port, sim_t *sim) : xlen(0), sim(sim), client_fd(0), - recv_buf(64 * 1024), send_buf(64 * 1024) + // gdb likes to send 0x100000 bytes at once when downloading. + recv_buf(0x180000), send_buf(64 * 1024) { socket_fd = socket(AF_INET, SOCK_STREAM, 0); if (socket_fd == -1) { @@ -1504,7 +1505,6 @@ void gdbserver_t::read() // available. size_t count = recv_buf.contiguous_empty_size(); - assert(count > 0); ssize_t bytes = ::read(client_fd, recv_buf.contiguous_empty(), count); if (bytes == -1) { if (errno == EAGAIN) { @@ -1637,6 +1637,25 @@ void gdbserver_t::process_requests() break; } } + + if (recv_buf.full()) { + fprintf(stderr, + "Receive buffer is full, but no complete packet was found!\n"); + for (unsigned line = 0; line < 8; line++) { + for (unsigned i = 0; i < 16; i++) { + fprintf(stderr, "%02x ", recv_buf.entry(line * 16 + i)); + } + for (unsigned i = 0; i < 16; i++) { + uint8_t e = recv_buf.entry(line * 16 + i); + if (e >= ' ' && e <= '~') + fprintf(stderr, "%c", e); + else + fprintf(stderr, "."); + } + fprintf(stderr, "\n"); + } + assert(!recv_buf.full()); + } } void gdbserver_t::handle_halt_reason(const std::vector &packet) diff --git a/riscv/gdbserver.h b/riscv/gdbserver.h index 0ed8881..f5a00f3 100644 --- a/riscv/gdbserver.h +++ b/riscv/gdbserver.h @@ -25,6 +25,7 @@ public: unsigned int size() const; bool empty() const { return start == end; } bool full() const { return ((end+1) % capacity) == start; } + T entry(unsigned index) { return data[(start + index) % capacity]; } // Return size and address of the block of RAM where more data can be copied // to be added to the buffer. -- 2.30.2