Home > Back-end >  LwIP into NUC970_NonOS_BSP-master incorrect works LWIP_DEBUG option
LwIP into NUC970_NonOS_BSP-master incorrect works LWIP_DEBUG option

Time:09-07

I'm trying build LwIP 1.4.1 (this version uses vendor for example) and I want to build with diagnostic messages for UDP. Problem: In debug.h condition #ifdef LWIP_DEBUG builds as undefined, but if #define LWIP_DEBUG exist warning about redefine it.

Updated: it repeatable in four files.

udp.c

#include "lwip/opt.h"

err_t
udp_bind(struct udp_pcb *pcb, ip_addr_t *ipaddr, u16_t port)
{
    // My comment
  LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE, ("udp_bind(ipaddr = "));
  return ERR_OK;
}

opt.h

#ifndef __LWIP_OPT_H__
#define __LWIP_OPT_H__

#include "lwipopts.h"
#include "lwip/debug.h"

#endif /* __LWIP_OPT_H__ */

lwipopts.h

#ifndef __LWIPOPTS_H__
#define __LWIPOPTS_H__

#include "lwipopts.h"
#include "lwip/debug.h"

#define LWIP_DEBUG  1
#define UDP_DEBUG   LWIP_DBG_ON


#endif /* __LWIPOPTS_H__ */

and debug.h

#ifndef __LWIP_DEBUG_H__
#define __LWIP_DEBUG_H__

#include "lwip/opt.h"

//#define LWIP_DEBUG  exist
#ifdef LWIP_DEBUG
#define LWIP_DEBUGF(debug, message) do { if ((debug) & 0x80U)  { \
                                 LWIP_PLATFORM_DIAG(message); \
                               } } while(0)

#else  /* LWIP_DEBUG */
#define LWIP_DEBUGF(debug, message) 
#endif /* LWIP_DEBUG */

#endif /* __LWIP_DEBUG_H__ */

CodePudding user response:

If you try on purpose to define it in multiple headers, that may be included at the same time from a .c file, each header needs to do something like:

#ifndef LWIP_DEBUG
  #define LWIP_DEBUG 1
#endif

Or alternatively:

#undef LWIP_DEBUG
#define LWIP_DEBUG 1

CodePudding user response:

I have found problem: remove any includes from lwipopts.h.

It reproduces in two files, udp.c and modifed lwipopts.h

#ifndef __LWIPOPTS_H__
#define __LWIPOPTS_H__

#include "lwipopts.h"
//#include "lwip/debug.h" 
/* REDUCED BODY BEGIN */
//#define LWIP_DEBUG  exist
#ifdef LWIP_DEBUG
#define LWIP_DEBUGF(debug, message) do { printf("%d, %s\n", debug, message); } while(0)
#else  /* LWIP_DEBUG */
#define LWIP_DEBUGF(debug, message) 
#endif /* LWIP_DEBUG */
/* REDUCED BODY END */

#define LWIP_DEBUG  1
#define UDP_DEBUG   LWIP_DBG_ON

#endif /* __LWIPOPTS_H__ */

Definition LWIP_DEBUG after #ifdef LWIP_DEBUG condition. It is because users lwipopts.h contain

#include "lwipopts.h"
#include "lwip/debug.h"

lwipopts.h should not contain any include directive! Little bit explain: How it should be

#include "lwip/opt.h"
  #include "lwipopts.h"
  // BODY lwipopts.h
  #include "lwip/debug.h"
    //#include "opt.h" /* guarded */
  // BODY debug.h

How it is in git Nuvoton (reduced):

#include "lwip/opt.h" /* udp.c */
  #include "lwipopts.h"
    //#include "lwipopts.h"  /* guarded */
    #include "lwip/debug.h"
      //#include "lwip/opt.h"  /* guarded */
      // BODY debug.h
    // BODY lwipopts.h
  //#include "lwip/debug.h" /* guarded */
    //#include "lwip/opt.h" /* guarded */

So, bodies of debug.h and lwipopts.h swaped.

  • Related