Dependents:   SNMPAgent HTTPServer think_speak_a cyassl-client ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers debug.h Source File

debug.h

00001 /*
00002  * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
00003  * All rights reserved. 
00004  * 
00005  * Redistribution and use in source and binary forms, with or without modification, 
00006  * are permitted provided that the following conditions are met:
00007  *
00008  * 1. Redistributions of source code must retain the above copyright notice,
00009  *    this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright notice,
00011  *    this list of conditions and the following disclaimer in the documentation
00012  *    and/or other materials provided with the distribution.
00013  * 3. The name of the author may not be used to endorse or promote products
00014  *    derived from this software without specific prior written permission. 
00015  *
00016  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 
00017  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
00018  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 
00019  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
00020  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 
00021  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
00022  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
00023  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 
00024  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 
00025  * OF SUCH DAMAGE.
00026  *
00027  * This file is part of the lwIP TCP/IP stack.
00028  * 
00029  * Author: Adam Dunkels <adam@sics.se>
00030  *
00031  */
00032 #ifndef __LWIP_DEBUG_H__
00033 #define __LWIP_DEBUG_H__
00034 
00035 #include "lwip/arch.h"
00036 
00037 /** lower two bits indicate debug level
00038  * - 0 all
00039  * - 1 warning
00040  * - 2 serious
00041  * - 3 severe
00042  */
00043 #define LWIP_DBG_LEVEL_ALL     0x00
00044 #define LWIP_DBG_LEVEL_OFF     LWIP_DBG_LEVEL_ALL /* compatibility define only */
00045 #define LWIP_DBG_LEVEL_WARNING 0x01 /* bad checksums, dropped packets, ... */
00046 #define LWIP_DBG_LEVEL_SERIOUS 0x02 /* memory allocation failures, ... */
00047 #define LWIP_DBG_LEVEL_SEVERE  0x03
00048 #define LWIP_DBG_MASK_LEVEL    0x03
00049 
00050 /** flag for LWIP_DEBUGF to enable that debug message */
00051 #define LWIP_DBG_ON            0x80U
00052 /** flag for LWIP_DEBUGF to disable that debug message */
00053 #define LWIP_DBG_OFF           0x00U
00054 
00055 /** flag for LWIP_DEBUGF indicating a tracing message (to follow program flow) */
00056 #define LWIP_DBG_TRACE         0x40U
00057 /** flag for LWIP_DEBUGF indicating a state debug message (to follow module states) */
00058 #define LWIP_DBG_STATE         0x20U
00059 /** flag for LWIP_DEBUGF indicating newly added code, not thoroughly tested yet */
00060 #define LWIP_DBG_FRESH         0x10U
00061 /** flag for LWIP_DEBUGF to halt after printing this debug message */
00062 #define LWIP_DBG_HALT          0x08U
00063 
00064 #ifndef LWIP_NOASSERT
00065 #define LWIP_ASSERT(message, assertion) do { if(!(assertion)) \
00066   LWIP_PLATFORM_ASSERT(message); } while(0)
00067 #else  /* LWIP_NOASSERT */
00068 #define LWIP_ASSERT(message, assertion) 
00069 #endif /* LWIP_NOASSERT */
00070 
00071 /** if "expression" isn't true, then print "message" and execute "handler" expression */
00072 #ifndef LWIP_ERROR
00073 #define LWIP_ERROR(message, expression, handler) do { if (!(expression)) { \
00074   LWIP_PLATFORM_ASSERT(message); handler;}} while(0)
00075 #endif /* LWIP_ERROR */
00076 
00077 #ifdef LWIP_DEBUG
00078 /** print debug message only if debug message type is enabled...
00079  *  AND is of correct type AND is at least LWIP_DBG_LEVEL
00080  */
00081 #define LWIP_DEBUGF(debug, message) do { \
00082                                if ( \
00083                                    ((debug) & LWIP_DBG_ON) && \
00084                                    ((debug) & LWIP_DBG_TYPES_ON) && \
00085                                    ((s16_t)((debug) & LWIP_DBG_MASK_LEVEL) >= LWIP_DBG_MIN_LEVEL)) { \
00086                                  LWIP_PLATFORM_DIAG(message); \
00087                                  if ((debug) & LWIP_DBG_HALT) { \
00088                                    while(1); \
00089                                  } \
00090                                } \
00091                              } while(0)
00092 
00093 #else  /* LWIP_DEBUG */
00094 #define LWIP_DEBUGF(debug, message) 
00095 #endif /* LWIP_DEBUG */
00096 
00097 #endif /* __LWIP_DEBUG_H__ */
00098