Skip to contentSkip to conversation

src: rename pr_debug() to pr_gmp_debug() and use printf() 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: rename pr_debug() to pr_gmp_debug() and use printf() whenever possible

Rename pr_debug() to pr_gmp_debug() so the new function name reminds us the explicit dependency with libgmp, as suggested by Patrick.

Moreover, use printf() instead of pr_debug() if no mpz_t types are used, so we get debugging information for proto-ctx as well.

pr_gmp_debug() is disabled with --with-mini-gmp since it relies on the gmp_printf(), which is not available in the mini-gmp implementation.

---
 include/utils.h           |    4 ++--
 src/netlink_delinearize.c |    2 --
 src/proto.c               |   14 +++++++-------
 src/segtree.c             |   14 +++++++-------
 4 files changed, 16 insertions(+), 18 deletions(-)
include/utils.h +2 -2
index dcefc6b..afe468c 100644
@@ -14,9 +14,9 @@
 #define BITS_PER_BYTE	8
 
 #if defined(DEBUG) && defined(HAVE_LIBGMP)
-#define pr_debug(fmt, arg...) gmp_printf(fmt, ##arg)
+#define pr_gmp_debug(fmt, arg...) gmp_printf(fmt, ##arg)
 #else
-#define pr_debug(fmt, arg...) ({ if (false) {}; 0; })
+#define pr_gmp_debug(fmt, arg...) ({ if (false) {}; 0; })
 #endif
 
 #define __fmtstring(x, y)	__attribute__((format(printf, x, y)))
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
 }
 
src/segtree.c +7 -7
index 753d8b8..a72e6b8 100644
@@ -190,7 +190,7 @@ static void ei_insert(struct seg_tree *tree, struct elementary_interval *new)
 	rei = ei_lookup(tree, new->right);
 
 	if (segtree_debug())
-		pr_debug("insert: [%Zx %Zx]\n", new->left, new->right);
+		pr_gmp_debug("insert: [%Zx %Zx]\n", new->left, new->right);
 
 	if (lei != NULL && rei != NULL && lei == rei) {
 		/*
@@ -200,7 +200,7 @@ static void ei_insert(struct seg_tree *tree, struct elementary_interval *new)
 		 * [lei_left, new_left) and (new_right, rei_right]
 		 */
 		if (segtree_debug())
-			pr_debug("split [%Zx %Zx]\n", lei->left, lei->right);
+			pr_gmp_debug("split [%Zx %Zx]\n", lei->left, lei->right);
 
 		ei_remove(tree, lei);
 
@@ -220,7 +220,7 @@ static void ei_insert(struct seg_tree *tree, struct elementary_interval *new)
 			 * [lei_left, new_left)[new_left, new_right]
 			 */
 			if (segtree_debug()) {
-				pr_debug("adjust left [%Zx %Zx]\n",
+				pr_gmp_debug("adjust left [%Zx %Zx]\n",
 					 lei->left, lei->right);
 			}
 
@@ -238,7 +238,7 @@ static void ei_insert(struct seg_tree *tree, struct elementary_interval *new)
 			 * [new_left, new_right](new_right, rei_right]
 			 */
 			if (segtree_debug()) {
-				pr_debug("adjust right [%Zx %Zx]\n",
+				pr_gmp_debug("adjust right [%Zx %Zx]\n",
 					 rei->left, rei->right);
 			}
 
@@ -358,7 +358,7 @@ static void segtree_linearize(struct list_head *list, struct seg_tree *tree)
 	 */
 	rb_for_each_entry_safe(ei, node, next, &tree->root, rb_node) {
 		if (segtree_debug())
-			pr_debug("iter: [%Zx %Zx]\n", ei->left, ei->right);
+			pr_gmp_debug("iter: [%Zx %Zx]\n", ei->left, ei->right);
 
 		if (prev == NULL) {
 			/*
@@ -443,7 +443,7 @@ int set_to_intervals(struct list_head *errs, struct set *set)
 
 	list_for_each_entry_safe(ei, next, &list, list) {
 		if (segtree_debug()) {
-			pr_debug("list: [%.*Zx %.*Zx]\n",
+			pr_gmp_debug("list: [%.*Zx %.*Zx]\n",
 				 2 * tree.keylen / BITS_PER_BYTE, ei->left,
 				 2 * tree.keylen / BITS_PER_BYTE, ei->right);
 		}
@@ -453,7 +453,7 @@ int set_to_intervals(struct list_head *errs, struct set *set)
 
 	if (segtree_debug()) {
 		expr_print(set->init);
-		pr_debug("\n");
+		pr_gmp_debug("\n");
 	}
 	return 0;
 }
Signature · 1 line
1.7.10.4
#1 lore raw
Quoted 8 lines · Pablo Neira Ayuso

Rename pr_debug() to pr_gmp_debug() so the new function name reminds us the explicit dependency with libgmp, as suggested by Patrick.

Moreover, use printf() instead of pr_debug() if no mpz_t types are used, so we get debugging information for proto-ctx as well.

pr_gmp_debug() is disabled with --with-mini-gmp since it relies on the gmp_printf(), which is not available in the mini-gmp implementation.

Not entirely, my suggestion was to keep the existing instances of pr_debug() (mapped to printf) everywhere but in segtree.

Quoted 13 lines
src/proto.c +1 -5
@@ -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",

src/proto.c static void proto_ctx_debug(const struct proto_ctx *ctx, enum proto_bases base) · line 149

Quoted 10 lines
src/proto.c +6 -2
-			 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

So I wouldn't change this.

#2 lore raw
In reply to Pablo Neira Ayuso

src/segtree.c static void ei_insert(struct seg_tree *tree, struct elementary_interval *new) · line 224

Quoted 10 lines · Pablo Neira Ayuso

index 753d8b8..a72e6b8 100644

src/segtree.c +1 -1
@@ -220,7 +220,7 @@ static void ei_insert(struct seg_tree *tree, struct elementary_interval *new)
 			 * [lei_left, new_left)[new_left, new_right]
 			 */
 			if (segtree_debug()) {
-				pr_debug("adjust left [%Zx %Zx]\n",
+				pr_gmp_debug("adjust left [%Zx %Zx]\n",
 					 lei->left, lei->right);

Also please keep the parameter alignment to the opening bracket.