diff --git a/sys/include/od.h b/sys/include/od.h index 1b0f84d537..6e58d1ce9d 100644 --- a/sys/include/od.h +++ b/sys/include/od.h @@ -36,15 +36,36 @@ extern "C" { /** * @brief Dumps memory stored at *data* byte-wise up to *data_len* in * hexadecimal representation to stdout. If the pseudomodlue `od_string` - is used (`USEMODULE += od_string`) the ASCII representation of *data* is - also displayed. + * is used (`USEMODULE += od_string`) the ASCII representation of *data* is + * also displayed. + * The displayed start address of *data* can be given as *offset*. + * + * @param[in] data Data to dump. + * @param[in] data_len Length in bytes of *data* to output. + * @param[in] width Number of bytes per line. If *width* is 0, + * @ref OD_WIDTH_DEFAULT is assumed as a default value. + * @param[in] offset Adds an offset to the printed memory addresses. + * If the origin of the data is an address in memory, + * this can be used to print the real addresses together + * with the data. + */ +void od_hex_dump_ext(const void *data, size_t data_len, uint8_t width, uint32_t offset); + +/** + * @brief Dumps memory stored at *data* byte-wise up to *data_len* in + * hexadecimal representation to stdout. If the pseudomodlue `od_string` + * is used (`USEMODULE += od_string`) the ASCII representation of *data* is + * also displayed. * * @param[in] data Data to dump. * @param[in] data_len Length in bytes of *data* to output. * @param[in] width Number of bytes per line. If *width* is 0, * @ref OD_WIDTH_DEFAULT is assumed as a default value. */ -void od_hex_dump(const void *data, size_t data_len, uint8_t width); +static inline void od_hex_dump(const void *data, size_t data_len, uint8_t width) +{ + od_hex_dump_ext(data, data_len, width, 0); +} #ifdef __cplusplus } diff --git a/sys/od/od.c b/sys/od/od.c index b95080170a..92dc2be7b7 100644 --- a/sys/od/od.c +++ b/sys/od/od.c @@ -20,9 +20,9 @@ #include "od.h" -void od_hex_dump(const void *data, size_t data_len, uint8_t width) +void od_hex_dump_ext(const void *data, size_t data_len, uint8_t width, uint32_t offset) { - print_str("00000000"); + print_u32_hex(offset); if (width == 0) { width = OD_WIDTH_DEFAULT; @@ -41,11 +41,11 @@ void od_hex_dump(const void *data, size_t data_len, uint8_t width) print_str(" "); } print_str(" "); - for(unsigned k = 0; k < (i % width) + 1; k++){ - if(isprint(((uint8_t *)data)[str_pos+k])){ + for (unsigned k = 0; k < (i % width) + 1; k++){ + if (isprint(((uint8_t *)data)[str_pos+k])) { putchar(((uint8_t *)data)[str_pos+k]); } - else{ + else { putchar('.'); } } @@ -55,7 +55,7 @@ void od_hex_dump(const void *data, size_t data_len, uint8_t width) putchar('\n'); if (i != (data_len - 1)) { - print_u32_hex((uint32_t)(i + 1)); + print_u32_hex((uint32_t)(offset + i + 1)); } } } diff --git a/tests/od/main.c b/tests/od/main.c index 2d77cfdd92..2204bf1a9e 100644 --- a/tests/od/main.c +++ b/tests/od/main.c @@ -37,6 +37,7 @@ int main(void) CALL(od_hex_dump(long_str, sizeof(long_str), 4)); CALL(od_hex_dump(long_str, sizeof(long_str), 3)); CALL(od_hex_dump(long_str, sizeof(long_str), 8)); + CALL(od_hex_dump_ext(long_str, sizeof(long_str), 8, 0x100)); return 0; } diff --git a/tests/od/tests/01-run.py b/tests/od/tests/01-run.py index a9de23120b..0334fe6d9c 100755 --- a/tests/od/tests/01-run.py +++ b/tests/od/tests/01-run.py @@ -35,6 +35,10 @@ def testfunc(child): child.expect_exact("00000000 FF 2C 61 FF 2E 62 63 64 .,a..bcd") child.expect_exact("00000008 65 66 67 68 69 6A 6B 6C efghijkl") child.expect_exact("00000010 6D 6E 6F 70 00 mnop.") + child.expect_exact("od_hex_dump_ext(long_str, sizeof(long_str), 8, 0x100)") + child.expect_exact("00000100 FF 2C 61 FF 2E 62 63 64 .,a..bcd") + child.expect_exact("00000108 65 66 67 68 69 6A 6B 6C efghijkl") + child.expect_exact("00000110 6D 6E 6F 70 00 mnop.") print("All tests successful")