Skip to contentSkip to conversation

src: use printf() instead of pr_debug() whenever possible

PATCH In review Pablo Neira Ayuso 2 participants 3 messages Jan 8, 2015 netfilter

lore
Share & tools
lore

Pablo Neira Ayuso

author maintainer
#0 lore raw

PATCH 1/1 src: use printf() instead of pr_debug() whenever possible

pr_debug() is disabled with --with-mini-gmp since it relies on the gmp_printf(), which is not available in the mini-gmp implementation. Use printf() instead of pr_debug() if no mpz_t types are used, so we get debugging information for proto-ctx as well.

This leaves the pr_debug() usage limited to src/segtree.c.

---
 src/netlink_delinearize.c |    2 --
 src/proto.c               |   14 +++++++-------
 2 files changed, 7 insertions(+), 9 deletions(-)
src/netlink_delinearize.c +0 -2
index e9a04dd..b34d586 100644
@@ -915,8 +915,6 @@ static void expr_postprocess(struct rule_pp_ctx *ctx,
 {
 	struct expr *expr = *exprp, *i;
 
-	//pr_debug("%s len %u\n", expr->ops->name, expr->len);
-
 	switch (expr->ops->type) {
 	case EXPR_MAP:
 		expr_postprocess(ctx, stmt, &expr->map);
src/proto.c +7 -7
index 7dc7b3e..6a12ee8 100644
@@ -137,15 +137,15 @@ static void proto_ctx_debug(const struct proto_ctx *ctx, enum proto_bases base)
 	if (!(debug_level & DEBUG_PROTO_CTX))
 		return;
 
-	pr_debug("update %s protocol context:\n", proto_base_names[base]);
+	printf("update %s protocol context:\n", proto_base_names[base]);
 	for (i = PROTO_BASE_LL_HDR; i <= PROTO_BASE_MAX; i++) {
-		pr_debug(" %-20s: %s%s\n",
-			 proto_base_names[i],
-			 ctx->protocol[i].desc ? ctx->protocol[i].desc->name :
-						 "none",
-			 i == base ? " <-" : "");
+		printf(" %-20s: %s%s\n",
+		       proto_base_names[i],
+		       ctx->protocol[i].desc ? ctx->protocol[i].desc->name :
+					       "none",
+		       i == base ? " <-" : "");
 	}
-	pr_debug("\n");
+	printf("\n");
 #endif
 }
 
Signature · 1 line
1.7.10.4
#1 lore raw
Quoted 6 lines · Pablo Neira Ayuso

pr_debug() is disabled with --with-mini-gmp since it relies on the gmp_printf(), which is not available in the mini-gmp implementation. Use printf() instead of pr_debug() if no mpz_t types are used, so we get debugging information for proto-ctx as well.

This leaves the pr_debug() usage limited to src/segtree.c.

I don't think this patch is conceptually good. The intention of pr_debug() is to be able to disable debugging at compile time to avoid ifdefs everywhere.

We currently need them for external debugging functions like mnl, but f.i. in proto_ctx_debug() the compiler should very well be able to determine that the function is a NOP without debugging enabled.

I'd rather change pr_debug to a normal printf and adapt segtree to use a pr_gmp_debug or something like that.

author maintainer
#2 lore raw
Quoted 2 lines · Patrick McHardy

I'd rather change pr_debug to a normal printf and adapt segtree to use a pr_gmp_debug or something like that.

Good idea, patch will follow up soon. Thanks Patrick.