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)
138 size_t bin_len = strlen (hex) / 2;
141 hex2bin (hex, bin.data (), bin_len);
152 size_t len = strlen (hex);
154 ret.reserve (len / 2);
155 for (
size_t i = 0; i < len; ++i)
157 if (hex[0] ==
'\0' || hex[1] ==
'\0')
177 for (i = 0; i < count; i++)
179 *hex++ =
tohex ((*bin >> 4) & 0xf);
180 *hex++ =
tohex (*bin++ & 0xf);
193 ret.reserve (count * 2);
194 for (
int i = 0; i < count; ++i)
196 ret +=
tohex ((*bin >> 4) & 0xf);
197 ret +=
tohex (*bin++ & 0xf);
208 return b ==
'$' || b ==
'#' || b ==
'}' || b ==
'*';
215 gdb_byte *out_buf,
int *out_len_units,
216 int out_maxlen_bytes)
218 int input_unit_index, output_byte_index = 0, byte_index_in_unit;
219 int number_escape_bytes_needed;
224 for (input_unit_index = 0;
225 input_unit_index < len_units;
229 number_escape_bytes_needed = 0;
230 for (byte_index_in_unit = 0;
231 byte_index_in_unit < unit_size;
232 byte_index_in_unit++)
234 int idx = input_unit_index * unit_size + byte_index_in_unit;
237 number_escape_bytes_needed++;
241 if (output_byte_index + unit_size + number_escape_bytes_needed >
246 for (byte_index_in_unit = 0;
247 byte_index_in_unit < unit_size;
248 byte_index_in_unit++)
250 int idx = input_unit_index * unit_size + byte_index_in_unit;
254 out_buf[output_byte_index++] =
'}';
255 out_buf[output_byte_index++] = b ^ 0x20;
258 out_buf[output_byte_index++] = b;
262 *out_len_units = input_unit_index;
263 return output_byte_index;
272 int input_index, output_index;
277 for (input_index = 0; input_index < len; input_index++)
281 if (output_index + 1 > out_maxlen)
282 error (
_(
"Received too much data from the target."));
286 out_buf[output_index++] = b ^ 0x20;
292 out_buf[output_index++] = b;
296 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)
std::string hex2str(const char *hex)
char * pack_hex_byte(char *pkt, int byte)
gdb::def_vector< gdb_byte > byte_vector
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)
const char * unpack_varlen_hex(const char *buff, ULONGEST *result)
void error(const char *fmt,...)
static int ishex(int ch, int *val)