-
Notifications
You must be signed in to change notification settings - Fork 17
Debugging system: ideas on how to improve the debugging system
Currently debugging is turned on and off in every file separately.
The only way to enable DEBUG for the module is to set DEBUG to 1 or something other than 0 within the code of the module. There are also some modules within contiki where DEBUG is set to 1 in the release version, looks like someone forgot to set it back to 0 again:
user@machine:~/workspace/contiki-2.6$ fgrep " DEBUG 1" * -r
core/net/mac/ctdma_mac.c:#define DEBUG 1
...
platform/redbee-dev/contiki-mc1322x-main.c:#define DEBUG 1
- Uses top level makefile.include to recompile specified modules with a DEBUG=1 or DEBUG=0 switch. The names of DEBUG=1 modules are stored in a text file in the $OBJECT directory. Example:
$make TARGET=avr-raven DEBUG="rpl-dag.c,sicslowpan.c"
avr-gcc -DEBUG=1 ... rpl-dag.c
avr-gcc -DEBUG=1 ... sicslowpan.c
...
$make TARGET=avr-raven DEBUG=rpl-dag.c
avr-gcc ... -DEBUG=0 sicslowpan.c
...
$make TARGET=avr-raven
avr-gcc ... -DEBUG=0 rpl-dag.c
+ Full recompile not needed
- Not as portable? More cumbersome than include files?
- Useless if build system is not GNU build system --marcas 22:31, 12 July 2012 (CEST)
- Minimal change to existing source, breaks nothing if not used.
- Not one byte of debug system in the final binary if DEBUG is disabled --marcas 15:54, 13 July 2012 (CEST)
This method extends the current implementation used in contiki 2.6 . The idea behind it is to move the definition of the used debug output function into a global debug.h file. Also other switches are defined in the debug.h file, allowing one to switch on or off different modules for debugging. The main drawback : All modules that include debug.h have to recompiled if a change is performed in debug.h.
This file includes all definitions for debug handling:
- The debug output function (DBG_FUNC), which has to be a varargs function. This function has to use the printf signature ... this allows one to write an output function for any output device (uart,spi,i2c,tcp/ip ...).
- The on/off switches for the modules
#ifndef DEBUG_H
#define DEBUG_H
/* Debugging output function (printf or any other var args function) */
#if DEBUG
#include <stdio.h>
#define DBG_FUNC(...) printf(__VA_ARGS__)
#else
#define DBG_FUNC(...)
#endif /* DEBUG */
/* Following DEBUG check allows to write more complex debug sections beyond DBG("Debugmessage: %d",var). */
/* But try to avoid more complex debug sections, for the readability of the code and run time issues (real time)! */
#if DEBUG
/* application modules */
#define DEBUG_MAIN 1
/* NETSTACK modules */
#define DEBUG_NETSTACK_RADIO 0
#define DEBUG_NETSTACK_RDC 0
#define DEBUG_NETSTACK_MAC 0
#define DEBUG_NETSTACK_NETWORK 0
#define DEBUG_NETSTACK_FRAMER 0
/* core/sys modules */
/* ... */
#endif /* DEBUG */
#endif /* DEBUG_H */
The module can be enabled for debugging in debug.h.
If the module is disabled for debugging, the DBG - function is defined as empty, and thus not compiled into the module.
#include <stdlib.h>
#include "debug.h"
#if DEBUG_MAIN
#define DBG(...) DBG_FUNC(__VA_ARGS__)
#else
#define DBG(...)
#endif
int
main(void)
{
DBG("This is a simple debug message!\n");
#if DEBUG_MAIN
{
int dbg_test;
DBG("This is a more complex debug message! - ");
for(dbg_test = 0; dbg_test < 5; dbg_test++) {
DBG("%d ", dbg_test);
}
DBG("\n");
}
#endif /* DEBUG_MAIN */
return EXIT_SUCCESS;
}
+ Simple, portable
- Full recompile
- The cost of the full recompile might be reduced by ccache --Morty 21:36, 12 July 2012 (CEST)
- Not one byte of debug system in the final binary if DEBUG is disabled --marcas 15:54, 13 July 2012
- Unless the file is generated this is likely to fail, because it must be actively maintained. ---Morty 2012/08/06 13:55//
- debug.h - maintenance only required if the main DEBUG switch is enabled. Disabled by default in release. --marcas 16:25, 06 August 2012
- Removed C99-only parts completly, as it also has to work with C89 syntax - Reason: Coding rules and low level C compilers and preprocessors --marcas 19:34, 15 August 2012
- As only one NETSTACK may be used at one time, there is no need for specific NETSTACK debug switches (e.g. DEBUG_XMAC and so on) --marcas 7:27, 12 October 2012
+ Portable, full recompile not needed
- Many debug_xxx.h files
- Not one byte of debug system in the final binary if DEBUG is disabled --marcas 15:54, 13 July 2012 (CEST)
+ Simple, portable, full recompile not needed
- Increased memory use
- This will not work on your average sensor mote. --Morty 21:36, 12 July 2012 (CEST)