lwip-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lwip-users] debugging issues


From: Zschocke, Florian
Subject: [lwip-users] debugging issues
Date: Thu, 3 Jul 2003 11:00:26 +0200

Hi all!

It's me again, this time picking at the lwIP debugging system. :) While it
is already pretty advanced with its different levels and options, I think it
still has some deficiencies that I'd like to attack.

a) 
Different types of debug messages can be defined with DBG_TRACE, DBG_FRESH
and DBG_STATE. But there are lots of debug messages in the code which do not
specify one of those types. Rightfully so as I believe because I think not
every debug message fits into one of the three categories and it's also
easier to use if you just need some quick debug output to test some things.
The problem with this is that these do not get printed unless EDBUG_TYPES_ON
gets set to DBG_ON which will result in all debug messages getting printed.

What I am missing is a DBG_DEFAULT type for all not further categorized
debug messages. The problem is how to handle this so you don't have to use
DBG_DEFAULT everywhere in the code but assume DBG_DEFAULT for debug messages
without a type specifier. This is our solution:

/** flag for DEBUGF indicating a default debug message not otherwise
qualified */
#define DBG_DEFAULT (u8_t)0x40U
/** flag for DEBUGF indicating a tracing message (to follow program flow) */
#define DBG_TRACE   (u8_t)0x20U
/** flag for DEBUGF indicating a state debug message (to follow module
states) */
#define DBG_STATE   (u8_t)0x10U
/** flag for DEBUGF indicating newly added code, not thoroughly tested yet
*/
#define DBG_FRESH   (u8_t)0x08U
/** flag for DEBUGF to halt after printing this debug message */
#define DBG_HALT    (u8_t)0x04U

#  define DEBUGF(debug, x) do { \
      if ( ((debug) & DBG_ON) && \
           ((((debug)==DBG_ON)?((debug)|DBG_DEFAULT):(debug)) &
DBG_TYPES_ON) &&\
           (((debug) & DBG_MASK_LEVEL) >= DBG_MIN_LEVEL)) {\
        LWIP_PLATFORM_DIAG(x) if ((debug) & DBG_HALT) while(1); } \
    } while(0)


This code introduces a DBG_DEFAULT type which is assumed for every debug
message that has no type specifier set. It allows to specify which debug
messages to get printed, you can turn off efault messages by not including
DBG_DEFAULT in DBG_TYPES_ON.


b)
Hmm, this was about the ip_addr_dbeug_print() macro but I just saw that it
already got changed. Thanks for that. :)


c)
I would like to propose a new debug option: SOCKDATA_DEBUG. Right now when
you want to debug socket operations like socket(), connect() or close() you
have to turn on SOCKETS_DEBUG. This will also turn on debug messages for
functions like recvfrom() and sendto(). Thus you get swamped with output on
a busy connection. I would like to suggest that different debug options are
used for the data path and the control path so that you are still able to
debug the control path without getting output from the data path. We now use
SOCKDATA_DEBUG in lwip_recvfom(), lwip_send(), lwip_sendto(),
lwip_selscan(), lwip_select() and event_callback(). Maybe this is also
applicable for other section of the core code.


d)
One major gripe with the debug system is that it is targeted at compiletime
configuration. This subject had already come up on this list before but
unfortunately no changes were made even though there seemed to be interest
in being able to switch debugging on and off during runtime. We use a
runtime configuration system for lwIP ourselves, having the following issue
with the current lwIP code. With a runtime system the xxx_DEBUG #defines
must be defined to some variable of some sort instead of a constant. This
causes trouble with code like the following:

#if SOCKETS_DEBUG
  LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_bind(%d, addr=", s));
  ip_addr_debug_print(SOCKETS_DEBUG, &local_addr);
  LWIP_DEBUGF(SOCKETS_DEBUG, (" port=%u)\n", ntohs(local_port)));
#endif

The #if SOCKETS_DEBUG will not compile. Using #ifdef SOCKETS_DEBUG is not
possible or else standalone DEBUGF() lines cannot use the SOCKETS_DEBUG
anymore. A solution would be to have additional HAS_xxx_DEBUG macros
#defines that can be tested against:

#ifdef HAS_SOCKETS_DEBUG
  LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_bind(%d, addr=", s));
  ip_addr_debug_print(SOCKETS_DEBUG, &local_addr);
  LWIP_DEBUGF(SOCKETS_DEBUG, (" port=%u)\n", ntohs(local_port)));
#endif

This is a bi more work, but I can't think of a better solution. Maybe
someone else has a better idea to enable runtime debug configuration
support.

Thanks,
Florian.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]