28 if (a >=
'0' && a <=
'9')
30 else if (a >=
'a' && a <=
'f')
32 else if (a >=
'A' && a <=
'F')
35 error (
_(
"Reply contains invalid hex digit %d"), a);
46 return 'a' + nib - 10;
51 static const char hexchars[] =
"0123456789abcdef";
56 if ((ch >=
'a') && (ch <=
'f'))
61 if ((ch >=
'A') && (ch <=
'F'))
66 if ((ch >=
'0') && (ch <=
'9'))
88 *pkt++ =
hexchars[(byte >> 4) & 0xf];
102 while (
ishex (*buff, &nibble))
105 retval = retval << 4;
106 retval |= nibble & 0x0f;
119 for (i = 0; i < count; i++)
121 if (hex[0] == 0 || hex[1] == 0)
140 for (i = 0; i < count; i++)
142 *hex++ =
tohex ((*bin >> 4) & 0xf);
143 *hex++ =
tohex (*bin++ & 0xf);
154 return b ==
'$' || b ==
'#' || b ==
'}' || b ==
'*';
161 gdb_byte *out_buf,
int *out_len_units,
162 int out_maxlen_bytes)
164 int input_unit_index, output_byte_index = 0, byte_index_in_unit;
165 int number_escape_bytes_needed;
170 for (input_unit_index = 0;
171 input_unit_index < len_units;
175 number_escape_bytes_needed = 0;
176 for (byte_index_in_unit = 0;
177 byte_index_in_unit < unit_size;
178 byte_index_in_unit++)
180 int idx = input_unit_index * unit_size + byte_index_in_unit;
183 number_escape_bytes_needed++;
187 if (output_byte_index + unit_size + number_escape_bytes_needed >
192 for (byte_index_in_unit = 0;
193 byte_index_in_unit < unit_size;
194 byte_index_in_unit++)
196 int idx = input_unit_index * unit_size + byte_index_in_unit;
200 out_buf[output_byte_index++] =
'}';
201 out_buf[output_byte_index++] = b ^ 0x20;
204 out_buf[output_byte_index++] = b;
208 *out_len_units = input_unit_index;
209 return output_byte_index;
218 int input_index, output_index;
223 for (input_index = 0; input_index <
len; input_index++)
227 if (output_index + 1 > out_maxlen)
228 error (
_(
"Received too much data from the target."));
232 out_buf[output_index++] = b ^ 0x20;
238 out_buf[output_index++] = b;
242 error (
_(
"Unmatched escape character in target response."));
int remote_unescape_input(const gdb_byte *buffer, int len, gdb_byte *out_buf, int out_maxlen)
int bin2hex(const gdb_byte *bin, char *hex, int count)
int remote_escape_output(const gdb_byte *buffer, int len_units, int unit_size, gdb_byte *out_buf, int *out_len_units, int out_maxlen_bytes)
char * pack_nibble(char *buf, int nibble)
char * unpack_varlen_hex(char *buff, ULONGEST *result)
char * pack_hex_byte(char *pkt, int byte)
static const char hexchars[]
unsigned long long ULONGEST
static int needs_escaping(gdb_byte b)
int hex2bin(const char *hex, gdb_byte *bin, int count)
void error(const char *fmt,...)
static int ishex(int ch, int *val)
const ULONGEST const LONGEST len