validation: remove out of date sm_locking5.c
[smatch.git] / check_debug.c
blob99d62ce75e13bb745a323004c4e39a6e6085ca42
1 /*
2 * sparse/check_debug.c
4 * Copyright (C) 2009 Dan Carpenter.
6 * Licensed under the Open Software License version 1.1
8 */
10 #include "smatch.h"
11 #include "smatch_slist.h" // blast this was supposed to be internal only stuff
13 static int my_id;
15 static void match_all_values(const char *fn, struct expression *expr, void *info)
17 struct state_list *slist;
19 slist = get_all_states(SMATCH_EXTRA);
20 __print_slist(slist);
21 free_slist(&slist);
24 static void match_cur_slist(const char *fn, struct expression *expr, void *info)
26 __print_cur_slist();
29 static void match_print_value(const char *fn, struct expression *expr, void *info)
31 struct state_list *slist;
32 struct sm_state *tmp;
33 struct expression *arg_expr;
35 arg_expr = get_argument_from_call_expr(expr->args, 0);
36 if (arg_expr->type != EXPR_STRING) {
37 sm_msg("error: the argument to %s is supposed to be a string literal", fn);
38 return;
41 slist = get_all_states(SMATCH_EXTRA);
42 FOR_EACH_PTR(slist, tmp) {
43 if (!strcmp(tmp->name, arg_expr->string->data))
44 sm_msg("%s = %s", tmp->name, tmp->state->name);
45 } END_FOR_EACH_PTR(tmp);
46 free_slist(&slist);
49 static void match_print_implied_min(const char *fn, struct expression *expr, void *info)
51 struct expression *arg;
52 long long val;
53 char *name;
55 arg = get_argument_from_call_expr(expr->args, 0);
56 if (!get_implied_min(arg, &val))
57 val = whole_range.min;
59 name = get_variable_from_expr_complex(arg, NULL);
60 sm_msg("implied min: %s = %lld", name, val);
61 free_string(name);
64 static void match_print_implied_max(const char *fn, struct expression *expr, void *info)
66 struct expression *arg;
67 long long val;
68 char *name;
70 arg = get_argument_from_call_expr(expr->args, 0);
71 if (!get_implied_max(arg, &val))
72 val = whole_range.max;
74 name = get_variable_from_expr_complex(arg, NULL);
75 sm_msg("implied max: %s = %lld", name, val);
76 free_string(name);
79 static void print_possible(struct sm_state *sm)
81 struct sm_state *tmp;
83 sm_msg("Possible values for %s", sm->name);
84 FOR_EACH_PTR(sm->possible, tmp) {
85 printf("%s\n", tmp->state->name);
86 } END_FOR_EACH_PTR(tmp);
87 sm_msg("===");
90 static void match_possible(const char *fn, struct expression *expr, void *info)
92 struct state_list *slist;
93 struct sm_state *tmp;
94 struct expression *arg_expr;
96 arg_expr = get_argument_from_call_expr(expr->args, 0);
97 if (arg_expr->type != EXPR_STRING) {
98 sm_msg("error: the argument to %s is supposed to be a string literal", fn);
99 return;
102 slist = get_all_states(SMATCH_EXTRA);
103 FOR_EACH_PTR(slist, tmp) {
104 if (!strcmp(tmp->name, arg_expr->string->data))
105 print_possible(tmp);
106 } END_FOR_EACH_PTR(tmp);
107 free_slist(&slist);
110 static void match_note(const char *fn, struct expression *expr, void *info)
112 struct expression *arg_expr;
114 arg_expr = get_argument_from_call_expr(expr->args, 0);
115 if (arg_expr->type != EXPR_STRING) {
116 sm_msg("error: the argument to %s is supposed to be a string literal", fn);
117 return;
119 sm_msg("%s", arg_expr->string->data);
122 static void match_debug_on(const char *fn, struct expression *expr, void *info)
124 option_debug = 1;
127 static void match_debug_off(const char *fn, struct expression *expr, void *info)
129 option_debug = 0;
131 void check_debug(int id)
133 my_id = id;
134 add_function_hook("__smatch_all_values", &match_all_values, NULL);
135 add_function_hook("__smatch_value", &match_print_value, NULL);
136 add_function_hook("__smatch_implied_min", &match_print_implied_min, NULL);
137 add_function_hook("__smatch_implied_max", &match_print_implied_max, NULL);
138 add_function_hook("__smatch_possible", &match_possible, NULL);
139 add_function_hook("__smatch_cur_slist", &match_cur_slist, NULL);
140 add_function_hook("__smatch_note", &match_note, NULL);
141 add_function_hook("__smatch_debug_on", &match_debug_on, NULL);
142 add_function_hook("__smatch_debug_off", &match_debug_off, NULL);