diff --git a/Makefile b/Makefile index 1ccd45d39..5ace58483 100644 --- a/Makefile +++ b/Makefile @@ -261,7 +261,8 @@ endif # DEBUG_MEM_STATS, DEBUG_DONT_SHARE_POOLS, DEBUG_FD, DEBUG_POOL_INTEGRITY, # DEBUG_NO_POOLS, DEBUG_FAIL_ALLOC, DEBUG_STRICT_ACTION=[0-3], DEBUG_HPACK, # DEBUG_AUTH, DEBUG_SPOE, DEBUG_UAF, DEBUG_THREAD, DEBUG_STRICT, DEBUG_DEV, -# DEBUG_TASK, DEBUG_MEMORY_POOLS, DEBUG_POOL_TRACING, DEBUG_QPACK, DEBUG_LIST. +# DEBUG_TASK, DEBUG_MEMORY_POOLS, DEBUG_POOL_TRACING, DEBUG_QPACK, DEBUG_LIST, +# DEBUG_GLITCHES. DEBUG = #### Trace options diff --git a/include/haproxy/bug.h b/include/haproxy/bug.h index 8183681ab..eb20773cb 100644 --- a/include/haproxy/bug.h +++ b/include/haproxy/bug.h @@ -172,6 +172,7 @@ enum debug_counter_type { DBG_BUG, DBG_BUG_ONCE, DBG_COUNT_IF, + DBG_GLITCH, DBG_COUNTER_TYPES // must be last }; @@ -230,12 +231,27 @@ extern __attribute__((__weak__)) struct debug_count __stop_dbg_cnt HA_SECTION_S 1; /* let's return the true condition */ \ }) : 0); } while (0) +/* DEBUG_GLITCHES enables counting the number of glitches per line of code. The + * condition is empty (nothing to write there), except maybe __VA_ARGS at the + * end. + */ +# if !defined(DEBUG_GLITCHES) +# define _COUNT_GLITCH(file, line, ...) do { } while (0) +# else +# define _COUNT_GLITCH(file, line, ...) do { \ + __DBG_COUNT(, file, line, DBG_GLITCH, __VA_ARGS__); \ + } while (0) +# endif #else /* USE_OBSOLETE_LINKER not defined below */ # define __DBG_COUNT(cond, file, line, type, ...) do { } while (0) # define _COUNT_IF(cond, file, line, ...) do { } while (0) +# define _COUNT_GLITCH(file, line, ...) do { } while (0) #endif +/* reports a glitch for current file and line, optionally with an explanation */ +#define COUNT_GLITCH(...) _COUNT_GLITCH(__FILE__, __LINE__, __VA_ARGS__) + /* This is the generic low-level macro dealing with conditional warnings and * bugs. The caller decides whether to crash or not and what prefix and suffix * to pass. The macro returns the boolean value of the condition as an int for diff --git a/src/debug.c b/src/debug.c index c4da8d7db..78940bfc4 100644 --- a/src/debug.c +++ b/src/debug.c @@ -2253,8 +2253,12 @@ static int debug_parse_cli_counters(char **args, char *payload, struct appctx *a ctx->types |= 1 << DBG_COUNT_IF; continue; } + else if (strcmp(args[arg], "glt") == 0) { + ctx->types |= 1 << DBG_GLITCH; + continue; + } else - return cli_err(appctx, "Expects an optional action ('reset','show'), optional types ('bug','chk','cnt') and optionally 'all' to even dump null counters.\n"); + return cli_err(appctx, "Expects an optional action ('reset','show'), optional types ('bug','chk','cnt','glt') and optionally 'all' to even dump null counters.\n"); } if (action == 1) { // reset @@ -2288,6 +2292,7 @@ static int debug_iohandler_counters(struct appctx *appctx) [DBG_BUG] = "BUG", [DBG_BUG_ONCE] = "CHK", [DBG_COUNT_IF] = "CNT", + [DBG_GLITCH] = "GLT", }; struct dev_cnt_ctx *ctx = appctx->svcctx; struct debug_count *ptr;