Skip to content

Commit

Permalink
Add a function to help debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
NickeZ committed Feb 13, 2024
1 parent 5e81443 commit 6a7ba4d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ void util_uint8_to_hex(const uint8_t* in_bin, const size_t in_len, char* out)
rust_util_bytes(in_bin, in_len), rust_util_bytes_mut((uint8_t*)out, in_len * 2 + 1));
}

#if defined(SEMIHOSTING)
char* util_uint8_to_hex_alloc(const uint8_t* in_bin, const size_t in_len)
{
void* out = malloc(in_len * 2 + 1);
rust_util_uint8_to_hex(
rust_util_bytes(in_bin, in_len), rust_util_bytes_mut((uint8_t*)out, in_len * 2 + 1));
return (char*)out;
}
#endif

void util_cleanup_str(char** str)
{
util_zero(*str, strlens(*str));
Expand Down
4 changes: 4 additions & 0 deletions src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ void util_zero(volatile void* dst, size_t len);
// `out` must be of size in_len*2+1. Use BB_HEX_SIZE() to compute the size.
void util_uint8_to_hex(const uint8_t* in_bin, size_t in_len, char* out);

// This function is only compiled when we compile with SEMIHOSTING, it is convenient when debugging
// to print byte arrays as hex.
char* util_uint8_to_hex_alloc(const uint8_t* in_bin, size_t in_len);

#define BB_HEX_SIZE(in_bin) (sizeof((in_bin)) * 2 + 1)

void util_cleanup_str(char** str);
Expand Down

0 comments on commit 6a7ba4d

Please sign in to comment.