Skip to content

Commit

Permalink
checksum madness
Browse files Browse the repository at this point in the history
  • Loading branch information
aappleby committed Mar 26, 2023
1 parent ec59a82 commit 6247b43
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 59 deletions.
33 changes: 22 additions & 11 deletions GDBPacket.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ struct GDBPacket {
void clear() {
for (int i = 0; i < 1024; i++) buf[i] = 0;
size = 0;
checksum = 0;
//checksum = 0;
error = false;
cursor = 0;
packet_valid = false;
Expand Down Expand Up @@ -51,12 +51,7 @@ struct GDBPacket {
//----------------------------------------

char peek_char() {
if (cursor >= size) {
return 0;
}
else {
return buf[cursor];
}
return cursor >= size ? 0 : buf[cursor];
}

char take_char() {
Expand All @@ -69,7 +64,7 @@ struct GDBPacket {
}
}

int take_hex() {
int take_i32() {
int sign = match('-') ? -1 : 1;

int accum = 0;
Expand All @@ -87,6 +82,22 @@ struct GDBPacket {
return sign * accum;
}

unsigned int take_u32() {
unsigned int accum = 0;
bool any_digits = false;

int digit = 0;
for (int i = 0; i < 8; i++) {
if (!from_hex(peek_char(), digit)) break;
accum = (accum << 4) | digit;
any_digits = true;
cursor++;
}

if (!any_digits) error = true;
return accum;
}

void take(char c) {
char d = take_char();
if (c != d) {
Expand Down Expand Up @@ -130,12 +141,12 @@ struct GDBPacket {

void start_packet() {
clear();
checksum = 0;
//checksum = 0;
}

void put_buf(char c) {
buf[cursor++] = c;
checksum += c;
//checksum += c;
size++;
}

Expand Down Expand Up @@ -165,7 +176,7 @@ struct GDBPacket {
char buf[32768/4];
int sentinel2 = 0xF00DCAFE;
int size = 0;
char checksum = 0;
//char checksum = 0;
bool error = false;
int cursor = 0;
bool packet_valid = false;
Expand Down
Loading

0 comments on commit 6247b43

Please sign in to comment.