debug: gdbstub: introduce gdb_bin2hex()

Adds a new function gdb_bin2hex() to convert binary into
hexadecimal string representation. This is similar to
bin2hex() but does not force a null character at the end
of the output buffer. This avoids an issue where the last
character of the hexadecimal string is replaced with
null character before sending to GDB.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
This commit is contained in:
Daniel Leung 2021-10-25 10:33:08 -07:00 committed by Anas Nashif
commit 6eaaaa9acc
2 changed files with 37 additions and 3 deletions

View file

@ -15,4 +15,20 @@
#define GDB_EXCEPTION_INVALID_MEMORY 11UL
#define GDB_EXCEPTION_OVERFLOW 16UL
/**
* @brief Convert a binary array into string representation.
*
* Note that this is similar to bin2hex() but does not force
* a null character at the end of the hexadeciaml output buffer.
*
* @param buf The binary array to convert
* @param buflen The length of the binary array to convert
* @param hex Address of where to store the string representation.
* @param hexlen Size of the storage area for string representation.
*
* @return The length of the converted string, or 0 if an error occurred.
*/
size_t gdb_bin2hex(const uint8_t *buf, size_t buflen,
char *hex, size_t hexlen);
#endif