2013-11-27 16:28:31 +01:00
|
|
|
/*
|
2014-04-01 11:46:21 +02:00
|
|
|
* Copyright (C) 2014 Freie Universität Berlin
|
2010-09-22 15:10:42 +02:00
|
|
|
*
|
2014-08-23 15:43:13 +02:00
|
|
|
* This file is subject to the terms and conditions of the GNU Lesser
|
|
|
|
* General Public License v2.1. See the file LICENSE in the top level
|
|
|
|
* directory for more details.
|
2013-11-27 16:28:31 +01:00
|
|
|
*/
|
2014-02-11 18:15:43 +01:00
|
|
|
|
2013-11-27 16:28:31 +01:00
|
|
|
/**
|
|
|
|
* @addtogroup core_util
|
2010-09-22 15:10:42 +02:00
|
|
|
* @{
|
2013-11-27 16:28:31 +01:00
|
|
|
*
|
|
|
|
* @file debug.h
|
|
|
|
* @brief Debug-header
|
|
|
|
*
|
|
|
|
* #define ENABLE_DEBUG, include this and then use DEBUG as printf you can toggle.
|
|
|
|
*
|
2014-01-28 11:50:12 +01:00
|
|
|
* @author Kaspar Schleiser <kaspar@schleiser.de>
|
2010-09-22 15:10:42 +02:00
|
|
|
*/
|
2014-02-11 18:15:43 +01:00
|
|
|
|
2013-11-27 16:28:31 +01:00
|
|
|
#ifndef __DEBUG_H
|
|
|
|
#define __DEBUG_H
|
2014-02-11 18:15:43 +01:00
|
|
|
|
2014-10-09 01:18:16 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2010-09-22 15:10:42 +02:00
|
|
|
#include <stdio.h>
|
2014-03-03 10:37:50 +01:00
|
|
|
#include "sched.h"
|
2010-09-22 15:10:42 +02:00
|
|
|
|
2014-04-01 11:46:21 +02:00
|
|
|
/**
|
|
|
|
* @name Print debug information if the calling thread stack is large enough
|
|
|
|
*
|
2014-05-27 16:26:47 +02:00
|
|
|
* Use this macro the same as `printf`. When `DEVELHELP` is defined inside an
|
|
|
|
* implementation file, all usages of `DEBUG_PRINT` will print the given
|
|
|
|
* information to std-out after verifying the stack is big enough. If `DEVELHELP`
|
|
|
|
* is not set, this check is not performed. (CPU exception may occur)
|
2014-04-01 11:46:21 +02:00
|
|
|
*
|
|
|
|
* @{
|
|
|
|
*/
|
2014-03-03 00:25:09 +01:00
|
|
|
#if DEVELHELP
|
|
|
|
#include "cpu-conf.h"
|
|
|
|
#define DEBUG_PRINT(...) \
|
|
|
|
do { \
|
2014-04-10 22:28:35 +02:00
|
|
|
if ((sched_active_thread == NULL) || (sched_active_thread->stack_size > KERNEL_CONF_STACKSIZE_PRINTF)) { \
|
2014-03-03 00:25:09 +01:00
|
|
|
printf(__VA_ARGS__); \
|
|
|
|
} \
|
|
|
|
else { \
|
|
|
|
puts("Cannot debug, stack too small"); \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
#else
|
|
|
|
#define DEBUG_PRINT(...) printf(__VA_ARGS__)
|
|
|
|
#endif
|
2014-04-01 11:46:21 +02:00
|
|
|
/** @} */
|
2014-03-03 00:25:09 +01:00
|
|
|
|
2014-04-01 11:46:21 +02:00
|
|
|
/**
|
|
|
|
* @brief Print debug information to std-out
|
|
|
|
*
|
|
|
|
* If *ENABLE_DEBUG* is defined inside an implementation file, all calls to
|
|
|
|
* *DEBUG* and *DEBUGF* will work the same as *printf* and output the given
|
|
|
|
* information to stdout. If *ENABLE_DEBUG* is not defined, all calls to
|
|
|
|
* *DEBUG* and *DEBUGF* will be ignored.
|
|
|
|
*
|
|
|
|
* In addition to just printing the given information *DEBUGF* will further
|
|
|
|
* print extended debug information about the current thread and function.
|
|
|
|
*
|
|
|
|
* @{
|
|
|
|
*/
|
2013-07-24 00:36:06 +02:00
|
|
|
#if ENABLE_DEBUG
|
2014-03-03 10:37:50 +01:00
|
|
|
#include "tcb.h"
|
2014-03-03 00:25:09 +01:00
|
|
|
#define DEBUG(...) DEBUG_PRINT(__VA_ARGS__)
|
2014-03-03 10:37:50 +01:00
|
|
|
#define DEBUGF(...) \
|
|
|
|
do { \
|
|
|
|
DEBUG_PRINT("DEBUG(%s): %s:%d in %s: ", \
|
2014-04-10 22:28:35 +02:00
|
|
|
sched_active_thread ? sched_active_thread->name : "NO THREAD", \
|
2014-03-19 14:22:26 +01:00
|
|
|
__FILE__, __LINE__, __func__); \
|
2014-03-03 10:37:50 +01:00
|
|
|
DEBUG_PRINT(__VA_ARGS__); \
|
|
|
|
} while (0)
|
2013-07-25 21:56:37 +02:00
|
|
|
#undef ENABLE_DEBUG
|
2010-09-22 15:10:42 +02:00
|
|
|
#else
|
|
|
|
#define DEBUG(...)
|
2014-03-03 10:37:50 +01:00
|
|
|
#define DEBUGF(...)
|
2010-09-22 15:10:42 +02:00
|
|
|
#endif
|
2013-11-27 16:28:31 +01:00
|
|
|
/** @} */
|
2014-04-01 11:46:21 +02:00
|
|
|
|
2014-10-09 01:18:16 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-11-27 16:28:31 +01:00
|
|
|
#endif /* __DEBUG_H */
|
2014-04-01 11:46:21 +02:00
|
|
|
/** @} */
|