From 0d906ed608ef633b66cc6903d0904f058576e448 Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Mon, 17 Jun 2013 13:39:28 +0300 Subject: [PATCH] debug: introduce __smatch_state(check_name, state_name) Except for smatch_extra states and smatch_compare then there wasn't a way to print just one state before. The way to use this is like: __smatch_state("check_user_data", "foo.x"); Signed-off-by: Dan Carpenter --- check_debug.c | 31 +++++++++++++++++++++++++++++++ check_debug.h | 1 + 2 files changed, 32 insertions(+) diff --git a/check_debug.c b/check_debug.c index 588ce381..d42743c1 100644 --- a/check_debug.c +++ b/check_debug.c @@ -28,6 +28,36 @@ static void match_cur_slist(const char *fn, struct expression *expr, void *info) __print_cur_slist(); } +static void match_state(const char *fn, struct expression *expr, void *info) +{ + struct expression *check_arg, *state_arg; + struct sm_state *sm; + int found = 0; + + check_arg = get_argument_from_call_expr(expr->args, 0); + if (check_arg->type != EXPR_STRING) { + sm_msg("error: the check_name argument to %s is supposed to be a string literal", fn); + return; + } + state_arg = get_argument_from_call_expr(expr->args, 1); + if (state_arg->type != EXPR_STRING) { + sm_msg("error: the state_name argument to %s is supposed to be a string literal", fn); + return; + } + + FOR_EACH_PTR(__get_cur_slist(), sm) { + if (strcmp(check_name(sm->owner), check_arg->string->data) != 0) + continue; + if (strcmp(sm->name, state_arg->string->data) != 0) + continue; + sm_msg("'%s' = '%s'", sm->name, sm->state->name); + found = 1; + } END_FOR_EACH_PTR(sm); + + if (!found) + sm_msg("%s '%s' not found", check_arg->string->data, state_arg->string->data); +} + static void match_print_value(const char *fn, struct expression *expr, void *info) { struct state_list *slist; @@ -324,6 +354,7 @@ void check_debug(int id) { my_id = id; add_function_hook("__smatch_all_values", &match_all_values, NULL); + add_function_hook("__smatch_state", &match_state, NULL); add_function_hook("__smatch_value", &match_print_value, NULL); add_function_hook("__smatch_implied", &match_print_implied, NULL); add_function_hook("__smatch_implied_min", &match_print_implied_min, NULL); diff --git a/check_debug.h b/check_debug.h index 6a5ee9b9..dd4f59ed 100644 --- a/check_debug.h +++ b/check_debug.h @@ -3,6 +3,7 @@ static inline void __smatch_cur_slist(void){} static inline void __smatch_all_values(void){} +static inline void __smatch_state(const char *check_name, const char *state_name){} static inline void __smatch_value(const char *unused){} static inline void __smatch_implied(long long val){} static inline void __smatch_implied_min(long long val){} -- 2.11.4.GIT