summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorroot <root@debian.localnet>2012-12-08 18:08:44 +0100
committerPatrick McHardy <kaber@trash.net>2012-12-08 18:11:20 +0100
commit47ff571046570e8f70f545de162e09c2ff147f80 (patch)
tree177823218da0ae77ce0514d60ee77e845c74eade
parent84792b4813a4ebf59e546acfac80144775e0d47e (diff)
debug: include verbose message in all BUG statements
Signed-off-by: Patrick McHardy <kaber@trash.net>
-rw-r--r--include/utils.h6
-rw-r--r--src/datatype.c4
-rw-r--r--src/erec.c2
-rw-r--r--src/evaluate.c32
-rw-r--r--src/netlink.c2
-rw-r--r--src/netlink_delinearize.c6
-rw-r--r--src/netlink_linearize.c14
-rw-r--r--src/rule.c12
-rw-r--r--src/segtree.c4
9 files changed, 44 insertions, 38 deletions
diff --git a/include/utils.h b/include/utils.h
index 15271e5b..854986f2 100644
--- a/include/utils.h
+++ b/include/utils.h
@@ -30,7 +30,11 @@
#define __must_check __attribute__((warn_unused_result))
#define __noreturn __attribute__((__noreturn__))
-#define BUG() assert(0)
+#ifdef DEBUG
+#define BUG(fmt, arg...) ({ fprintf(stderr, "BUG: " fmt, ##arg); assert(0); })
+#else
+#define BUG(fmt, arg...) assert(0)
+#endif
#define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))
#define BUILD_BUG_ON_ZERO(e) (sizeof(char[1 - 2 * !!(e)]) - 1)
diff --git a/src/datatype.c b/src/datatype.c
index 70670e97..f369d5f0 100644
--- a/src/datatype.c
+++ b/src/datatype.c
@@ -73,7 +73,7 @@ void datatype_print(const struct expr *expr)
return dtype->print(expr);
if (dtype->sym_tbl != NULL)
return symbolic_constant_print(dtype->sym_tbl, expr);
- BUG();
+ BUG("datatype has no print method or symbol table\n");
}
struct error_record *symbol_parse(const struct expr *sym,
@@ -184,7 +184,7 @@ static void verdict_type_print(const struct expr *expr)
printf("return");
break;
default:
- BUG();
+ BUG("invalid verdict value %u\n", expr->verdict);
}
}
diff --git a/src/erec.c b/src/erec.c
index 554a406c..f2b0ce66 100644
--- a/src/erec.c
+++ b/src/erec.c
@@ -97,7 +97,7 @@ void erec_print(FILE *f, const struct error_record *erec)
case INDESC_NETLINK:
break;
default:
- BUG();
+ BUG("invalid input descriptor type %u\n", indesc->type);
}
if (indesc->type == INDESC_NETLINK) {
diff --git a/src/evaluate.c b/src/evaluate.c
index ad3cefb9..a2cc8e45 100644
--- a/src/evaluate.c
+++ b/src/evaluate.c
@@ -142,7 +142,8 @@ static enum ops byteorder_conversion_op(struct expr *expr,
default:
break;
}
- BUG();
+ BUG("invalid byte order conversion %u => %u\n",
+ expr->byteorder, byteorder);
}
static int byteorder_conversion(struct eval_ctx *ctx, struct expr **expr,
@@ -239,7 +240,7 @@ static int expr_evaluate_value(struct eval_ctx *ctx, struct expr **expr)
}
break;
default:
- BUG();
+ BUG("invalid basetype %s\n", expr_basetype(*expr)->name);
}
return 0;
}
@@ -397,7 +398,7 @@ static int expr_evaluate_unary(struct eval_ctx *ctx, struct expr **expr)
byteorder = BYTEORDER_HOST_ENDIAN;
break;
default:
- BUG();
+ BUG("invalid unary operation %u\n", unary->op);
}
unary->dtype = arg->dtype;
@@ -447,7 +448,7 @@ static int constant_binop_simplify(struct eval_ctx *ctx, struct expr **expr)
mpz_rshift_ui(val, mpz_get_uint32(right->value));
break;
default:
- BUG();
+ BUG("invalid binary operation %u\n", op->op);
}
new = constant_expr_alloc(&op->location, op->dtype, op->byteorder,
@@ -563,7 +564,7 @@ static int expr_evaluate_binop(struct eval_ctx *ctx, struct expr **expr)
case OP_OR:
return expr_evaluate_bitwise(ctx, expr);
default:
- BUG();
+ BUG("invalid binary operation %u\n", op->op);
}
}
@@ -687,7 +688,8 @@ static int expr_evaluate_map(struct eval_ctx *ctx, struct expr **expr)
"Expression is not a map");
break;
default:
- BUG();
+ BUG("invalid mapping expression %s\n",
+ map->mappings->ops->name);
}
map->dtype = ctx->ectx.dtype;
@@ -766,7 +768,7 @@ static int binop_transfer_one(struct eval_ctx *ctx,
*right, expr_get(left->right));
break;
default:
- BUG();
+ BUG("invalid binary operation %u\n", left->op);
}
return expr_evaluate(ctx, right);
@@ -916,7 +918,7 @@ static int expr_evaluate_relational(struct eval_ctx *ctx, struct expr **expr)
return -1;
break;
default:
- BUG();
+ BUG("invalid expression type %s\n", right->ops->name);
}
break;
case OP_LT:
@@ -981,7 +983,7 @@ range:
return -1;
break;
default:
- BUG();
+ BUG("invalid relational operation %u\n", rel->op);
}
if (binop_transfer(ctx, expr) < 0)
@@ -1035,7 +1037,7 @@ static int expr_evaluate(struct eval_ctx *ctx, struct expr **expr)
case EXPR_RELATIONAL:
return expr_evaluate_relational(ctx, expr);
default:
- BUG();
+ BUG("unknown expression type %s\n", (*expr)->ops->name);
}
}
@@ -1059,7 +1061,7 @@ static int stmt_evaluate_verdict(struct eval_ctx *ctx, struct stmt *stmt)
case EXPR_MAP:
break;
default:
- BUG();
+ BUG("invalid verdict expression %s\n", stmt->expr->ops->name);
}
return 0;
}
@@ -1135,7 +1137,7 @@ static int stmt_evaluate(struct eval_ctx *ctx, struct stmt *stmt)
case STMT_NAT:
return stmt_evaluate_nat(ctx, stmt);
default:
- BUG();
+ BUG("unknown statement type %s\n", stmt->ops->name);
}
}
@@ -1259,7 +1261,7 @@ static int cmd_evaluate_add(struct eval_ctx *ctx, struct cmd *cmd)
return 0;
return table_evaluate(ctx, cmd->table);
default:
- BUG();
+ BUG("invalid command object type %u\n", cmd->obj);
}
}
@@ -1274,7 +1276,7 @@ static int cmd_evaluate_delete(struct eval_ctx *ctx, struct cmd *cmd)
case CMD_OBJ_TABLE:
return 0;
default:
- BUG();
+ BUG("invalid command object type %u\n", cmd->obj);
}
}
@@ -1298,7 +1300,7 @@ static int cmd_evaluate(struct eval_ctx *ctx, struct cmd *cmd)
case CMD_FLUSH:
return 0;
default:
- BUG();
+ BUG("invalid command operation %u\n", cmd->op);
};
}
diff --git a/src/netlink.c b/src/netlink.c
index 764d9fad..912dfd5b 100644
--- a/src/netlink.c
+++ b/src/netlink.c
@@ -246,7 +246,7 @@ struct nfnl_nft_data *netlink_gen_data(const struct expr *expr)
case EXPR_VERDICT:
return netlink_gen_verdict(expr);
default:
- BUG();
+ BUG("invalid data expression type %s\n", expr->ops->name);
}
}
diff --git a/src/netlink_delinearize.c b/src/netlink_delinearize.c
index 1963966c..4e267b87 100644
--- a/src/netlink_delinearize.c
+++ b/src/netlink_delinearize.c
@@ -250,7 +250,8 @@ static void netlink_parse_byteorder(struct netlink_parse_ctx *ctx,
op = OP_HTON;
break;
default:
- BUG();
+ BUG("invalid byteorder operation %u\n",
+ nfnl_nft_byteorder_get_op(nle));
}
expr = unary_expr_alloc(loc, op, arg);
@@ -639,8 +640,7 @@ static void expr_postprocess(struct rule_pp_ctx *ctx,
case EXPR_VERDICT:
break;
default:
- printf("%s\n", expr->ops->name);
- BUG();
+ BUG("unknown expression type %s\n", expr->ops->name);
}
}
diff --git a/src/netlink_linearize.c b/src/netlink_linearize.c
index 18315bdf..cfd66915 100644
--- a/src/netlink_linearize.c
+++ b/src/netlink_linearize.c
@@ -25,7 +25,7 @@ struct netlink_linearize_ctx {
static enum nft_registers get_register(struct netlink_linearize_ctx *ctx)
{
if (ctx->reg_low > NFT_REG_MAX)
- BUG();
+ BUG("register reg_low %u invalid\n", ctx->reg_low);
return ctx->reg_low++;
}
@@ -164,7 +164,7 @@ static enum nft_cmp_ops netlink_gen_cmp_op(enum ops op)
case OP_GTE:
return NFT_CMP_GTE;
default:
- BUG();
+ BUG("invalid comparison operation %u\n", op);
}
}
@@ -274,7 +274,7 @@ static void netlink_gen_relational(struct netlink_linearize_ctx *ctx,
case OP_LOOKUP:
return netlink_gen_lookup(ctx, expr, dreg);
default:
- BUG();
+ BUG("invalid relational operation %u\n", expr->op);
}
}
@@ -331,7 +331,7 @@ static void netlink_gen_binop(struct netlink_linearize_ctx *ctx,
combine_binop(mask, xor, tmp, val);
break;
default:
- BUG();
+ BUG("invalid binary operation %u\n", i->op);
}
}
@@ -364,7 +364,7 @@ static enum nft_byteorder_ops netlink_gen_unary_op(enum ops op)
case OP_NTOH:
return NFT_BYTEORDER_HTON;
default:
- BUG();
+ BUG("invalid unary operation %u\n", op);
}
}
@@ -424,7 +424,7 @@ static void netlink_gen_expr(struct netlink_linearize_ctx *ctx,
case EXPR_CT:
return netlink_gen_ct(ctx, expr, dreg);
default:
- BUG();
+ BUG("unknown expression type %s\n", expr->ops->name);
}
}
@@ -571,7 +571,7 @@ static void netlink_gen_stmt(struct netlink_linearize_ctx *ctx,
case STMT_NAT:
return netlink_gen_nat_stmt(ctx, stmt);
default:
- BUG();
+ BUG("unknown statement type %s\n", stmt->ops->name);
}
}
diff --git a/src/rule.c b/src/rule.c
index 3bf48aac..e90e6179 100644
--- a/src/rule.c
+++ b/src/rule.c
@@ -329,7 +329,7 @@ void cmd_free(struct cmd *cmd)
table_free(cmd->table);
break;
default:
- BUG();
+ BUG("invalid command object type %u\n", cmd->obj);
}
}
xfree(cmd);
@@ -411,7 +411,7 @@ static int do_command_add(struct netlink_ctx *ctx, struct cmd *cmd)
case CMD_OBJ_SETELEM:
return do_add_setelems(ctx, &cmd->handle, cmd->expr);
default:
- BUG();
+ BUG("invalid command object type %u\n", cmd->obj);
}
return 0;
}
@@ -430,7 +430,7 @@ static int do_command_delete(struct netlink_ctx *ctx, struct cmd *cmd)
case CMD_OBJ_SETELEM:
return netlink_delete_setelems(ctx, &cmd->handle, cmd->expr);
default:
- BUG();
+ BUG("invalid command object type %u\n", cmd->obj);
}
}
@@ -493,7 +493,7 @@ static int do_command_list(struct netlink_ctx *ctx, struct cmd *cmd)
}
return 0;
default:
- BUG();
+ BUG("invalid command object type %u\n", cmd->obj);
}
list_for_each_entry_safe(rule, nrule, &ctx->list, list) {
@@ -519,7 +519,7 @@ static int do_command_flush(struct netlink_ctx *ctx, struct cmd *cmd)
case CMD_OBJ_CHAIN:
return netlink_flush_chain(ctx, &cmd->handle);
default:
- BUG();
+ BUG("invalid command object type %u\n", cmd->obj);
}
return 0;
}
@@ -536,7 +536,7 @@ int do_command(struct netlink_ctx *ctx, struct cmd *cmd)
case CMD_FLUSH:
return do_command_flush(ctx, cmd);
default:
- BUG();
+ BUG("invalid command object type %u\n", cmd->obj);
}
}
diff --git a/src/segtree.c b/src/segtree.c
index fb404a43..216e4588 100644
--- a/src/segtree.c
+++ b/src/segtree.c
@@ -246,7 +246,7 @@ static void range_low(mpz_t rop, struct expr *expr)
case EXPR_MAPPING:
return range_low(rop, expr->left);
default:
- BUG();
+ BUG("invalid range expression type %s\n", expr->ops->name);
}
}
@@ -268,7 +268,7 @@ static void range_high(mpz_t rop, const struct expr *expr)
case EXPR_MAPPING:
return range_high(rop, expr->left);
default:
- BUG();
+ BUG("invalid range expression type %s\n", expr->ops->name);
}
}