diff options
author | Tom Tromey <tromey@redhat.com> | 2014-01-18 14:32:47 -0700 |
---|---|---|
committer | Tom Tromey <tromey@redhat.com> | 2014-02-12 09:59:14 -0700 |
commit | 9c3d65319a230a106392e4b67c8c89c8f5e2929f (patch) | |
tree | 857987f9c4847e816d518f3641ba091d07a768e4 /gdb/remote.c | |
parent | 01fd3ea573324b8248efbb236d994420641e3d32 (diff) | |
download | gdb-9c3d65319a230a106392e4b67c8c89c8f5e2929f.zip gdb-9c3d65319a230a106392e4b67c8c89c8f5e2929f.tar.gz gdb-9c3d65319a230a106392e4b67c8c89c8f5e2929f.tar.bz2 |
move some rsp bits into rsp-low.h
This moves various low-level remote serial protocol bits into
common/rsp-low.[ch].
This is as close to a pure move as possible. There are some
redundancies remaining but those will be dealt with in a subsequent
patch.
Note that the two variants of remote_escape_output disagreed on the
treatment of "*". On the theory that quoting cannot hurt but the
absence possibly can, I chose the gdbserver variant to be the
canonical one.
2014-02-12 Tom Tromey <tromey@redhat.com>
* tracepoint.c: Include rsp-low.h.
* remote.h (hex2bin, bin2hex, unpack_varlen_hex): Don't declare.
* remote.c: Include rsp-low.h.
(hexchars, ishex, unpack_varlen_hex, pack_nibble, pack_hex_byte)
(fromhex, hex2bin, tohex, bin2hex, remote_escape_output)
(remote_unescape_input): Move to common/rsp-low.c.
* common/rsp-low.h: New file.
* common/rsp-low.c: New file.
* Makefile.in (SFILES): Add common/rsp-low.c.
(HFILES_NO_SRCDIR): Add common/rsp-low.h.
(COMMON_OBS): Add rsp-low.o.
(rsp-low.o): New target.
2014-02-12 Tom Tromey <tromey@redhat.com>
* tracepoint.c: Include rsp-low.h.
* server.c: Include rsp-low.h.
* remote-utils.h (convert_ascii_to_int, convert_int_to_ascii)
(unhexify, hexify, remote_escape_output, unpack_varlen_hex): Don't
declare.
* remote-utils.c: Include rsp-low.h.
(fromhex, hexchars, ishex, unhexify, tohex, hexify)
(remote_escape_output, remote_unescape_input, unpack_varlen_hex)
(convert_int_to_ascii, convert_ascii_to_int): Move to
common/rsp-low.c.
* regcache.c: Include rsp-low.h.
* ax.c: Include rsp-low.h.
* Makefile.in (SFILES): Add common/rsp-low.c.
(OBS): Add rsp-low.o.
(rsp-low.o): New target.
Diffstat (limited to 'gdb/remote.c')
-rw-r--r-- | gdb/remote.c | 217 |
1 files changed, 1 insertions, 216 deletions
diff --git a/gdb/remote.c b/gdb/remote.c index eff4c44..eaaeb74 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -45,6 +45,7 @@ #include "target-descriptions.h" #include "gdb_bfd.h" #include "filestuff.h" +#include "rsp-low.h" #include <sys/time.h> @@ -124,8 +125,6 @@ static void remote_serial_write (const char *str, int len); static void remote_kill (struct target_ops *ops); -static int tohex (int nib); - static int remote_can_async_p (void); static int remote_is_async_p (void); @@ -154,8 +153,6 @@ static void init_extended_remote_ops (void); static void remote_stop (ptid_t); -static int ishex (int ch, int *val); - static int stubhex (int ch); static int hexnumstr (char *, ULONGEST); @@ -176,8 +173,6 @@ static ptid_t remote_current_thread (ptid_t oldptid); static void remote_find_new_threads (void); -static int fromhex (int a); - static int putpkt_binary (char *buf, int cnt); static void check_binary_download (CORE_ADDR addr); @@ -1937,14 +1932,8 @@ struct gdb_ext_thread_info #define BUF_THREAD_ID_SIZE (OPAQUETHREADBYTES * 2) -char *unpack_varlen_hex (char *buff, ULONGEST *result); - static char *unpack_nibble (char *buf, int *val); -static char *pack_nibble (char *buf, int nibble); - -static char *pack_hex_byte (char *pkt, int /* unsigned char */ byte); - static char *unpack_byte (char *buf, int *value); static char *pack_int (char *buf, int value); @@ -2071,31 +2060,6 @@ read_ptid (char *buf, char **obuf) return ptid_build (pid, 0, tid); } -/* Encode 64 bits in 16 chars of hex. */ - -static const char hexchars[] = "0123456789abcdef"; - -static int -ishex (int ch, int *val) -{ - if ((ch >= 'a') && (ch <= 'f')) - { - *val = ch - 'a' + 10; - return 1; - } - if ((ch >= 'A') && (ch <= 'F')) - { - *val = ch - 'A' + 10; - return 1; - } - if ((ch >= '0') && (ch <= '9')) - { - *val = ch - '0'; - return 1; - } - return 0; -} - static int stubhex (int ch) { @@ -2125,23 +2089,6 @@ stub_unpack_int (char *buff, int fieldlength) return retval; } -char * -unpack_varlen_hex (char *buff, /* packet to parse */ - ULONGEST *result) -{ - int nibble; - ULONGEST retval = 0; - - while (ishex (*buff, &nibble)) - { - buff++; - retval = retval << 4; - retval |= nibble & 0x0f; - } - *result = retval; - return buff; -} - static char * unpack_nibble (char *buf, int *val) { @@ -2150,21 +2097,6 @@ unpack_nibble (char *buf, int *val) } static char * -pack_nibble (char *buf, int nibble) -{ - *buf++ = hexchars[(nibble & 0x0f)]; - return buf; -} - -static char * -pack_hex_byte (char *pkt, int byte) -{ - *pkt++ = hexchars[(byte >> 4) & 0xf]; - *pkt++ = hexchars[(byte & 0xf)]; - return pkt; -} - -static char * unpack_byte (char *buf, int *value) { *value = stub_unpack_int (buf, 2); @@ -4665,68 +4597,6 @@ extended_remote_attach (struct target_ops *ops, char *args, int from_tty) extended_remote_attach_1 (ops, args, from_tty); } -/* Convert hex digit A to a number. */ - -static int -fromhex (int a) -{ - if (a >= '0' && a <= '9') - return a - '0'; - else if (a >= 'a' && a <= 'f') - return a - 'a' + 10; - else if (a >= 'A' && a <= 'F') - return a - 'A' + 10; - else - error (_("Reply contains invalid hex digit %d"), a); -} - -int -hex2bin (const char *hex, gdb_byte *bin, int count) -{ - int i; - - for (i = 0; i < count; i++) - { - if (hex[0] == 0 || hex[1] == 0) - { - /* Hex string is short, or of uneven length. - Return the count that has been converted so far. */ - return i; - } - *bin++ = fromhex (hex[0]) * 16 + fromhex (hex[1]); - hex += 2; - } - return i; -} - -/* Convert number NIB to a hex digit. */ - -static int -tohex (int nib) -{ - if (nib < 10) - return '0' + nib; - else - return 'a' + nib - 10; -} - -int -bin2hex (const gdb_byte *bin, char *hex, int count) -{ - int i; - - /* May use a length, or a nul-terminated string as input. */ - if (count == 0) - count = strlen ((char *) bin); - - for (i = 0; i < count; i++) - { - *hex++ = tohex ((*bin >> 4) & 0xf); - *hex++ = tohex (*bin++ & 0xf); - } - *hex = 0; - return i; -} /* Check for the availability of vCont. This function should also check the response. */ @@ -6679,91 +6549,6 @@ remote_address_masked (CORE_ADDR addr) return addr; } -/* Convert BUFFER, binary data at least LEN bytes long, into escaped - binary data in OUT_BUF. Set *OUT_LEN to the length of the data - encoded in OUT_BUF, and return the number of bytes in OUT_BUF - (which may be more than *OUT_LEN due to escape characters). The - total number of bytes in the output buffer will be at most - OUT_MAXLEN. */ - -static int -remote_escape_output (const gdb_byte *buffer, int len, - gdb_byte *out_buf, int *out_len, - int out_maxlen) -{ - int input_index, output_index; - - output_index = 0; - for (input_index = 0; input_index < len; input_index++) - { - gdb_byte b = buffer[input_index]; - - if (b == '$' || b == '#' || b == '}') - { - /* These must be escaped. */ - if (output_index + 2 > out_maxlen) - break; - out_buf[output_index++] = '}'; - out_buf[output_index++] = b ^ 0x20; - } - else - { - if (output_index + 1 > out_maxlen) - break; - out_buf[output_index++] = b; - } - } - - *out_len = input_index; - return output_index; -} - -/* Convert BUFFER, escaped data LEN bytes long, into binary data - in OUT_BUF. Return the number of bytes written to OUT_BUF. - Raise an error if the total number of bytes exceeds OUT_MAXLEN. - - This function reverses remote_escape_output. It allows more - escaped characters than that function does, in particular because - '*' must be escaped to avoid the run-length encoding processing - in reading packets. */ - -static int -remote_unescape_input (const gdb_byte *buffer, int len, - gdb_byte *out_buf, int out_maxlen) -{ - int input_index, output_index; - int escaped; - - output_index = 0; - escaped = 0; - for (input_index = 0; input_index < len; input_index++) - { - gdb_byte b = buffer[input_index]; - - if (output_index + 1 > out_maxlen) - { - warning (_("Received too much data from remote target;" - " ignoring overflow.")); - return output_index; - } - - if (escaped) - { - out_buf[output_index++] = b ^ 0x20; - escaped = 0; - } - else if (b == '}') - escaped = 1; - else - out_buf[output_index++] = b; - } - - if (escaped) - error (_("Unmatched escape character in target response.")); - - return output_index; -} - /* Determine whether the remote target supports binary downloading. This is accomplished by sending a no-op memory write of zero length to the target at the specified address. It does not suffice to send |