dfilter: Add more debug code

This commit is contained in:
João Valverde 2022-02-27 14:11:50 +00:00
parent 70301ba54c
commit 1278e36152
4 changed files with 74 additions and 5 deletions

View File

@ -428,6 +428,8 @@ is_bytes_type(enum ftenum type)
static void
check_exists(dfwork_t *dfw, stnode_t *st_arg1)
{
LOG_NODE(st_arg1);
switch (stnode_type_id(st_arg1)) {
case STTYPE_FIELD:
/* This is OK */
@ -467,6 +469,8 @@ check_drange_sanity(dfwork_t *dfw, stnode_t *st)
header_field_info *hfinfo1;
ftenum_t ftype1;
LOG_NODE(st);
entity1 = sttype_range_entity(st);
ws_assert(entity1);
@ -520,6 +524,8 @@ check_function(dfwork_t *dfw, stnode_t *st_node)
guint iparam;
guint nparams;
LOG_NODE(st_node);
funcdef = sttype_function_funcdef(st_node);
params = sttype_function_params(st_node);
nparams = g_slist_length(params);
@ -569,6 +575,8 @@ check_relation_LHS_FIELD(dfwork_t *dfw, test_op_t st_op,
ftenum_t ftype1, ftype2;
fvalue_t *fvalue;
LOG_NODE(st_node);
type2 = stnode_type_id(st_arg2);
hfinfo1 = stnode_data(st_arg1);
@ -666,6 +674,8 @@ check_relation_LHS_STRING(dfwork_t *dfw, test_op_t st_op _U_,
ftenum_t ftype2;
fvalue_t *fvalue;
LOG_NODE(st_node);
type2 = stnode_type_id(st_arg2);
if (type2 == STTYPE_FIELD) {
@ -725,6 +735,8 @@ check_relation_LHS_UNPARSED(dfwork_t *dfw, test_op_t st_op _U_,
ftenum_t ftype2;
fvalue_t *fvalue;
LOG_NODE(st_node);
type2 = stnode_type_id(st_arg2);
if (type2 == STTYPE_FIELD) {
@ -783,6 +795,8 @@ check_relation_LHS_CHARCONST(dfwork_t *dfw, test_op_t st_op _U_,
ftenum_t ftype2;
fvalue_t *fvalue;
LOG_NODE(st_node);
type2 = stnode_type_id(st_arg2);
if (type2 == STTYPE_FIELD) {
@ -841,6 +855,8 @@ check_relation_LHS_RANGE(dfwork_t *dfw, test_op_t st_op,
ftenum_t ftype2;
fvalue_t *fvalue;
LOG_NODE(st_node);
check_drange_sanity(dfw, st_arg1);
type2 = stnode_type_id(st_arg2);
@ -916,6 +932,8 @@ check_relation_LHS_FUNCTION(dfwork_t *dfw, test_op_t st_op,
df_func_def_t *funcdef2;
/* GSList *params; */
LOG_NODE(st_node);
check_function(dfw, st_arg1);
type2 = stnode_type_id(st_arg2);
@ -1001,6 +1019,8 @@ check_relation(dfwork_t *dfw, test_op_t st_op,
FtypeCanFunc can_func, gboolean allow_partial_value,
stnode_t *st_node, stnode_t *st_arg1, stnode_t *st_arg2)
{
LOG_NODE(st_node);
switch (stnode_type_id(st_arg1)) {
case STTYPE_FIELD:
check_relation_LHS_FIELD(dfw, st_op, can_func,
@ -1036,6 +1056,8 @@ static void
check_relation_contains(dfwork_t *dfw, stnode_t *st_node,
stnode_t *st_arg1, stnode_t *st_arg2)
{
LOG_NODE(st_node);
/* Protocol can only be on LHS for "contains".
* Check to see if protocol is on RHS, and re-interpret it as UNPARSED
* instead. The subsequent functions will parse it according to the
@ -1096,6 +1118,8 @@ check_relation_matches(dfwork_t *dfw, stnode_t *st_node,
char *errmsg = NULL;
const char *patt;
LOG_NODE(st_node);
if (stnode_type_id(st_arg2) != STTYPE_STRING) {
FAIL(dfw, "Matches requires a double quoted string on the right side.");
}
@ -1142,6 +1166,8 @@ check_relation_in(dfwork_t *dfw, stnode_t *st_node _U_,
GSList *nodelist;
stnode_t *node_left, *node_right;
LOG_NODE(st_node);
if (stnode_type_id(st_arg1) != STTYPE_FIELD) {
FAIL(dfw, "Only a field may be tested for membership in a set.");
}
@ -1185,7 +1211,7 @@ check_test(dfwork_t *dfw, stnode_t *st_node)
test_op_t st_op, st_arg_op;
stnode_t *st_arg1, *st_arg2;
log_test(st_node);
LOG_NODE(st_node);
sttype_test_get(st_node, &st_op, &st_arg1, &st_arg2);
@ -1259,6 +1285,8 @@ check_test(dfwork_t *dfw, stnode_t *st_node)
static void
semcheck(dfwork_t *dfw, stnode_t *st_node)
{
LOG_NODE(st_node);
/* The parser assures that the top-most syntax-tree
* node will be a TEST node, no matter what. So assert that. */
switch (stnode_type_id(st_node)) {

View File

@ -334,8 +334,8 @@ sprint_node(stnode_t *node)
}
void
log_test_full(enum ws_log_level level,
const char *file _U_, int line _U_, const char *func,
log_node_full(enum ws_log_level level,
const char *file, int line, const char *func,
stnode_t *node, const char *msg)
{
if (!ws_log_msg_is_active(WS_LOG_DOMAIN, level))
@ -343,7 +343,29 @@ log_test_full(enum ws_log_level level,
if (node == NULL) {
ws_log_write_always_full(WS_LOG_DOMAIN, level,
NULL, -1, func, "%s is NULL", msg);
file, line, func, "%s is NULL", msg);
return;
}
char *str = sprint_node(node);
ws_log_write_always_full(WS_LOG_DOMAIN, level, file, line, func,
"%s = %s", msg, str);
g_free(str);
}
void
log_test_full(enum ws_log_level level,
const char *file, int line, const char *func,
stnode_t *node, const char *msg)
{
if (!ws_log_msg_is_active(WS_LOG_DOMAIN, level))
return;
if (node == NULL) {
ws_log_write_always_full(WS_LOG_DOMAIN, level,
file, line, func, "%s is NULL", msg);
return;
}
@ -358,7 +380,7 @@ log_test_full(enum ws_log_level level,
if (st_rhs)
rhs = sprint_node(st_rhs);
ws_log_write_always_full(WS_LOG_DOMAIN, level, NULL, -1, func,
ws_log_write_always_full(WS_LOG_DOMAIN, level, file, line, func,
"%s: LHS = %s; RHS = %s",
stnode_todebug(node),
lhs ? lhs : "NULL",

View File

@ -156,16 +156,32 @@ stnode_inside_parens(stnode_t *node);
void
stnode_set_inside_parens(stnode_t *node, gboolean inside);
void
log_node_full(enum ws_log_level level,
const char *file, int line, const char *func,
stnode_t *node, const char *msg);
void
log_test_full(enum ws_log_level level,
const char *file, int line, const char *func,
stnode_t *node, const char *msg);
#ifdef WS_DISABLE_DEBUG
#define log_node(node) (void)0;
#define log_test(node) (void)0;
#define LOG_NODE(node) (void)0;
#else
#define log_node(node) \
log_node_full(LOG_LEVEL_NOISY, __FILE__, __LINE__, __func__, node, #node)
#define log_test(node) \
log_test_full(LOG_LEVEL_NOISY, __FILE__, __LINE__, __func__, node, #node)
#define LOG_NODE(node) \
do { \
if (stnode_type_id(node) == STTYPE_TEST) \
log_test(node); \
else \
log_node(node); \
} while (0)
#endif
void

View File

@ -266,6 +266,9 @@ fvalue_from_charconst(ftenum_t ftype, unsigned long number, gchar **err_msg);
WS_DLL_PUBLIC char *
fvalue_to_string_repr(wmem_allocator_t *scope, const fvalue_t *fv, ftrepr_t rtype, int field_display);
#define fvalue_to_debug_repr(scope, fv) \
fvalue_to_string_repr(NULL, fv, FTREPR_DFILTER, 0)
WS_DLL_PUBLIC ftenum_t
fvalue_type_ftenum(fvalue_t *fv);