From 58aa0da3154306058b3abd44a2e0a81848d18ce2 Mon Sep 17 00:00:00 2001 From: Oleg Hahm Date: Sun, 2 Mar 2014 23:24:40 +0000 Subject: [PATCH 1/6] added missing ENABLE_DEBUG define in mutex.c --- core/mutex.c | 1 + 1 file changed, 1 insertion(+) diff --git a/core/mutex.c b/core/mutex.c index ee4b108f13..d2756e4ef3 100644 --- a/core/mutex.c +++ b/core/mutex.c @@ -29,6 +29,7 @@ #include "thread.h" #include "irq.h" +#define ENABLE_DEBUG (0) #include "debug.h" int mutex_init(struct mutex_t *mutex) From 6e7e92ee5a73842f2dae89829db3820a4034407e Mon Sep 17 00:00:00 2001 From: Oleg Hahm Date: Sun, 2 Mar 2014 23:25:38 +0000 Subject: [PATCH 2/6] more debug for rpl_udp example --- examples/rpl_udp/rpl.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/examples/rpl_udp/rpl.c b/examples/rpl_udp/rpl.c index 13f9fdd065..37d23ee4a2 100644 --- a/examples/rpl_udp/rpl.c +++ b/examples/rpl_udp/rpl.c @@ -29,6 +29,9 @@ #include "rpl_dodag.h" #include "demo.h" +#define ENABLE_DEBUG (0) +#include "debug.h" + #ifdef MODULE_NATIVENET #define TRANSCEIVER TRANSCEIVER_NATIVE #else @@ -65,8 +68,10 @@ void rpl_udp_init(int argc, char **argv) return; } + DEBUG("%s, %d: Setting HW address to %u\n", __FILE__, __LINE__, id); net_if_set_hardware_address(0, id); + DEBUG("%s, %d: Initializing RPL for interface 0\n", __FILE__, __LINE__); state = rpl_init(0); if (state != SIXLOWERROR_SUCCESS) { @@ -84,7 +89,9 @@ void rpl_udp_init(int argc, char **argv) ipv6_iface_set_routing_provider(rpl_get_next_hop); } + DEBUG("%s, %d: Start monitor\n", __FILE__, __LINE__); int monitor_pid = thread_create(monitor_stack_buffer, MONITOR_STACK_SIZE, PRIORITY_MAIN - 2, CREATE_STACKTEST, rpl_udp_monitor, "monitor"); + DEBUG("%s, %d: Register at transceiver %02X\n", __FILE__, __LINE__, TRANSCEIVER); transceiver_register(TRANSCEIVER, monitor_pid); ipv6_register_packet_handler(monitor_pid); //sixlowpan_lowpan_register(monitor_pid); From 2ef9b78ccfa11bcec85284264fdae56300319e33 Mon Sep 17 00:00:00 2001 From: Oleg Hahm Date: Sun, 2 Mar 2014 23:25:09 +0000 Subject: [PATCH 3/6] add stacksize checker for DEBUG macro --- core/include/debug.h | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/core/include/debug.h b/core/include/debug.h index 06abdbe9f2..39ec14a6c8 100644 --- a/core/include/debug.h +++ b/core/include/debug.h @@ -24,8 +24,24 @@ #include +#if DEVELHELP +#include "sched.h" +#include "cpu-conf.h" +#define DEBUG_PRINT(...) \ + do { \ + if (active_thread->stack_size > KERNEL_CONF_STACKSIZE_PRINTF) { \ + printf(__VA_ARGS__); \ + } \ + else { \ + puts("Cannot debug, stack too small"); \ + } \ + } while (0) +#else +#define DEBUG_PRINT(...) printf(__VA_ARGS__) +#endif + #if ENABLE_DEBUG -#define DEBUG(...) printf(__VA_ARGS__) +#define DEBUG(...) DEBUG_PRINT(__VA_ARGS__) #undef ENABLE_DEBUG #else #define DEBUG(...) From 20b52304661dd620f48f3e11b7231f6dc2dd60c5 Mon Sep 17 00:00:00 2001 From: Oleg Hahm Date: Mon, 3 Mar 2014 09:37:50 +0000 Subject: [PATCH 4/6] additional debug macro --- core/include/debug.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/core/include/debug.h b/core/include/debug.h index 39ec14a6c8..f8d8b21016 100644 --- a/core/include/debug.h +++ b/core/include/debug.h @@ -23,9 +23,9 @@ #define __DEBUG_H #include +#include "sched.h" #if DEVELHELP -#include "sched.h" #include "cpu-conf.h" #define DEBUG_PRINT(...) \ do { \ @@ -41,10 +41,18 @@ #endif #if ENABLE_DEBUG +#include "tcb.h" #define DEBUG(...) DEBUG_PRINT(__VA_ARGS__) +#define DEBUGF(...) \ + do { \ + DEBUG_PRINT("DEBUG(%s): %s:%d in %s: ", \ + active_thread->name, __FILE__, __LINE__, __func__); \ + DEBUG_PRINT(__VA_ARGS__); \ + } while (0) #undef ENABLE_DEBUG #else #define DEBUG(...) +#define DEBUGF(...) #endif /** @} */ From 1c67af2ddd36c7c20dc9130dad2dbeeb97fd10fb Mon Sep 17 00:00:00 2001 From: Oleg Hahm Date: Mon, 3 Mar 2014 09:59:19 +0000 Subject: [PATCH 5/6] using DEBUGF where reasonable --- examples/rpl_udp/helper.c | 4 ++-- examples/rpl_udp/rpl.c | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/rpl_udp/helper.c b/examples/rpl_udp/helper.c index d5282b948e..1288ca87c7 100644 --- a/examples/rpl_udp/helper.c +++ b/examples/rpl_udp/helper.c @@ -29,7 +29,7 @@ #include "demo.h" -#define ENABLE_DEBUG (1) +#define ENABLE_DEBUG (0) #include "debug.h" #define LL_HDR_LEN (0x4) @@ -69,7 +69,7 @@ void rpl_udp_monitor(void) if (m.type == PKT_PENDING) { p = (radio_packet_t *) m.content.ptr; - DEBUG("Received packet from ID %u\n", p->src); + DEBUGF("Received packet from ID %u\n", p->src); DEBUG("\tLength:\t%u\n", p->length); DEBUG("\tSrc:\t%u\n", p->src); DEBUG("\tDst:\t%u\n", p->dst); diff --git a/examples/rpl_udp/rpl.c b/examples/rpl_udp/rpl.c index 37d23ee4a2..f4d682cd4c 100644 --- a/examples/rpl_udp/rpl.c +++ b/examples/rpl_udp/rpl.c @@ -68,10 +68,10 @@ void rpl_udp_init(int argc, char **argv) return; } - DEBUG("%s, %d: Setting HW address to %u\n", __FILE__, __LINE__, id); + DEBUGF("Setting HW address to %u\n", id); net_if_set_hardware_address(0, id); - DEBUG("%s, %d: Initializing RPL for interface 0\n", __FILE__, __LINE__); + DEBUGF("Initializing RPL for interface 0\n"); state = rpl_init(0); if (state != SIXLOWERROR_SUCCESS) { @@ -89,9 +89,9 @@ void rpl_udp_init(int argc, char **argv) ipv6_iface_set_routing_provider(rpl_get_next_hop); } - DEBUG("%s, %d: Start monitor\n", __FILE__, __LINE__); + DEBUGF("Start monitor\n"); int monitor_pid = thread_create(monitor_stack_buffer, MONITOR_STACK_SIZE, PRIORITY_MAIN - 2, CREATE_STACKTEST, rpl_udp_monitor, "monitor"); - DEBUG("%s, %d: Register at transceiver %02X\n", __FILE__, __LINE__, TRANSCEIVER); + DEBUGF("Register at transceiver %02X\n", TRANSCEIVER); transceiver_register(TRANSCEIVER, monitor_pid); ipv6_register_packet_handler(monitor_pid); //sixlowpan_lowpan_register(monitor_pid); From 85bd8cae17156fd6afe4b71e307897c02d9f246b Mon Sep 17 00:00:00 2001 From: Oleg Hahm Date: Wed, 19 Mar 2014 14:22:26 +0100 Subject: [PATCH 6/6] check for existence of active_thread --- core/include/debug.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/core/include/debug.h b/core/include/debug.h index f8d8b21016..2619524a39 100644 --- a/core/include/debug.h +++ b/core/include/debug.h @@ -29,7 +29,7 @@ #include "cpu-conf.h" #define DEBUG_PRINT(...) \ do { \ - if (active_thread->stack_size > KERNEL_CONF_STACKSIZE_PRINTF) { \ + if ((active_thread == NULL) || (active_thread->stack_size > KERNEL_CONF_STACKSIZE_PRINTF)) { \ printf(__VA_ARGS__); \ } \ else { \ @@ -46,7 +46,8 @@ #define DEBUGF(...) \ do { \ DEBUG_PRINT("DEBUG(%s): %s:%d in %s: ", \ - active_thread->name, __FILE__, __LINE__, __func__); \ + active_thread ? active_thread->name : "NO THREAD", \ + __FILE__, __LINE__, __func__); \ DEBUG_PRINT(__VA_ARGS__); \ } while (0) #undef ENABLE_DEBUG