Blame view

RIOT/core/include/debug.h 2.64 KB
fb11e647   vrobic   reseau statique a...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
  /*
   * Copyright (C) 2014 Freie Universitรคt Berlin
   *
   * 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
   * @brief       Debug-header
   *
   * @details     If *ENABLE_DEBUG* is defined inside an implementation file, all
   *              calls to ::DEBUG will work the same as *printf* and output the
   *              given information to stdout. If *ENABLE_DEBUG* is not defined,
   *              all calls to ::DEBUG will be ignored.
   *
   * @author      Kaspar Schleiser <kaspar@schleiser.de>
   */
  
  #ifndef DEBUG_H
  #define DEBUG_H
  
  #include <stdio.h>
  #include "sched.h"
  #include "thread.h"
  
  #ifdef __cplusplus
  extern "C" {
  #endif
  
  /**
   * @def ENABLE_DEBUG
   * @brief   This macro can be defined as 0 or other on a file-based level.
   *          @ref DEBUG() will generate output only if ENABLE_DEBUG is non-zero.
   */
  
  /**
   * @def DEBUG_PRINT
   *
   * @brief 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 stdout after verifying the stack is big enough. If `DEVELHELP`
   * is not set, this check is not performed. (CPU exception may occur)
   */
  #ifdef DEVELHELP
  #include "cpu_conf.h"
  #define DEBUG_PRINT(...) \
      do { \
          if ((sched_active_thread == NULL) || (sched_active_thread->stack_size > THREAD_EXTRA_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
  
  /**
   * @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
  #  define DEBUG_FUNC ""
  # endif
  
  /**
   * @def DEBUG
   *
   * @brief Print debug information to stdout
   *
   * @note Another name for ::DEBUG_PRINT
   */
  #define DEBUG(...) DEBUG_PRINT(__VA_ARGS__)
  #else
  #define DEBUG(...)
  #endif
  /** @} */
  
  /**
   * @def DEBUG_EXTRA_STACKSIZE
   *
   * @brief Extra stacksize needed when ENABLE_DEBUG==1
   */
  #if ENABLE_DEBUG
  #define DEBUG_EXTRA_STACKSIZE THREAD_EXTRA_STACKSIZE_PRINTF
  #else
  #define DEBUG_EXTRA_STACKSIZE (0)
  #endif
  
  #ifdef __cplusplus
  }
  #endif
  
  #endif /* DEBUG_H */
  /** @} */