1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00
RIOT/core/include/debug.h

117 lines
3.0 KiB
C
Raw Normal View History

/*
* Copyright (C) 2014 Freie Universität Berlin
*
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.
*/
/**
* @addtogroup core_util
* @{
*
* @file debug.h
* @brief Debug-header
*
* @details If ENABLE_DEBUG is set, before this header is included,
* ::DEBUG will print out to stdout, otherwise do nothing
*
* @author Kaspar Schleiser <kaspar@schleiser.de>
*/
#ifndef DEBUG_H
#define DEBUG_H
#include <stdio.h>
#include "sched.h"
#ifdef __cplusplus
2015-02-10 19:56:01 +01:00
extern "C" {
#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.
*/
/**
* @name Print debug information if the calling thread stack is large enough
*
* 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-03-03 00:25:09 +01:00
#if DEVELHELP
#include "cpu-conf.h"
#define DEBUG_PRINT(...) \
do { \
2015-03-31 12:42:19 +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-03-03 00:25:09 +01: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.
*
* @{
*/
#if ENABLE_DEBUG
2014-03-03 10:37:50 +01:00
#include "tcb.h"
/**
* @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 ""
# endif
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: ", \
sched_active_thread ? sched_active_thread->name : "NO THREAD", \
__FILE__, __LINE__, DEBUG_FUNC); \
2014-03-03 10:37:50 +01:00
DEBUG_PRINT(__VA_ARGS__); \
} while (0)
#else
#define DEBUG(...)
2014-03-03 10:37:50 +01:00
#define DEBUGF(...)
#endif
/** @} */
#ifdef __cplusplus
}
#endif
#endif /* DEBUG_H */
/** @} */