1 /** 2 * @file 3 * Debug messages infrastructure 4 */ 5 6 /* 7 * Copyright (c) 2001-2004 Swedish Institute of Computer Science. 8 * All rights reserved. 9 * 10 * Redistribution and use in source and binary forms, with or without modification, 11 * are permitted provided that the following conditions are met: 12 * 13 * 1. Redistributions of source code must retain the above copyright notice, 14 * this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright notice, 16 * this list of conditions and the following disclaimer in the documentation 17 * and/or other materials provided with the distribution. 18 * 3. The name of the author may not be used to endorse or promote products 19 * derived from this software without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 22 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 23 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 24 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 26 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 29 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 30 * OF SUCH DAMAGE. 31 * 32 * This file is part of the lwIP TCP/IP stack. 33 * 34 * Author: Adam Dunkels <adam@sics.se> 35 * 36 */ 37 #ifndef LWIP_HDR_DEBUG_H 38 #define LWIP_HDR_DEBUG_H 39 40 #include "lwip/arch.h" 41 42 /** lower two bits indicate debug level 43 * - 0 all 44 * - 1 warning 45 * - 2 serious 46 * - 3 severe 47 */ 48 #define LWIP_DBG_LEVEL_ALL 0x00 49 #define LWIP_DBG_LEVEL_OFF LWIP_DBG_LEVEL_ALL /* compatibility define only */ 50 #define LWIP_DBG_LEVEL_WARNING 0x01 /* bad checksums, dropped packets, ... */ 51 #define LWIP_DBG_LEVEL_SERIOUS 0x02 /* memory allocation failures, ... */ 52 #define LWIP_DBG_LEVEL_SEVERE 0x03 53 #define LWIP_DBG_MASK_LEVEL 0x03 54 55 /** flag for LWIP_DEBUGF to enable that debug message */ 56 #define LWIP_DBG_ON 0x80U 57 /** flag for LWIP_DEBUGF to disable that debug message */ 58 #define LWIP_DBG_OFF 0x00U 59 60 /** flag for LWIP_DEBUGF indicating a tracing message (to follow program flow) */ 61 #define LWIP_DBG_TRACE 0x40U 62 /** flag for LWIP_DEBUGF indicating a state debug message (to follow module states) */ 63 #define LWIP_DBG_STATE 0x20U 64 /** flag for LWIP_DEBUGF indicating newly added code, not thoroughly tested yet */ 65 #define LWIP_DBG_FRESH 0x10U 66 /** flag for LWIP_DEBUGF to halt after printing this debug message */ 67 #define LWIP_DBG_HALT 0x08U 68 69 /** 70 * LWIP_NOASSERT: Disable LWIP_ASSERT checks. 71 * -- To disable assertions define LWIP_NOASSERT in arch/cc.h. 72 */ 73 #ifndef LWIP_NOASSERT 74 #define LWIP_ASSERT(message, assertion) do { if (!(assertion)) { \ 75 LWIP_PLATFORM_ASSERT(message); }} while(0) 76 #ifndef LWIP_PLATFORM_ASSERT 77 #error "If you want to use LWIP_ASSERT, LWIP_PLATFORM_ASSERT(message) needs to be defined in your arch/cc.h" 78 #endif 79 #else /* LWIP_NOASSERT */ 80 #define LWIP_ASSERT(message, assertion) 81 #endif /* LWIP_NOASSERT */ 82 83 /** if "expression" isn't true, then print "message" and execute "handler" expression */ 84 #ifndef LWIP_ERROR 85 #ifndef LWIP_NOASSERT 86 #define LWIP_PLATFORM_ERROR(message) LWIP_PLATFORM_ASSERT(message) 87 #elif defined LWIP_DEBUG 88 #define LWIP_PLATFORM_ERROR(message) LWIP_PLATFORM_DIAG((message)) 89 #else 90 #define LWIP_PLATFORM_ERROR(message) 91 #endif 92 93 #define LWIP_ERROR(message, expression, handler) do { if (!(expression)) { \ 94 LWIP_PLATFORM_ERROR(message); handler;}} while(0) 95 #endif /* LWIP_ERROR */ 96 97 #ifdef LWIP_DEBUG 98 #ifndef LWIP_PLATFORM_DIAG 99 #error "If you want to use LWIP_DEBUG, LWIP_PLATFORM_DIAG(message) needs to be defined in your arch/cc.h" 100 #endif 101 /** print debug message only if debug message type is enabled... 102 * AND is of correct type AND is at least LWIP_DBG_LEVEL 103 */ 104 #define LWIP_DEBUGF(debug, message) do { \ 105 if ( \ 106 ((debug) & LWIP_DBG_ON) && \ 107 ((debug) & LWIP_DBG_TYPES_ON) && \ 108 ((s16_t)((debug) & LWIP_DBG_MASK_LEVEL) >= LWIP_DBG_MIN_LEVEL)) { \ 109 LWIP_PLATFORM_DIAG(message); \ 110 if ((debug) & LWIP_DBG_HALT) { \ 111 while(1); \ 112 } \ 113 } \ 114 } while(0) 115 116 #ifdef WITH_LWIP_PKTPRINT 117 typedef struct pkt_stats_data { 118 uint64_t rx_bytes; 119 uint64_t rx_packets; 120 uint64_t tx_bytes; 121 uint64_t tx_packets; 122 uint64_t rx_tcp_bytes; 123 uint64_t rx_tcp_packets; 124 uint64_t rx_udp_bytes; 125 uint64_t rx_udp_packets; 126 uint64_t rx_other_bytes; 127 uint64_t rx_other_packets; 128 uint64_t tx_tcp_bytes; 129 uint64_t tx_tcp_packets; 130 uint64_t tx_udp_bytes; 131 uint64_t tx_udp_packets; 132 uint64_t tx_other_bytes; 133 uint64_t tx_other_packets; 134 } pkt_stats_data; 135 136 void lwip_pkt_stats(pkt_stats_data *data); 137 138 void lwip_pkt_print(char* note_ptr, void *pbuf, void* netif); 139 #define LWIP_PKTDEBUGF(note_ptr, pbuf, netif) do { \ 140 s16_t debug = PKTPRINT_DEBUG; \ 141 if ( \ 142 ((debug) & LWIP_DBG_ON) && \ 143 ((debug) & LWIP_DBG_TYPES_ON)) { \ 144 lwip_pkt_print(note_ptr, pbuf, netif); \ 145 if ((debug) & LWIP_DBG_HALT) { \ 146 while(1); \ 147 } \ 148 } \ 149 } while(0) 150 151 #else 152 #define LWIP_PKTDEBUGF(note_ptr, pbuf, netif) 153 #endif /* WITH_LWIP_PKTPRINT */ 154 #else /* LWIP_DEBUG */ 155 #define LWIP_DEBUGF(debug, message) 156 #define LWIP_PKTDEBUGF(note_ptr, pbuf, netif) 157 #endif /* LWIP_DEBUG */ 158 159 #endif /* LWIP_HDR_DEBUG_H */ 160 161