From 6a8919c637b28fab7cc6f8e87cfca6f13bb8cb1d Mon Sep 17 00:00:00 2001 From: Christoph Lipka Date: Tue, 26 Jan 2016 16:09:21 +0900 Subject: DLT_PTR: User macro to print pointers This macro internally checks the size of a void pointer to decide if the pointer address is sent with DLT_HEX32 or DLT_HEX64 macro. Signed-off-by: Christoph Lipka Change-Id: Ie316ac411f2174e0760e09244d04b83c8006f55d --- include/dlt/dlt_user_macros.h | 12 ++++++++++++ src/tests/dlt-test-user.c | 5 +++++ 2 files changed, 17 insertions(+) diff --git a/include/dlt/dlt_user_macros.h b/include/dlt/dlt_user_macros.h index 3bb161f..919df7e 100644 --- a/include/dlt/dlt_user_macros.h +++ b/include/dlt/dlt_user_macros.h @@ -327,6 +327,18 @@ #define DLT_BIN16(UINT_VAR) \ (void)dlt_user_log_write_uint16_formatted(&log_local,UINT_VAR,DLT_FORMAT_BIN16) +/** + * Architecture independent macro to print pointers + */ +#define DLT_PTR(PTR_VAR) \ + do { \ + if (sizeof(void *) < 8) { \ + DLT_HEX32((uintptr_t)PTR_VAR); \ + } else { \ + DLT_HEX64((uintptr_t)PTR_VAR); \ + } \ + } while(0) + /** * Trace network message * @param CONTEXT object containing information about one special logging context diff --git a/src/tests/dlt-test-user.c b/src/tests/dlt-test-user.c index 80614e0..16479a2 100644 --- a/src/tests/dlt-test-user.c +++ b/src/tests/dlt-test-user.c @@ -479,6 +479,8 @@ int test5m(void) char buffer[32]; int num; + void *ptr = malloc(sizeof(int)); + for(num=0;num<32;num++) { buffer[num] = num; @@ -506,10 +508,13 @@ int test5m(void) DLT_LOG(context_macro_test[4],DLT_LOG_INFO,DLT_STRING("Next line: DLT_LOG_STRING_UINT")); DLT_LOG_STRING_UINT(context_macro_test[4], DLT_LOG_INFO,"String output: ", 42); + DLT_LOG(context_macro_test[4],DLT_LOG_INFO,DLT_STRING("Next line: DLT_LOG_PTR")); + DLT_LOG(context_macro_test[4],DLT_LOG_INFO,DLT_PTR(ptr)); /* wait 2 second before next test */ sleep(2); DLT_LOG(context_info,DLT_LOG_INFO,DLT_STRING("Test5: (Macro IF) finished")); + free(ptr); return 0; } -- cgit v1.2.1