mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
sys/od: allow to specify address offset with od_hex_dump_ext()
When dumping memory the printed addresses always start with `00000000`. This can be very confusing and lead to errors. Allow the user to specify a starting address of the printed memory that will be used instead. By introducing a wrapper function, existing users are unaffected.
This commit is contained in:
parent
6b233f6403
commit
89c97ae59a
@ -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
|
||||
}
|
||||
|
12
sys/od/od.c
12
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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")
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user