Loading...
Searching...
No Matches
debug.h File Reference

Debug-header. More...

Detailed Description

Debug-header.

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 kaspa.nosp@m.r@sc.nosp@m.hleis.nosp@m.er.d.nosp@m.e

Definition in file debug.h.

#include <stdio.h>
#include "sched.h"
#include "thread.h"
#include "cpu_conf.h"
#include "architecture.h"
+ Include dependency graph for debug.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define DEBUG_EXTRA_STACKSIZE   THREAD_EXTRA_STACKSIZE_PRINTF
 Extra stacksize needed when ENABLE_DEBUG==1.
 
#define DEBUG_PRINT(...)
 Print debug information if the calling thread stack is large enough.
 
#define DEBUG_BREAKPOINT(val)   ARCHITECTURE_BREAKPOINT(val)
 Set a debug breakpoint.
 

Debugging defines

#define ENABLE_DEBUG   0
 This macro can be defined as 0 or other on a file-based level.
 
#define DEBUG_FUNC   ""
 Contains the function name if given compiler supports it.
 
#define DEBUG(...)   do { if (ENABLE_DEBUG) { DEBUG_PRINT(__VA_ARGS__); } } while (0)
 Print debug information to stdout.
 
#define DEBUG_PUTS(str)   do { if (ENABLE_DEBUG) { puts(str); } } while (0)
 Print debug information to stdout using puts(), so no stack size restrictions do apply.
 

Macro Definition Documentation

◆ DEBUG

#define DEBUG (   ...)    do { if (ENABLE_DEBUG) { DEBUG_PRINT(__VA_ARGS__); } } while (0)

Print debug information to stdout.

Note
Another name for DEBUG_PRINT

Definition at line 118 of file debug.h.

◆ DEBUG_BREAKPOINT

#define DEBUG_BREAKPOINT (   val)    ARCHITECTURE_BREAKPOINT(val)

Set a debug breakpoint.

When DEVELHELP is enabled, this traps the CPU and allows to debug the program with e.g. gdb. Without DEVELHELP this turns into a no-op.

Warning
If no Debugger is attached, the CPU might get stuck here and consume a lot of power until reset.
Parameters
valBreakpoint context for debugger, usually ignored.

Definition at line 78 of file debug.h.

◆ DEBUG_EXTRA_STACKSIZE

#define DEBUG_EXTRA_STACKSIZE   THREAD_EXTRA_STACKSIZE_PRINTF

Extra stacksize needed when ENABLE_DEBUG==1.

Definition at line 135 of file debug.h.

◆ DEBUG_FUNC

#define DEBUG_FUNC   ""

Contains the function name if given compiler supports it.

Otherwise it is an empty string.

Definition at line 108 of file debug.h.

◆ DEBUG_PRINT

#define DEBUG_PRINT (   ...)
Value:
do { \
if ((thread_get_active() == NULL) || \
(thread_get_active()->stack_size >= \
printf(__VA_ARGS__); \
} \
else { \
puts("Cannot debug, stack too small. Consider using DEBUG_PUTS()."); \
} \
} while (0)
static thread_t * thread_get_active(void)
Returns a pointer to the Thread Control Block of the currently running thread.
Definition thread.h:407
#define THREAD_EXTRA_STACKSIZE_PRINTF
Size of the task's printf stack in bytes.

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)

Definition at line 47 of file debug.h.

◆ DEBUG_PUTS

#define DEBUG_PUTS (   str)    do { if (ENABLE_DEBUG) { puts(str); } } while (0)

Print debug information to stdout using puts(), so no stack size restrictions do apply.

Definition at line 126 of file debug.h.

◆ ENABLE_DEBUG

#define ENABLE_DEBUG   0

This macro can be defined as 0 or other on a file-based level.

DEBUG() will generate output only if ENABLE_DEBUG is non-zero.

Definition at line 92 of file debug.h.