1 1.1 christos /* Low-level RSP routines for GDB, the GNU debugger. 2 1.1 christos 3 1.1.1.5 christos Copyright (C) 1988-2025 Free Software Foundation, Inc. 4 1.1 christos 5 1.1 christos This file is part of GDB. 6 1.1 christos 7 1.1 christos This program is free software; you can redistribute it and/or modify 8 1.1 christos it under the terms of the GNU General Public License as published by 9 1.1 christos the Free Software Foundation; either version 3 of the License, or 10 1.1 christos (at your option) any later version. 11 1.1 christos 12 1.1 christos This program is distributed in the hope that it will be useful, 13 1.1 christos but WITHOUT ANY WARRANTY; without even the implied warranty of 14 1.1 christos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 1.1 christos GNU General Public License for more details. 16 1.1 christos 17 1.1 christos You should have received a copy of the GNU General Public License 18 1.1 christos along with this program. If not, see <http://www.gnu.org/licenses/>. */ 19 1.1 christos 20 1.1.1.4 christos #ifndef GDBSUPPORT_RSP_LOW_H 21 1.1.1.4 christos #define GDBSUPPORT_RSP_LOW_H 22 1.1 christos 23 1.1 christos /* Convert number NIB to a hex digit. */ 24 1.1 christos 25 1.1 christos extern int tohex (int nib); 26 1.1 christos 27 1.1 christos /* Write a character representing the low order four bits of NIBBLE in 28 1.1 christos hex to *BUF. Returns BUF+1. */ 29 1.1 christos 30 1.1 christos extern char *pack_nibble (char *buf, int nibble); 31 1.1 christos 32 1.1 christos /* Write the low byte of BYTE in hex to *BUF. Returns BUF+2. */ 33 1.1 christos 34 1.1 christos extern char *pack_hex_byte (char *pkt, int byte); 35 1.1 christos 36 1.1 christos /* Read hex digits from BUFF and convert to a number, which is stored 37 1.1 christos in RESULT. Reads until a non-hex digit is seen. Returns a pointer 38 1.1 christos to the terminating character. */ 39 1.1 christos 40 1.1 christos extern const char *unpack_varlen_hex (const char *buff, ULONGEST *result); 41 1.1 christos 42 1.1 christos /* Like hex2bin, but return a std::string. */ 43 1.1 christos 44 1.1 christos extern std::string hex2str (const char *hex); 45 1.1 christos 46 1.1 christos /* Like hex2bin, but return a std::string. */ 47 1.1 christos 48 1.1 christos extern std::string hex2str (const char *hex, int count); 49 1.1 christos 50 1.1 christos /* Convert some bytes to a hexadecimal representation. BIN holds the 51 1.1 christos bytes to convert. COUNT says how many bytes to convert. The 52 1.1 christos resulting characters are stored in HEX, followed by a NUL 53 1.1 christos character. Returns the number of bytes actually converted. */ 54 1.1 christos 55 1.1 christos extern int bin2hex (const gdb_byte *bin, char *hex, int count); 56 1.1 christos 57 1.1.1.3 christos extern int bin2hex (gdb::array_view<gdb_byte> bin, char *hex); 58 1.1.1.3 christos 59 1.1 christos /* Overloaded version of bin2hex that returns a std::string. */ 60 1.1 christos 61 1.1 christos extern std::string bin2hex (const gdb_byte *bin, int count); 62 1.1 christos 63 1.1 christos /* Convert BUFFER, binary data at least LEN_UNITS addressable memory units 64 1.1 christos long, into escaped binary data in OUT_BUF. Only copy memory units that fit 65 1.1 christos completely in OUT_BUF. Set *OUT_LEN_UNITS to the number of units from 66 1.1 christos BUFFER successfully encoded in OUT_BUF, and return the number of bytes used 67 1.1 christos in OUT_BUF. The total number of bytes in the output buffer will be at most 68 1.1 christos OUT_MAXLEN_BYTES. This function properly escapes '*', and so is suitable 69 1.1 christos for the server side as well as the client. */ 70 1.1 christos 71 1.1 christos extern int remote_escape_output (const gdb_byte *buffer, int len_units, 72 1.1 christos int unit_size, gdb_byte *out_buf, 73 1.1 christos int *out_len_units, int out_maxlen_bytes); 74 1.1 christos 75 1.1 christos /* Convert BUFFER, escaped data LEN bytes long, into binary data 76 1.1 christos in OUT_BUF. Return the number of bytes written to OUT_BUF. 77 1.1 christos Raise an error if the total number of bytes exceeds OUT_MAXLEN. 78 1.1 christos 79 1.1 christos This function reverses remote_escape_output. */ 80 1.1 christos 81 1.1 christos extern int remote_unescape_input (const gdb_byte *buffer, int len, 82 1.1 christos gdb_byte *out_buf, int out_maxlen); 83 1.1 christos 84 1.1.1.4 christos #endif /* GDBSUPPORT_RSP_LOW_H */ 85