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
|
|
|
*
|
2015-05-22 07:34:41 +02:00
|
|
|
* @file
|
2013-11-27 16:28:31 +01:00
|
|
|
* @brief Debug-header
|
|
|
|
*
|
2015-04-21 09:45:21 +02:00
|
|
|
* @details 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.
|
2013-11-27 16:28:31 +01:00
|
|
|
*
|
2015-04-21 09:45:21 +02:00
|
|
|
* In addition to just printing the given information ::DEBUGF
|
|
|
|
* will further print extended debug information about the current
|
|
|
|
* thread and function.
|
|
|
|
*
|
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
|
|
|
|
2015-03-26 17:07:04 +01:00
|
|
|
#ifndef DEBUG_H
|
|
|
|
#define DEBUG_H
|
2014-02-11 18:15:43 +01:00
|
|
|
|
2014-10-13 14:44:28 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include "sched.h"
|
|
|
|
|
2014-10-09 01:18:16 +02:00
|
|
|
#ifdef __cplusplus
|
2015-02-10 19:56:01 +01:00
|
|
|
extern "C" {
|
2014-10-09 01:18:16 +02:00
|
|
|
#endif
|
|
|
|
|
2015-02-10 19:56:01 +01:00
|
|
|
/**
|
|
|
|
* @def ENABLE_DEBUG
|
|
|
|
* @brief This macro can be defined as 0 or other on a file-based level.
|
|
|
|
* If ENABLE_DEBUG is 0 @ref DEBUG() and @ref DEBUGF() will generate
|
|
|
|
* no output if not they will generate output.
|
|
|
|
*/
|
|
|
|
|
2014-04-01 11:46:21 +02:00
|
|
|
/**
|
2015-04-21 09:45:21 +02:00
|
|
|
* @def DEBUG_PRINT
|
|
|
|
*
|
|
|
|
* @brief Print debug information if the calling thread stack is large enough
|
2014-04-01 11:46:21 +02:00
|
|
|
*
|
2014-05-27 16:26:47 +02:00
|
|
|
* Use this macro the same as `printf`. When `DEVELHELP` is defined inside an
|
2015-04-21 09:45:21 +02:00
|
|
|
* implementation file, all usages of ::DEBUG_PRINT will print the given
|
|
|
|
* information to stdout after verifying the stack is big enough. If `DEVELHELP`
|
2014-05-27 16:26:47 +02:00
|
|
|
* 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
|
2015-05-22 14:31:23 +02:00
|
|
|
#include "cpu_conf.h"
|
2014-03-03 00:25:09 +01:00
|
|
|
#define DEBUG_PRINT(...) \
|
|
|
|
do { \
|
2015-04-28 20:02:05 +02:00
|
|
|
if ((sched_active_thread == NULL) || (sched_active_thread->stack_size > THREAD_EXTRA_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
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @{
|
|
|
|
*/
|
2013-07-24 00:36:06 +02:00
|
|
|
#if ENABLE_DEBUG
|
2014-03-03 10:37:50 +01:00
|
|
|
#include "tcb.h"
|
2015-02-12 12:54:07 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @def DEBUG_FUNC
|
|
|
|
*
|
|
|
|
* @brief Contains the function name if given compiler supports it.
|
|
|
|
* Otherwise it is an empty string.
|
|
|
|
*/
|
|
|
|
# if defined(__cplusplus) && defined(__GNUC__)
|
|
|
|
# define DEBUG_FUNC __PRETTY_FUNCTION__
|
|
|
|
# elif __STDC_VERSION__ >= 199901L
|
|
|
|
# define DEBUG_FUNC __func__
|
|
|
|
# elif __GNUC__ >= 2
|
|
|
|
# define DEBUG_FUNC __FUNCTION__
|
|
|
|
# else
|
2015-02-12 14:30:32 +01:00
|
|
|
# define DEBUG_FUNC ""
|
2015-02-12 12:54:07 +01:00
|
|
|
# endif
|
|
|
|
|
2015-04-21 09:45:21 +02:00
|
|
|
/**
|
|
|
|
* @def DEBUG
|
|
|
|
*
|
|
|
|
* @brief Print debug information to stdout
|
|
|
|
*
|
|
|
|
* @note Another name for ::DEBUG_PRINT
|
|
|
|
*/
|
2014-03-03 00:25:09 +01:00
|
|
|
#define DEBUG(...) DEBUG_PRINT(__VA_ARGS__)
|
2015-04-21 09:45:21 +02:00
|
|
|
/**
|
|
|
|
* @def DEBUGF
|
|
|
|
*
|
|
|
|
* @brief Print extended debug information about the current thread and
|
|
|
|
* function to stdout
|
|
|
|
*/
|
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", \
|
2015-02-12 12:54:07 +01:00
|
|
|
__FILE__, __LINE__, DEBUG_FUNC); \
|
2014-03-03 10:37:50 +01:00
|
|
|
DEBUG_PRINT(__VA_ARGS__); \
|
|
|
|
} while (0)
|
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
|
|
|
|
|
2015-03-26 17:07:04 +01:00
|
|
|
#endif /* DEBUG_H */
|
2014-04-01 11:46:21 +02:00
|
|
|
/** @} */
|