MINOR: flags/fd: decode FD flags states

The new function is fd_show_flags() and it reports known FD flags:

  $ ./dev/flags/flags fd 0x000121
  fd->flags = FD_POLL_IN | FD_EV_READY_W | FD_EV_ACTIVE_R
diff --git a/dev/flags/flags.c b/dev/flags/flags.c
index ac933e2..d867ba2 100644
--- a/dev/flags/flags.c
+++ b/dev/flags/flags.c
@@ -3,9 +3,10 @@
 
 #include <haproxy/channel-t.h>
 #include <haproxy/connection-t.h>
-#include <haproxy/stconn-t.h>
+#include <haproxy/fd-t.h>
 #include <haproxy/http_ana-t.h>
 #include <haproxy/htx-t.h>
+#include <haproxy/stconn-t.h>
 #include <haproxy/stream-t.h>
 #include <haproxy/task-t.h>
 
@@ -22,10 +23,11 @@
 #define SHOW_AS_HSL   0x00000200
 #define SHOW_AS_HTX   0x00000400
 #define SHOW_AS_HMSG  0x00000800
+#define SHOW_AS_FD    0x00001000
 
 // command line names, must be in exact same order as the SHOW_AS_* flags above
 // so that show_as_words[i] matches flag 1U<<i.
-const char *show_as_words[] = { "ana", "chn", "conn", "sc", "stet", "strm", "task", "txn", "sd", "hsl", "htx", "hmsg", };
+const char *show_as_words[] = { "ana", "chn", "conn", "sc", "stet", "strm", "task", "txn", "sd", "hsl", "htx", "hmsg", "fd", };
 
 /* will be sufficient for even largest flag names */
 static char buf[4096];
@@ -131,6 +133,7 @@
 		if (show_as & SHOW_AS_HSL)   printf("sl->flags = %s\n",   (hsl_show_flags    (buf, bsz, " | ", flags), buf));
 		if (show_as & SHOW_AS_HTX)   printf("htx->flags = %s\n",  (htx_show_flags    (buf, bsz, " | ", flags), buf));
 		if (show_as & SHOW_AS_HMSG)  printf("hmsg->flags = %s\n", (hmsg_show_flags   (buf, bsz, " | ", flags), buf));
+		if (show_as & SHOW_AS_FD)    printf("fd->flags = %s\n",   (fd_show_flags     (buf, bsz, " | ", flags), buf));
 	}
 	return 0;
 }
diff --git a/include/haproxy/fd-t.h b/include/haproxy/fd-t.h
index cecf797..b2ca87c 100644
--- a/include/haproxy/fd-t.h
+++ b/include/haproxy/fd-t.h
@@ -24,6 +24,7 @@
 
 #include <haproxy/api-t.h>
 #include <haproxy/port_range-t.h>
+#include <haproxy/show_flags-t.h>
 
 /* Direction for each FD event update */
 enum {
@@ -112,6 +113,27 @@
 #define FD_EXCL_SYSCALL     (1U << FD_EXCL_SYSCALL_BIT)
 #define FD_DISOWN           (1U << FD_DISOWN_BIT)
 
+/* This function is used to report flags in debugging tools. Please reflect
+ * below any single-bit flag addition above in the same order via the
+ * __APPEND_FLAG macro. The new end of the buffer is returned.
+ */
+static forceinline char *fd_show_flags(char *buf, size_t len, const char *delim, uint flg)
+{
+#define _(f, ...) __APPEND_FLAG(buf, len, delim, flg, f, #f, __VA_ARGS__)
+	/* prologue */
+	_(0);
+	/* flags */
+	_(FD_EV_ACTIVE_R, _(FD_EV_ACTIVE_W, _(FD_EV_READY_R, _(FD_EV_READY_W,
+	_(FD_EV_SHUT_R, _(FD_EV_SHUT_W, _(FD_EV_ERR_RW, _(FD_POLL_IN,
+	_(FD_POLL_PRI, _(FD_POLL_OUT, _(FD_POLL_ERR, _(FD_POLL_HUP,
+	_(FD_LINGER_RISK, _(FD_CLONED, _(FD_INITIALIZED, _(FD_ET_POSSIBLE,
+	_(FD_EXPORTED, _(FD_EXCL_SYSCALL, _(FD_DISOWN)))))))))))))))))));
+	/* epilogue */
+	_(~0U);
+	return buf;
+#undef _
+}
+
 /* FD update status after fd_update_events() */
 enum {
 	FD_UPDT_DONE = 0,    // update done, nothing else to be done