From 354b6f5e288f466aed48d46dd8467b023a0b3660 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Thu, 6 Feb 2020 08:33:08 +0100 Subject: [PATCH] CONTRIB: debug: add the possibility to decode the value as certain types only It's often confusing to have a whole dump on the screen while only checking for a set of task or stream flags, and appending "|grep ^chn" isn't very convenient to repeat the opeation. Instead let's add the ability to filter the output as certain types only by prepending their name(s) before the value. --- contrib/debug/flags.c | 77 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 64 insertions(+), 13 deletions(-) diff --git a/contrib/debug/flags.c b/contrib/debug/flags.c index c5315f4c2a..e164c9345a 100644 --- a/contrib/debug/flags.c +++ b/contrib/debug/flags.c @@ -8,6 +8,21 @@ #include #include +// 1 bit per flag, no hole permitted here +#define SHOW_AS_ANA 0x00000001 +#define SHOW_AS_CHN 0x00000002 +#define SHOW_AS_CONN 0x00000004 +#define SHOW_AS_CS 0x00000008 +#define SHOW_AS_SI 0x00000010 +#define SHOW_AS_SIET 0x00000020 +#define SHOW_AS_STRM 0x00000040 +#define SHOW_AS_TASK 0x00000080 +#define SHOW_AS_TXN 0x00000100 + +// command line names, must be in exact same order as the SHOW_AS_* flags above +// so that show_as_words[i] matches flag 1U<ana = "); @@ -365,26 +393,49 @@ void show_strm_flags(unsigned int f) putchar('\n'); } +void usage_exit(const char *name) +{ + fprintf(stderr, "Usage: %s [ana|chn|conn|cs|si|sierr|strm|task|txn]* [0x]value\n", name); + exit(1); +} + int main(int argc, char **argv) { unsigned int flags; + unsigned int show_as = 0; + unsigned int f; + const char *name = argv[0]; + char *err; - if (argc < 2) { - fprintf(stderr, "Usage: %s 0x\n", argv[0]); - exit(1); + while (argc > 0) { + argv++; argc--; + if (argc < 1) + usage_exit(name); + + flags = strtoul(argv[0], &err, 0); + if (*argv[0] && !*err) + break; + + f = get_show_as(argv[0]); + if (!f) { + fprintf(stderr, "Unknown argument: <%s>\n", argv[0]); + usage_exit(name); + } + show_as |= f; } - flags = strtoul(argv[1], NULL, 0); + if (!show_as) + show_as = ~0U; - show_task_state(flags); - show_txn_flags(flags); - show_strm_flags(flags); - show_si_et(flags); - show_si_flags(flags); - show_cs_flags(flags); - show_conn_flags(flags); - show_chn_flags(flags); - show_chn_ana(flags); + if (show_as & SHOW_AS_ANA) show_chn_ana(flags); + if (show_as & SHOW_AS_CHN) show_chn_flags(flags); + if (show_as & SHOW_AS_CONN) show_conn_flags(flags); + if (show_as & SHOW_AS_CS) show_cs_flags(flags); + if (show_as & SHOW_AS_SI) show_si_flags(flags); + if (show_as & SHOW_AS_SIET) show_si_et(flags); + if (show_as & SHOW_AS_STRM) show_strm_flags(flags); + if (show_as & SHOW_AS_TASK) show_task_state(flags); + if (show_as & SHOW_AS_TXN) show_txn_flags(flags); return 0; }