1 #ifndef _RISCV_GDBSERVER_H
2 #define _RISCV_GDBSERVER_H
7 class circular_buffer_t
10 // The buffer can store capacity-1 data elements.
11 circular_buffer_t(unsigned int capacity
) : data(new T
[capacity
]),
12 start(0), end(0), capacity(capacity
) {}
13 circular_buffer_t() : start(0), end(0), capacity(0) {}
14 ~circular_buffer_t() { delete data
; }
17 unsigned int start
; // Data start, inclusive.
18 unsigned int end
; // Data end, exclusive.
19 unsigned int capacity
; // Size of the buffer.
20 unsigned int size() const;
21 bool empty() const { return start
== end
; }
22 // Tell the buffer that some bytes were consumed from the start of the
24 void consume(unsigned int bytes
);
26 // Return size and address of the block of RAM where more data can be copied
27 // to be added to the buffer.
28 unsigned int contiguous_space() const;
29 T
*contiguous_data() { return data
+ end
; }
30 void data_added(unsigned int bytes
);
34 T
operator[](unsigned int i
) {
35 return data
[(start
+ i
) % capacity
];
42 // Create a new server, listening for connections from localhost on the given
44 gdbserver_t(uint16_t port
);
46 // Process all pending messages from a client.
49 void handle_packet(const std::vector
<uint8_t> &packet
);
54 circular_buffer_t
<uint8_t> recv_buf
;
55 uint8_t send_buf
[64 * 1024]; // Circular buffer.
56 unsigned int send_start
, send_end
; // Data start (inclusive)/end (exclusive)pointers.
60 // Read pending data from the client.
62 // Accept a new client if there isn't one already connected.
64 // Process all complete requests in recv_buf.
65 void process_requests();
66 // Add the given message to send_buf.
67 void send(const char* msg
);