Date: Tue, 12 Feb 2013 08:56:09 +0100 From: Christoph Mallon <christoph.mallon@gmx.de> To: FreeBSD-gnats-submit@freebsd.org Subject: kern/176051: [PATCH] uipc: Simplify and correct debug printing of flags. Message-ID: <E1U5Ain-0006oh-FR@rotluchs.lokal> Resent-Message-ID: <201302120800.r1C800IT022167@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
>Number: 176051 >Category: kern >Synopsis: [PATCH] uipc: Simplify and correct debug printing of flags. >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: update >Submitter-Id: current-users >Arrival-Date: Tue Feb 12 08:00:00 UTC 2013 >Closed-Date: >Last-Modified: >Originator: Christoph Mallon >Release: FreeBSD 9.1-STABLE amd64 >Organization: >Environment: >Description: The code to print uipc flags contains lots of code duplication and in one case even prints wrong flag names (SS_* instead of SBS_*). This patch simplifies and corrects the code by introducing two simple macros to handle printing the flags. >How-To-Repeat: >Fix: Please apply this patch. --- 0001-uipc-Simplify-and-correct-debug-printing-of-flags.patch begins here --- >From 56e214f5eb0b4b54584f62d49a4b1e5cee335286 Mon Sep 17 00:00:00 2001 From: Christoph Mallon <christoph.mallon@gmx.de> Date: Thu, 17 Jan 2013 13:39:31 +0100 Subject: [PATCH] uipc: Simplify and correct debug printing of flags. This reduces code duplication and corrects printing the sb_states, which were incorrectly shown as SS_*. --- sys/kern/uipc_debug.c | 255 +++++++++++++------------------------------------- 1 file changed, 63 insertions(+), 192 deletions(-) diff --git a/sys/kern/uipc_debug.c b/sys/kern/uipc_debug.c index 57f4017..51e88aa 100644 --- a/sys/kern/uipc_debug.c +++ b/sys/kern/uipc_debug.c @@ -43,6 +43,11 @@ __FBSDID("$FreeBSD$"); #ifdef DDB #include <ddb/ddb.h> +#define PRINT_FLAG_INIT \ + int sep = 2 +#define PRINT_FLAG(var, flag) \ + ((var) & (flag) ? db_printf(", " #flag + sep), (void)(sep = 0) : (void)0) + static void db_print_sotype(short so_type) { @@ -77,149 +82,58 @@ db_print_sotype(short so_type) static void db_print_sooptions(short so_options) { - int comma; - - comma = 0; - if (so_options & SO_DEBUG) { - db_printf("%sSO_DEBUG", comma ? ", " : ""); - comma = 1; - } - if (so_options & SO_ACCEPTCONN) { - db_printf("%sSO_ACCEPTCONN", comma ? ", " : ""); - comma = 1; - } - if (so_options & SO_REUSEADDR) { - db_printf("%sSO_REUSEADDR", comma ? ", " : ""); - comma = 1; - } - if (so_options & SO_KEEPALIVE) { - db_printf("%sSO_KEEPALIVE", comma ? ", " : ""); - comma = 1; - } - if (so_options & SO_DONTROUTE) { - db_printf("%sSO_DONTROUTE", comma ? ", " : ""); - comma = 1; - } - if (so_options & SO_BROADCAST) { - db_printf("%sSO_BROADCAST", comma ? ", " : ""); - comma = 1; - } - if (so_options & SO_USELOOPBACK) { - db_printf("%sSO_USELOOPBACK", comma ? ", " : ""); - comma = 1; - } - if (so_options & SO_LINGER) { - db_printf("%sSO_LINGER", comma ? ", " : ""); - comma = 1; - } - if (so_options & SO_OOBINLINE) { - db_printf("%sSO_OOBINLINE", comma ? ", " : ""); - comma = 1; - } - if (so_options & SO_REUSEPORT) { - db_printf("%sSO_REUSEPORT", comma ? ", " : ""); - comma = 1; - } - if (so_options & SO_TIMESTAMP) { - db_printf("%sSO_TIMESTAMP", comma ? ", " : ""); - comma = 1; - } - if (so_options & SO_NOSIGPIPE) { - db_printf("%sSO_NOSIGPIPE", comma ? ", " : ""); - comma = 1; - } - if (so_options & SO_ACCEPTFILTER) { - db_printf("%sSO_ACCEPTFILTER", comma ? ", " : ""); - comma = 1; - } - if (so_options & SO_BINTIME) { - db_printf("%sSO_BINTIME", comma ? ", " : ""); - comma = 1; - } - if (so_options & SO_NO_OFFLOAD) { - db_printf("%sSO_NO_OFFLOAD", comma ? ", " : ""); - comma = 1; - } - if (so_options & SO_NO_DDP) { - db_printf("%sSO_NO_DDP", comma ? ", " : ""); - comma = 1; - } + PRINT_FLAG_INIT; + + PRINT_FLAG(so_options, SO_DEBUG); + PRINT_FLAG(so_options, SO_ACCEPTCONN); + PRINT_FLAG(so_options, SO_REUSEADDR); + PRINT_FLAG(so_options, SO_KEEPALIVE); + PRINT_FLAG(so_options, SO_DONTROUTE); + PRINT_FLAG(so_options, SO_BROADCAST); + PRINT_FLAG(so_options, SO_USELOOPBACK); + PRINT_FLAG(so_options, SO_LINGER); + PRINT_FLAG(so_options, SO_OOBINLINE); + PRINT_FLAG(so_options, SO_REUSEPORT); + PRINT_FLAG(so_options, SO_TIMESTAMP); + PRINT_FLAG(so_options, SO_NOSIGPIPE); + PRINT_FLAG(so_options, SO_ACCEPTFILTER); + PRINT_FLAG(so_options, SO_BINTIME); + PRINT_FLAG(so_options, SO_NO_OFFLOAD); + PRINT_FLAG(so_options, SO_NO_DDP); } static void db_print_sostate(short so_state) { - int comma; - - comma = 0; - if (so_state & SS_NOFDREF) { - db_printf("%sSS_NOFDREF", comma ? ", " : ""); - comma = 1; - } - if (so_state & SS_ISCONNECTED) { - db_printf("%sSS_ISCONNECTED", comma ? ", " : ""); - comma = 1; - } - if (so_state & SS_ISCONNECTING) { - db_printf("%sSS_ISCONNECTING", comma ? ", " : ""); - comma = 1; - } - if (so_state & SS_ISDISCONNECTING) { - db_printf("%sSS_ISDISCONNECTING", comma ? ", " : ""); - comma = 1; - } - if (so_state & SS_NBIO) { - db_printf("%sSS_NBIO", comma ? ", " : ""); - comma = 1; - } - if (so_state & SS_ASYNC) { - db_printf("%sSS_ASYNC", comma ? ", " : ""); - comma = 1; - } - if (so_state & SS_ISCONFIRMING) { - db_printf("%sSS_ISCONFIRMING", comma ? ", " : ""); - comma = 1; - } - if (so_state & SS_PROTOREF) { - db_printf("%sSS_PROTOREF", comma ? ", " : ""); - comma = 1; - } + PRINT_FLAG_INIT; + + PRINT_FLAG(so_state, SS_NOFDREF); + PRINT_FLAG(so_state, SS_ISCONNECTED); + PRINT_FLAG(so_state, SS_ISCONNECTING); + PRINT_FLAG(so_state, SS_ISDISCONNECTING); + PRINT_FLAG(so_state, SS_NBIO); + PRINT_FLAG(so_state, SS_ASYNC); + PRINT_FLAG(so_state, SS_ISCONFIRMING); + PRINT_FLAG(so_state, SS_PROTOREF); } static void db_print_soqstate(int so_qstate) { - int comma; + PRINT_FLAG_INIT; - comma = 0; - if (so_qstate & SQ_INCOMP) { - db_printf("%sSQ_INCOMP", comma ? ", " : ""); - comma = 1; - } - if (so_qstate & SQ_COMP) { - db_printf("%sSQ_COMP", comma ? ", " : ""); - comma = 1; - } + PRINT_FLAG(so_qstate, SQ_INCOMP); + PRINT_FLAG(so_qstate, SQ_COMP); } static void db_print_sbstate(short sb_state) { - int comma; + PRINT_FLAG_INIT; - comma = 0; - if (sb_state & SBS_CANTSENDMORE) { - db_printf("%sSS_CANTSENDMORE", comma ? ", " : ""); - comma = 1; - } - if (sb_state & SBS_CANTRCVMORE) { - db_printf("%sSS_CANTRCVMORE", comma ? ", " : ""); - comma = 1; - } - if (sb_state & SBS_RCVATMARK) { - db_printf("%sSS_RCVATMARK", comma ? ", " : ""); - comma = 1; - } + PRINT_FLAG(sb_state, SBS_CANTSENDMORE); + PRINT_FLAG(sb_state, SBS_CANTRCVMORE); + PRINT_FLAG(sb_state, SBS_RCVATMARK); } static void @@ -266,37 +180,15 @@ db_print_domain(struct domain *d, const char *domain_name, int indent) static void db_print_prflags(short pr_flags) { - int comma; - - comma = 0; - if (pr_flags & PR_ATOMIC) { - db_printf("%sPR_ATOMIC", comma ? ", " : ""); - comma = 1; - } - if (pr_flags & PR_ADDR) { - db_printf("%sPR_ADDR", comma ? ", " : ""); - comma = 1; - } - if (pr_flags & PR_CONNREQUIRED) { - db_printf("%sPR_CONNREQUIRED", comma ? ", " : ""); - comma = 1; - } - if (pr_flags & PR_WANTRCVD) { - db_printf("%sPR_WANTRCVD", comma ? ", " : ""); - comma = 1; - } - if (pr_flags & PR_RIGHTS) { - db_printf("%sPR_RIGHTS", comma ? ", " : ""); - comma = 1; - } - if (pr_flags & PR_IMPLOPCL) { - db_printf("%sPR_IMPLOPCL", comma ? ", " : ""); - comma = 1; - } - if (pr_flags & PR_LASTHDR) { - db_printf("%sPR_LASTHDR", comma ? ", " : ""); - comma = 1; - } + PRINT_FLAG_INIT; + + PRINT_FLAG(pr_flags, PR_ATOMIC); + PRINT_FLAG(pr_flags, PR_ADDR); + PRINT_FLAG(pr_flags, PR_CONNREQUIRED); + PRINT_FLAG(pr_flags, PR_WANTRCVD); + PRINT_FLAG(pr_flags, PR_RIGHTS); + PRINT_FLAG(pr_flags, PR_IMPLOPCL); + PRINT_FLAG(pr_flags, PR_LASTHDR); } static void @@ -342,41 +234,16 @@ db_print_protosw(struct protosw *pr, const char *prname, int indent) static void db_print_sbflags(short sb_flags) { - int comma; - - comma = 0; - if (sb_flags & SB_WAIT) { - db_printf("%sSB_WAIT", comma ? ", " : ""); - comma = 1; - } - if (sb_flags & SB_SEL) { - db_printf("%sSB_SEL", comma ? ", " : ""); - comma = 1; - } - if (sb_flags & SB_ASYNC) { - db_printf("%sSB_ASYNC", comma ? ", " : ""); - comma = 1; - } - if (sb_flags & SB_UPCALL) { - db_printf("%sSB_UPCALL", comma ? ", " : ""); - comma = 1; - } - if (sb_flags & SB_NOINTR) { - db_printf("%sSB_NOINTR", comma ? ", " : ""); - comma = 1; - } - if (sb_flags & SB_AIO) { - db_printf("%sSB_AIO", comma ? ", " : ""); - comma = 1; - } - if (sb_flags & SB_KNOTE) { - db_printf("%sSB_KNOTE", comma ? ", " : ""); - comma = 1; - } - if (sb_flags & SB_AUTOSIZE) { - db_printf("%sSB_AUTOSIZE", comma ? ", " : ""); - comma = 1; - } + PRINT_FLAG_INIT; + + PRINT_FLAG(sb_flags, SB_WAIT); + PRINT_FLAG(sb_flags, SB_SEL); + PRINT_FLAG(sb_flags, SB_ASYNC); + PRINT_FLAG(sb_flags, SB_UPCALL); + PRINT_FLAG(sb_flags, SB_NOINTR); + PRINT_FLAG(sb_flags, SB_AIO); + PRINT_FLAG(sb_flags, SB_KNOTE); + PRINT_FLAG(sb_flags, SB_AUTOSIZE); } static void @@ -528,4 +395,8 @@ DB_SHOW_COMMAND(domain, db_show_domain) db_print_domain(d, "domain", 0); } + +#undef PRINT_FLAG +#undef PRINT_FLAG_INIT + #endif -- 1.8.1.3 --- 0001-uipc-Simplify-and-correct-debug-printing-of-flags.patch ends here --- >Release-Note: >Audit-Trail: >Unformatted:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?E1U5Ain-0006oh-FR>