Skip to content

Commit

Permalink
Do not send a NUL at end of packets to gdb.
Browse files Browse the repository at this point in the history
GDB doesn't need it and see the NUL as a junk character
(visible with 'set debug remote 1').
  • Loading branch information
gingold-adacore committed Dec 17, 2015
1 parent 881ed00 commit 177ef67
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions gdbserver/gdb-remote.c
Expand Up @@ -18,22 +18,23 @@
static const char hex[] = "0123456789abcdef";

int gdb_send_packet(int fd, char* data) {
int length = strlen(data) + 5;
unsigned int data_length = strlen(data);
int length = data_length + 4;
char* packet = malloc(length); /* '$' data (hex) '#' cksum (hex) */

memset(packet, 0, length);

packet[0] = '$';

uint8_t cksum = 0;
for(unsigned int i = 0; i < strlen(data); i++) {
for(unsigned int i = 0; i < data_length; i++) {
packet[i + 1] = data[i];
cksum += data[i];
}

packet[length - 4] = '#';
packet[length - 3] = hex[cksum >> 4];
packet[length - 2] = hex[cksum & 0xf];
packet[length - 3] = '#';
packet[length - 2] = hex[cksum >> 4];
packet[length - 1] = hex[cksum & 0xf];

while(1) {
if(write(fd, packet, length) != length) {
Expand Down

0 comments on commit 177ef67

Please sign in to comment.