debug: add __smatch_states("register_comparison")
authorDan Carpenter <dan.carpenter@oracle.com>
Sat, 29 Jun 2013 09:21:06 +0000 (29 12:21 +0300)
committerDan Carpenter <dan.carpenter@oracle.com>
Sat, 29 Jun 2013 09:21:06 +0000 (29 12:21 +0300)
It prints out all the states for a specified check.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
check_debug.c
check_debug.h

index 68194ad..67edb70 100644 (file)
@@ -58,6 +58,29 @@ static void match_state(const char *fn, struct expression *expr, void *info)
                sm_msg("%s '%s' not found", check_arg->string->data, state_arg->string->data);
 }
 
+static void match_states(const char *fn, struct expression *expr, void *info)
+{
+       struct expression *check_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;
+       }
+
+       FOR_EACH_PTR(__get_cur_slist(), sm) {
+               if (strcmp(check_name(sm->owner), check_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: no states", check_arg->string->data);
+}
+
 static void match_print_value(const char *fn, struct expression *expr, void *info)
 {
        struct state_list *slist;
@@ -355,6 +378,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_states", &match_states, 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);
index dd4f59e..998699a 100644 (file)
@@ -4,6 +4,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_states(const char *check_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){}