• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "lwip/opt.h"
42 
43 #ifdef LWIP_ENABLE_DIAG_SUPPORT
44 #include "diag_util.h"
45 #endif
46 
47 #if defined (__cplusplus) && __cplusplus
48 extern "C" {
49 #endif
50 
51 /**
52  * @defgroup debugging_levels LWIP_DBG_MIN_LEVEL and LWIP_DBG_TYPES_ON values
53  * @ingroup lwip_opts_debugmsg
54  * @{
55  */
56 
57 /** @name Debug level (LWIP_DBG_MIN_LEVEL)
58  * @{
59  */
60 /** Debug level: ALL messages*/
61 #define LWIP_DBG_LEVEL_ALL     0x00
62 /** Debug level: Warnings. bad checksums, dropped packets, ... */
63 #define LWIP_DBG_LEVEL_WARNING 0x01
64 /** Debug level: Serious. memory allocation failures, ... */
65 #define LWIP_DBG_LEVEL_SERIOUS 0x02
66 /** Debug level: Severe */
67 #define LWIP_DBG_LEVEL_SEVERE  0x03
68 /**
69  * @}
70  */
71 
72 #define LWIP_DBG_MASK_LEVEL    0x03
73 /* compatibility define only */
74 #define LWIP_DBG_LEVEL_OFF     LWIP_DBG_LEVEL_ALL
75 
76 /** @name Enable/disable debug messages completely (LWIP_DBG_TYPES_ON)
77  * @{
78  */
79 /** flag for LWIP_DEBUGF to enable that debug message */
80 #define LWIP_DBG_ON            0x80U
81 /** flag for LWIP_DEBUGF to disable that debug message */
82 #define LWIP_DBG_OFF           0x00U
83 /**
84  * @}
85  */
86 
87 /** @name Debug message types (LWIP_DBG_TYPES_ON)
88  * @{
89  */
90 /** flag for LWIP_DEBUGF indicating a tracing message (to follow program flow) */
91 #ifndef LWIP_DBG_TRACE
92 #define LWIP_DBG_TRACE         0x40U
93 #endif
94 /** flag for LWIP_DEBUGF indicating a state dbg message (to follow module states) */
95 #define LWIP_DBG_STATE         0x20U
96 /** flag for LWIP_DEBUGF indicating newly added code, not thoroughly tested yet */
97 #define LWIP_DBG_FRESH         0x10U
98 /** flag for LWIP_DEBUGF to halt after printing this dbg message
99  * @endcond */
100 #define LWIP_DBG_HALT          0x08U
101 /**
102  * @}
103  */
104 
105 /**
106  * @}
107  */
108 
109 /**
110  * @defgroup lwip_assertions Assertion handling
111  * @ingroup lwip_opts_debug
112  * @{
113  */
114 /**
115  * LWIP_NOASSERT: Disable LWIP_ASSERT checks:
116  * To disable assertions define LWIP_NOASSERT in arch/cc.h.
117  */
118 #ifdef __DOXYGEN__
119 #ifndef LWIP_NOASSERT
120 #define LWIP_NOASSERT
121 #undef LWIP_NOASSERT
122 #endif
123 #endif
124 /**
125  * @}
126  */
127 
128 #ifndef LWIP_NOASSERT
129 #define LWIP_ASSERT(message, assertion) do { if (!(assertion)) { \
130   LWIP_PLATFORM_ASSERT(message); } } while (0)
131 #ifndef LWIP_PLATFORM_ASSERT
132 #error "If you want to use LWIP_ASSERT, LWIP_PLATFORM_ASSERT(message) needs to be defined in your arch/cc.h"
133 #endif
134 #else /* LWIP_NOASSERT */
135 #define LWIP_ASSERT(message, assertion)
136 #endif /* LWIP_NOASSERT */
137 
138 #ifndef LWIP_ERROR
139 #ifndef LWIP_NOASSERT
140 #define LWIP_PLATFORM_ERROR(message) LWIP_PLATFORM_ASSERT(message)
141 #elif defined LWIP_DEBUG
142 #define LWIP_PLATFORM_ERROR(message) LWIP_PLATFORM_DIAG((message))
143 #else
144 #define LWIP_PLATFORM_ERROR(message)
145 #endif
146 
147 #ifdef LWIP_ENABLE_DIAG_SUPPORT
148 #define LWIP_ERROR_LOG0(message)   diag_layer_msg_e0(0, message)
149 #else
150 #define LWIP_ERROR_LOG0(message)
151 #endif
152 
153 #ifdef CUSTOM_AT_COMMAND
154 #define LWIP_ERROR(message, expression, handler) do { \
155   if (!(expression)) { \
156     LWIP_ERROR_LOG0(message); \
157     handler; \
158   } \
159 } while (0)
160 #else
161 /* if "expression" isn't true, then print "message" and execute "handler" expression */
162 #define LWIP_ERROR(message, expression, handler) do { if (!(expression)) { \
163   LWIP_PLATFORM_ERROR(message); handler; } } while (0)
164 #endif /* LWIP_ERROR */
165 #endif
166 
167 /** Enable dbg message printing, but only if debug message type is enabled
168  *  AND is of correct type AND is at least LWIP_DBG_LEVEL.
169  */
170 #ifdef __DOXYGEN__
171 #define LWIP_DEBUG
172 #undef LWIP_DEBUG
173 #endif
174 
175 #ifdef LWIP_DEBUG
176 #ifndef LWIP_PLATFORM_DIAG
177 #error "If you want to use LWIP_DEBUG, LWIP_PLATFORM_DIAG(message) needs to be defined in your arch/cc.h"
178 #endif
179 #define LWIP_DEBUGF(dbg, message) do { \
180   if ( \
181     ((dbg) & LWIP_DBG_ON) && \
182     ((dbg) & LWIP_DBG_TYPES_ON) && \
183     ((s16_t)((dbg) & LWIP_DBG_MASK_LEVEL) >= LWIP_DBG_MIN_LEVEL)) { \
184     LWIP_PLATFORM_DIAG(message); \
185     if ((dbg) & LWIP_DBG_HALT) { \
186       while (1); \
187     } \
188   } \
189 } while (0)
190 
191 #else /* LWIP_DEBUG */
192 #define LWIP_DEBUGF(debug, message)
193 #endif /* LWIP_DEBUG */
194 
195 #ifdef LWIP_ENABLE_DIAG_SUPPORT
196 #define LWIP_DEBUGF_LOG0(dbg, fmt)   diag_layer_msg_i0(0, fmt);
197 #define LWIP_DEBUGF_LOG1(dbg, fmt, p1)  diag_layer_msg_i1(0, fmt, (hi_u32)(p1));
198 #define LWIP_DEBUGF_LOG2(dbg, fmt, p1, p2)  diag_layer_msg_i2(0, fmt, (hi_u32)(p1), (hi_u32)(p2));
199 #define LWIP_DEBUGF_LOG3(dbg, fmt, p1, p2, p3) \
200   diag_layer_msg_i3(0, fmt, (hi_u32)(p1), (hi_u32)(p2), (hi_u32)(p3));
201 #define LWIP_DEBUGF_LOG4(dbg, fmt, p1, p2, p3, p4) \
202   diag_layer_msg_i4(0, fmt, (hi_u32)(p1), (hi_u32)(p2), (hi_u32)(p3), (hi_u32)(p4));
203 #else
204 #define LWIP_DEBUGF_LOG0(dbg, fmt)   LWIP_DEBUGF(dbg, (fmt))
205 #define LWIP_DEBUGF_LOG1(dbg, fmt, p1)  LWIP_DEBUGF(dbg, (fmt, p1));
206 #define LWIP_DEBUGF_LOG2(dbg, fmt, p1, p2)  LWIP_DEBUGF(dbg, (fmt, p1, p2));
207 #define LWIP_DEBUGF_LOG3(dbg, fmt, p1, p2, p3)  LWIP_DEBUGF(dbg, (fmt, p1, p2, p3));
208 #define LWIP_DEBUGF_LOG4(dbg, fmt, p1, p2, p3, p4) LWIP_DEBUGF(dbg, (fmt, p1, p2, p3, p4));
209 #endif
210 
211 #if defined(PBUF_API) && PBUF_API
212 #define PBUF_ERROR(...) LWIP_ERROR(__VA_ARGS__)
213 #else
214 #define PBUF_ERROR(...)
215 #endif
216 
217 #ifdef LWIP_DEBUG_INFO
218 void debug_socket_info(int idx, int filter, int expend);
219 #if LWIP_TCP
220 void debug_tcppcb_info(void *pcb);
221 #endif /* LWIP_TCP */
222 #if LWIP_UDP || LWIP_UDPLITE
223 void debug_udppcb_info(void *pcb);
224 #endif /* LWIP_UDP || LWIP_UDPLITE */
225 #if LWIP_RAW
226 void debug_rawpcb_info(void *pcb);
227 #endif /* LWIP_RAW */
228 void debug_netconn_info(void *netconn_para, int expend);
229 
230 void debug_ippcb_info(void *pcb);
231 void debug_memp_type_info(int type);
232 void debug_memp_info(void);
233 void debug_memp_detail(int type);
234 #endif /* LWIP_DEBUG_INFO */
235 
236 #if defined (__cplusplus) && __cplusplus
237 }
238 #endif
239 #endif /* LWIP_HDR_DEBUG_H */
240