2004-10-19 Theodore A. Roth * src/gdbserver.c (gdb_extract_hex_num): Correctly handle multi-byte, little-endian register numbers. Index: src/gdbserver.c =================================================================== RCS file: /home/cvsroot/simulavr/src/gdbserver.c,v retrieving revision 1.49 diff -u -p -p -r1.49 gdbserver.c --- src/gdbserver.c 2 Dec 2003 03:56:45 -0000 1.49 +++ src/gdbserver.c 19 Oct 2004 18:56:38 -0000 @@ -408,6 +408,8 @@ gdb_write_registers (GdbComm_T *comm, in char is reached or size of int is exceeded or a NULL is reached. pkt is modified to point to stop char when done. + The number in the packet is in little endian order. + Use this function to extract a num with an arbitrary num of hex digits. This should _not_ be used to extract n digits from a m len string of digits (n <= m). */ @@ -417,18 +419,27 @@ gdb_extract_hex_num (char **pkt, char st { int i = 0; int num = 0; + uint8_t bval = 0; char *p = *pkt; - int max_shifts = sizeof (int) * 2 - 1; /* max number of nibbles to shift - through */ + int max_shifts = sizeof (int) - 1; /* max number of bytes to shift + through */ while ((*p != stop) && (*p != '\0')) { if (i > max_shifts) avr_error ("number too large"); - num = (num << (i * 4)) | hex2nib (*p); - i++; - p++; + bval = hex2nib (*p++) << 4; + + if ((*p == stop) || (*p == '\0')) + { + avr_warning ("premature termination of hex num extraction"); + break; + } + + bval = bval | hex2nib (*p++); + + num |= bval << (i * 8); } *pkt = p;