lwip-users
[Top][All Lists]
Advanced

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

AW: [lwip-users] Debug code


From: Zschocke, Florian
Subject: AW: [lwip-users] Debug code
Date: Tue, 25 Feb 2003 15:06:24 +0100

David Haas wrote on Dienstag, 25. Februar 2003 14:49:

> ip_addr_debug_print is a function call. It is generic and does
> not test any particular debug flag. So when it is called, it
> must be in a #if SOMETHING_DEBUG #endif section.
> It should probably be a macro which tests the debug flag.

No, actually it isn't. It is a macro defined in ip_addr.h which in turn
calls DEBUGF(). But you are right that this might have been the cause in
other cases. In ip.h there is e.g.

#if IP_DEBUG
void ip_debug_print(struct pbuf *p);
#endif /* IP_DEBUG */

That would require #if IP_DEBUG protections in the code when ip_debug_print
is used. I have changed that to:

#ifdef IP_DEBUG
void ip_debug_print(struct pbuf *p);
#else
#  define ip_debug_print(x)
#endif /* IP_DEBUG */

This is not quite the same since I use #ifdef IP_DEBUG instead of #if
IP_DEBUG for the same reason that I can't use #if IP_DEBUG in the source
files. But it should at least be considered to remove the extra #if-#endif
sections in the C files and instead define empty macros instead of the
function calls.

I found the same situation in tcp.h:

#if (defined TCP_DEBUG) || (defined TCP_INPUT_DEBUG) || (defined
TCP_OUTPUT_DEBUG)
void tcp_debug_print(struct tcp_hdr *tcphdr);
void tcp_debug_print_flags(u8_t flags);
void tcp_debug_print_state(enum tcp_state s);
void tcp_debug_print_pcbs(void);
int tcp_pcbs_sane(void);
#else
#  define tcp_debug_print(tcphdr)
#  define tcp_debug_print_flags(flags)
#  define tcp_debug_print_state(s)
#  define tcp_debug_print_pcbs()
#  define tcp_pcbs_sane() 1
#endif /* TCP_DEBUG */


If possible, I would prefer to have different macros for conditional
compilation and for use in DEBUGF() for the reasons stated in my first mail.
Another way to execute real functions only when debug flags are set, is to
use a macro similar to DEBUGF:

#define DEBUG_DO(debug, x) do { if (debug & DBG_ON) { x } } while (0)

which can be used like in the code:

DEBUG_DO( IP_DEBUG, foo(); bar(a, b) );

Florian.





reply via email to

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