From 6098ee8244374db8aa9d64b7769d69b560357f0b Mon Sep 17 00:00:00 2001 From: Simon Goldschmidt Date: Mon, 23 Dec 2019 21:02:38 +0100 Subject: [PATCH] ppp: improve PPP_DEBUG macro support --- src/include/lwip/debug.h | 10 ++++++---- src/include/netif/ppp/ppp_impl.h | 19 +++++++++++++------ 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/include/lwip/debug.h b/src/include/lwip/debug.h index 579fd242..0ec7e76e 100644 --- a/src/include/lwip/debug.h +++ b/src/include/lwip/debug.h @@ -140,11 +140,12 @@ #endif #ifdef LWIP_DEBUG -#define LWIP_DEBUGF(debug, message) do { \ - if ( \ - ((debug) & LWIP_DBG_ON) && \ +#define LWIP_DEBUG_ENABLED(debug) (((debug) & LWIP_DBG_ON) && \ ((debug) & LWIP_DBG_TYPES_ON) && \ - ((s16_t)((debug) & LWIP_DBG_MASK_LEVEL) >= LWIP_DBG_MIN_LEVEL)) { \ + ((s16_t)((debug) & LWIP_DBG_MASK_LEVEL) >= LWIP_DBG_MIN_LEVEL)) + +#define LWIP_DEBUGF(debug, message) do { \ + if (LWIP_DEBUG_ENABLED(debug)) { \ LWIP_PLATFORM_DIAG(message); \ if ((debug) & LWIP_DBG_HALT) { \ while(1); \ @@ -153,6 +154,7 @@ } while(0) #else /* LWIP_DEBUG */ +#define LWIP_DEBUG_ENABLED(debug) 0 #define LWIP_DEBUGF(debug, message) #endif /* LWIP_DEBUG */ diff --git a/src/include/netif/ppp/ppp_impl.h b/src/include/netif/ppp/ppp_impl.h index 40843d5a..cfdcd9f8 100644 --- a/src/include/netif/ppp/ppp_impl.h +++ b/src/include/netif/ppp/ppp_impl.h @@ -614,12 +614,19 @@ int ppp_slprintf(char *buf, int buflen, const char *fmt, ...); /* spr int ppp_vslprintf(char *buf, int buflen, const char *fmt, va_list args); /* vsprintf++ */ size_t ppp_strlcpy(char *dest, const char *src, size_t len); /* safe strcpy */ size_t ppp_strlcat(char *dest, const char *src, size_t len); /* safe strncpy */ -void ppp_dbglog(const char *fmt, ...); /* log a debug message */ -void ppp_info(const char *fmt, ...); /* log an informational message */ -void ppp_notice(const char *fmt, ...); /* log a notice-level message */ -void ppp_warn(const char *fmt, ...); /* log a warning message */ -void ppp_error(const char *fmt, ...); /* log an error message */ -void ppp_fatal(const char *fmt, ...); /* log an error message and die(1) */ +void ppp_dbglog_impl(const char *fmt, ...); /* log a debug message */ +void ppp_info_impl(const char *fmt, ...); /* log an informational message */ +void ppp_notice_impl(const char *fmt, ...); /* log a notice-level message */ +void ppp_warn_impl(const char *fmt, ...); /* log a warning message */ +void ppp_error_impl(const char *fmt, ...); /* log an error message */ +void ppp_fatal_impl(const char *fmt, ...); /* log an error message and die(1) */ +/* wrap all the above functions so they will only be linked when enabled */ +#define ppp_dbglog(x) do { if (LWIP_DEBUG_ENABLED(LOG_DEBUG)) { ppp_dbglog_impl x; }} while(0) +#define ppp_info(x) do { if (LWIP_DEBUG_ENABLED(LOG_INFO)) { ppp_info_impl x; }} while(0) +#define ppp_notice(x) do { if (LWIP_DEBUG_ENABLED(LOG_NOTICE)) { ppp_notice_impl x; }} while(0) +#define ppp_warn(x) do { if (LWIP_DEBUG_ENABLED(LOG_WARNING)) { ppp_warn_impl x; }} while(0) +#define ppp_error(x) do { if (LWIP_DEBUG_ENABLED(LOG_ERR)) { ppp_error_impl x; }} while(0) +#define ppp_fatal(x) do { if (LWIP_DEBUG_ENABLED(LOG_CRITICAL)) { ppp_fatal_impl x; }} while(0) #if PRINTPKT_SUPPORT void ppp_dump_packet(ppp_pcb *pcb, const char *tag, unsigned char *p, int len); /* dump packet to debug log if interesting */ -- 2.11.0.windows.1