]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
REORG: include: move the BUG_ON() code to haproxy/bug.h
authorWilly Tarreau <w@1wt.eu>
Wed, 27 May 2020 14:51:33 +0000 (16:51 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 11 Jun 2020 08:18:56 +0000 (10:18 +0200)
This one used to be stored into debug.h but the debug tools got larger
and require a lot of other includes, which can't use BUG_ON() anymore
because of this. It does not make sense and instead this macro should
be placed into the lower includes and given its omnipresence, the best
solution is to create a new bug.h with the few surrounding macros needed
to trigger bugs and place assertions anywhere.

Another benefit is that it won't be required to add include <debug.h>
anymore to use BUG_ON, it will automatically be covered by api.h. No
less than 32 occurrences were dropped.

The FSM_PRINTF macro was dropped since not used at all anymore (probably
since 1.6 or so).

35 files changed:
include/common/buf.h
include/common/debug.h
include/haproxy/api.h
include/haproxy/bug.h [new file with mode: 0644]
include/proto/session.h
src/backend.c
src/cli.c
src/connection.c
src/ev_epoll.c
src/filters.c
src/flt_spoe.c
src/frontend.c
src/h1_htx.c
src/http_acl.c
src/http_act.c
src/http_ana.c
src/http_conv.c
src/http_fetch.c
src/http_htx.c
src/http_rules.c
src/lb_chash.c
src/lb_fas.c
src/lb_fwlc.c
src/lb_fwrr.c
src/lb_map.c
src/memory.c
src/proto_sockpair.c
src/proto_tcp.c
src/proto_uxst.c
src/raw_sock.c
src/session.c
src/ssl_sock.c
src/stream.c
src/stream_interface.c
src/tcp_rules.c

index 0bdc5beb9dfa3b0b1e91fb3d01598891d7c91b5c..6ae9a4e676487d40a8b5bd7f3589a708187ba36b 100644 (file)
 #ifndef _COMMON_BUF_H
 #define _COMMON_BUF_H
 
-#include <inttypes.h>
 #include <string.h>
 #include <unistd.h>
-
-#include <common/debug.h>
+#include <haproxy/api.h>
 
 /* Structure defining a buffer's head */
 struct buffer {
index c234bdc7079fcf9fd87933548a35cd842c126b6d..c1b7e42ce1d8feba30c4b2ebec668c7f2f69a79b 100644 (file)
 #include <haproxy/api.h>
 #include <common/memory.h>
 
-#ifdef DEBUG_FULL
-#define DPRINTF(x...) fprintf(x)
-#else
-#define DPRINTF(x...)
-#endif
-
-#ifdef DEBUG_FSM
-#define FSM_PRINTF(x...) fprintf(x)
-#else
-#define FSM_PRINTF(x...)
-#endif
-
-/* This abort is more efficient than abort() because it does not mangle the
- * stack and stops at the exact location we need.
- */
-#define ABORT_NOW() (*(volatile int*)1=0)
-
-/* BUG_ON: complains if <cond> is true when DEBUG_STRICT or DEBUG_STRICT_NOCRASH
- * are set, does nothing otherwise. With DEBUG_STRICT in addition it immediately
- * crashes using ABORT_NOW() above.
- */
-#if defined(DEBUG_STRICT) || defined(DEBUG_STRICT_NOCRASH)
-#if defined(DEBUG_STRICT)
-#define CRASH_NOW() ABORT_NOW()
-#else
-#define CRASH_NOW()
-#endif
-
-#define BUG_ON(cond) _BUG_ON(cond, __FILE__, __LINE__)
-#define _BUG_ON(cond, file, line) __BUG_ON(cond, file, line)
-#define __BUG_ON(cond, file, line)                                             \
-       do {                                                                   \
-               if (unlikely(cond)) {                                          \
-                       const char msg[] = "\nFATAL: bug condition \"" #cond "\" matched at " file ":" #line "\n"; \
-                       DISGUISE(write(2, msg, strlen(msg)));                  \
-                       CRASH_NOW();                                           \
-               }                                                              \
-       } while (0)
-#else
-#undef CRASH_NOW
-#define BUG_ON(cond)
-#endif
-
 struct task;
 struct buffer;
 extern volatile unsigned long threads_to_dump;
index 5a916ba44709e7a12182a69c68c6e7093de43c71..f32050d7153f7897fa94f5c0ddbe4a5dd96e0c7e 100644 (file)
@@ -30,6 +30,7 @@
 #ifndef _HAPROXY_BASE_H
 #define _HAPROXY_BASE_H
 
+#include <haproxy/bug.h>
 #include <haproxy/initcall.h>
 #include <haproxy/api-t.h>
 
diff --git a/include/haproxy/bug.h b/include/haproxy/bug.h
new file mode 100644 (file)
index 0000000..d164c4c
--- /dev/null
@@ -0,0 +1,78 @@
+/*
+ * include/haproxy/bug.h
+ * Assertions and instant crash macros needed everywhere.
+ *
+ * Copyright (C) 2000-2020 Willy Tarreau - w@1wt.eu
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef _HAPROXY_BUG_H
+#define _HAPROXY_BUG_H
+
+#include <haproxy/compiler.h>
+
+/* quick debugging hack, should really be removed ASAP */
+#ifdef DEBUG_FULL
+#define DPRINTF(x...) fprintf(x)
+#else
+#define DPRINTF(x...)
+#endif
+
+/* This abort is more efficient than abort() because it does not mangle the
+ * stack and stops at the exact location we need.
+ */
+#define ABORT_NOW() (*(volatile int*)1=0)
+
+/* BUG_ON: complains if <cond> is true when DEBUG_STRICT or DEBUG_STRICT_NOCRASH
+ * are set, does nothing otherwise. With DEBUG_STRICT in addition it immediately
+ * crashes using ABORT_NOW() above.
+ */
+#if defined(DEBUG_STRICT) || defined(DEBUG_STRICT_NOCRASH)
+#if defined(DEBUG_STRICT)
+#define CRASH_NOW() ABORT_NOW()
+#else
+#define CRASH_NOW()
+#endif
+
+#define BUG_ON(cond) _BUG_ON(cond, __FILE__, __LINE__)
+#define _BUG_ON(cond, file, line) __BUG_ON(cond, file, line)
+#define __BUG_ON(cond, file, line)                                             \
+       do {                                                                   \
+               if (unlikely(cond)) {                                          \
+                       const char msg[] = "\nFATAL: bug condition \"" #cond "\" matched at " file ":" #line "\n"; \
+                       DISGUISE(write(2, msg, __builtin_strlen(msg)));        \
+                       CRASH_NOW();                                           \
+               }                                                              \
+       } while (0)
+#else
+#undef CRASH_NOW
+#define BUG_ON(cond)
+#endif
+
+#endif /* _HAPROXY_BUG_H */
+
+/*
+ * Local variables:
+ *  c-indent-level: 8
+ *  c-basic-offset: 8
+ * End:
+ */
index 61a7b0020bb48a8335d0be7e6dfa0dffdbf31b0f..522e43fe5adc01b5d9ec4988b8323471c339cbcb 100644 (file)
@@ -24,7 +24,6 @@
 
 #include <haproxy/api.h>
 #include <common/buffer.h>
-#include <common/debug.h>
 #include <common/memory.h>
 
 #include <types/global.h>
index ece412c7c5d2d5482e1066ce317b8bed9cd63304..c876003f9d05575e4c926129c3827344640fe021 100644 (file)
@@ -21,7 +21,6 @@
 
 #include <haproxy/api.h>
 #include <common/buffer.h>
-#include <common/debug.h>
 #include <haproxy/hash.h>
 #include <common/htx.h>
 #include <common/ticks.h>
index 13fc2049c4d06c8a7f9f038d16104f3b355ac0bf..a0118dc2b761b56f69f39a53c873ea1fbe5bcdd1 100644 (file)
--- a/src/cli.c
+++ b/src/cli.c
@@ -28,7 +28,6 @@
 
 #include <haproxy/api.h>
 #include <common/cfgparse.h>
-#include <common/debug.h>
 #include <common/memory.h>
 #include <common/mini-clist.h>
 #include <common/standard.h>
index a30a2dd97360a9f0062e00705409011dd132801e..adca5c14e3fc27c28c1d3e9af2df3c36de0b0cdd 100644 (file)
@@ -26,7 +26,6 @@
 #include <proto/sample.h>
 #include <proto/ssl_sock.h>
 
-#include <common/debug.h>
 
 DECLARE_POOL(pool_head_connection, "connection",  sizeof(struct connection));
 DECLARE_POOL(pool_head_connstream, "conn_stream", sizeof(struct conn_stream));
index 97a0b28c61624d268d2f140f5511b3b66bf9bb9c..91670afd3190a0c9b3b13542a0b65c8cb89f94ca 100644 (file)
@@ -15,7 +15,6 @@
 #include <sys/types.h>
 
 #include <haproxy/api.h>
-#include <common/debug.h>
 #include <common/hathreads.h>
 #include <common/standard.h>
 #include <common/ticks.h>
index 3d7bb456207fea27342a51b457178760d08c836d..f8cb526692f1eaa2e61a63cdbd54ae745893b738 100644 (file)
@@ -12,7 +12,6 @@
 
 #include <haproxy/api.h>
 #include <common/buffer.h>
-#include <common/debug.h>
 #include <common/cfgparse.h>
 #include <haproxy/errors.h>
 #include <common/htx.h>
index 5b8daa144a4fdf0f0ddb55e02517cec9dfd6c580..9bd6ab10aa9da92b2cc877d15ba197a8a5eed03c 100644 (file)
@@ -14,7 +14,6 @@
 
 #include <haproxy/api.h>
 #include <common/cfgparse.h>
-#include <common/debug.h>
 #include <common/hathreads.h>
 #include <common/memory.h>
 #include <common/time.h>
index 6274e8a40544fbdbb6afdf62313de12e7b53a821..ce5c3d76233ab10916cf0d6bf51d69872821f1d0 100644 (file)
@@ -24,7 +24,6 @@
 
 #include <haproxy/api.h>
 #include <common/chunk.h>
-#include <common/debug.h>
 #include <common/standard.h>
 #include <common/time.h>
 
index e9d79f6f8a2dab2da910f0d0fa4ee94c2b6ffa8e..6e582e389805b70e12cfc662b26672da2350c794 100644 (file)
@@ -11,7 +11,6 @@
  */
 
 #include <haproxy/api.h>
-#include <common/debug.h>
 #include <common/cfgparse.h>
 #include <common/h1.h>
 #include <common/http.h>
index 06c5d71f2b8a43806545d56c783865c415950025..fe71658da3b6385707447160d4a19628b051e0b3 100644 (file)
@@ -18,7 +18,6 @@
 
 #include <haproxy/api.h>
 #include <common/chunk.h>
-#include <common/debug.h>
 #include <common/http.h>
 #include <common/memory.h>
 #include <common/standard.h>
index 1918aa5839e36cabf4240d6313af9fbc0a026259..da57d8fe049449fc20aaa005d143b8b0dac33b76 100644 (file)
@@ -19,7 +19,6 @@
 #include <haproxy/api.h>
 #include <common/cfgparse.h>
 #include <common/chunk.h>
-#include <common/debug.h>
 #include <common/http.h>
 #include <common/memory.h>
 #include <common/standard.h>
index 4635c38e1daf7c94f0ba28d4360f66ed88085d6c..41f119de05a44d22f7cb7775ed6f711cc71ac965 100644 (file)
@@ -12,7 +12,6 @@
 
 #include <haproxy/api.h>
 #include <haproxy/base64.h>
-#include <common/debug.h>
 #include <common/htx.h>
 #include <common/net_helper.h>
 #include <common/uri_auth.h>
index 83c6bb33b45fa5388775d87c8959aea717651c1a..109952145992d502ab984b93bea19091faa1a94f 100644 (file)
@@ -18,7 +18,6 @@
 
 #include <haproxy/api.h>
 #include <common/chunk.h>
-#include <common/debug.h>
 #include <common/http.h>
 #include <common/memory.h>
 #include <common/standard.h>
index 5d7ae8828e3a388800cef478a8e72e88c2d6b0ed..96d44ab6072f0968a0aeeb0a6e80c3e0b4df6348 100644 (file)
@@ -19,7 +19,6 @@
 #include <haproxy/api.h>
 #include <haproxy/base64.h>
 #include <common/chunk.h>
-#include <common/debug.h>
 #include <common/h1.h>
 #include <common/http.h>
 #include <common/htx.h>
index f4a60042494bfaacd31aa74088b62bb7cf3496c2..38a91cc41937cd1827d2a35549d2e0b0a9677fa2 100644 (file)
@@ -17,7 +17,6 @@
 #include <haproxy/api.h>
 #include <types/global.h>
 
-#include <common/debug.h>
 #include <common/cfgparse.h>
 #include <common/h1.h>
 #include <common/http.h>
index 2661062ee3cfc81e37409389ecf6d541381c0980..6a5a5f33bd50d43fce60ef4810a4d8a5d56855ba 100644 (file)
@@ -19,7 +19,6 @@
 #include <haproxy/api.h>
 #include <common/cfgparse.h>
 #include <common/chunk.h>
-#include <common/debug.h>
 #include <common/http.h>
 #include <common/memory.h>
 #include <common/standard.h>
index b216541239dad7b56fd55822ae9ce6611b68dff6..0899ee76efaf8bb4ae9fba0b7a738c74e6b2adae 100644 (file)
@@ -17,7 +17,6 @@
  */
 
 #include <haproxy/api.h>
-#include <common/debug.h>
 #include <common/standard.h>
 #include <import/eb32tree.h>
 
index ef507b7cb38f0b04976ace372654e69bd983e4ef..72e9c9c0338dd610fcc85c7be0dbf7bdf378194a 100644 (file)
@@ -17,7 +17,6 @@
  */
 
 #include <haproxy/api.h>
-#include <common/debug.h>
 #include <import/eb32tree.h>
 
 #include <types/global.h>
index 89634bfe4fc6a117a18c81730d159e3604f3c6b1..b9cc9878b3b1d67162ec82c7631d2c353449b90c 100644 (file)
@@ -11,7 +11,6 @@
  */
 
 #include <haproxy/api.h>
-#include <common/debug.h>
 #include <import/eb32tree.h>
 
 #include <types/global.h>
index 31e8bb2d10e39671e45f17dcfc00170a67c1e8d1..6f87697416b682c37d1553684658b7517682178c 100644 (file)
@@ -11,7 +11,6 @@
  */
 
 #include <haproxy/api.h>
-#include <common/debug.h>
 #include <import/eb32tree.h>
 
 #include <types/global.h>
index 660475b961d719d3323005dc1d6516c6f6a6ae11..8d2461fcf0430889a3672cac9c48503da449f0d7 100644 (file)
@@ -11,7 +11,6 @@
  */
 
 #include <haproxy/api.h>
-#include <common/debug.h>
 #include <import/eb32tree.h>
 
 #include <types/global.h>
index 437ce10da0672b258c4a140e951c9d04a8fcfb3f..961a292c233d67d84025014b236918e251fb426c 100644 (file)
@@ -18,7 +18,6 @@
 #include <types/stats.h>
 
 #include <common/cfgparse.h>
-#include <common/debug.h>
 #include <common/hathreads.h>
 #include <common/memory.h>
 #include <common/mini-clist.h>
index ff642f26d49cd4a556a27a5feeaaf3c4c4cd70f5..c95d5d46f974df7fd4dc61fe67b8cd4d5eb79bd1 100644 (file)
@@ -27,7 +27,6 @@
 #include <sys/un.h>
 
 #include <haproxy/api.h>
-#include <common/debug.h>
 #include <haproxy/errors.h>
 #include <common/mini-clist.h>
 #include <common/standard.h>
index 063f4b363819ce1a7550df34e86c1385eb3aaa44..9233288fd7c241da85d0ef4f672ec6b65db80d7d 100644 (file)
@@ -31,7 +31,6 @@
 #include <netinet/in.h>
 
 #include <haproxy/api.h>
-#include <common/debug.h>
 #include <haproxy/errors.h>
 #include <common/mini-clist.h>
 #include <common/standard.h>
index 5fc976a63aa528604d03a9b3e6fd3a19d831515e..648f3a32f9ba93679c88f3cd60b0245b70933936 100644 (file)
@@ -27,7 +27,6 @@
 #include <sys/un.h>
 
 #include <haproxy/api.h>
-#include <common/debug.h>
 #include <haproxy/errors.h>
 #include <common/mini-clist.h>
 #include <common/standard.h>
index af8cc65afb5b185d3d8e8de1820122cb4bbd2a29..3612442c16623dc4b2f15a4617346da7a428fa45 100644 (file)
@@ -24,7 +24,6 @@
 
 #include <haproxy/api.h>
 #include <common/buffer.h>
-#include <common/debug.h>
 #include <common/standard.h>
 #include <common/ticks.h>
 #include <common/time.h>
index fd842a4041971d21760b86d3295d642a9a27b673..3f26cd47732b735d2b713c92740c668400974462 100644 (file)
@@ -12,7 +12,6 @@
 
 #include <haproxy/api.h>
 #include <common/buffer.h>
-#include <common/debug.h>
 #include <common/http.h>
 #include <common/memory.h>
 
index d11eaaf197cae64c4f67a693de7675cbcc813e13..c2bea22a09878134bcf19a95f7eade17b0080af0 100644 (file)
@@ -46,7 +46,6 @@
 
 #include <common/buffer.h>
 #include <common/chunk.h>
-#include <common/debug.h>
 #include <haproxy/errors.h>
 #include <haproxy/openssl-compat.h>
 #include <common/standard.h>
index 9030603810f940be53c60ddc3fb6dcbb0f04fa54..0c030379c80688dfbb9134fc214f972801ab7616 100644 (file)
@@ -17,7 +17,6 @@
 #include <haproxy/api.h>
 #include <common/cfgparse.h>
 #include <common/buffer.h>
-#include <common/debug.h>
 #include <common/hathreads.h>
 #include <common/htx.h>
 #include <common/memory.h>
index fc75c39fc55c70e92c055212a93983f22f2066a3..91f844b9714beab02d2d15105ee0b0e5ff424273 100644 (file)
@@ -21,7 +21,6 @@
 
 #include <haproxy/api.h>
 #include <common/buffer.h>
-#include <common/debug.h>
 #include <common/standard.h>
 #include <common/ticks.h>
 #include <common/time.h>
index 58e67ca765759ab150f9fa2f11b2b16301c1e230..0be4ecdf2275f56d80d11b7f33470d27bed58a33 100644 (file)
@@ -11,7 +11,6 @@
  */
 #include <haproxy/api.h>
 #include <common/cfgparse.h>
-#include <common/debug.h>
 #include <common/mini-clist.h>
 #include <common/standard.h>
 #include <common/ticks.h>