db: remove untrusted table
[smatch.git] / check_debug.c
blob3ed3a19a662cca453048849541d18167eeb88e52
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 print_possible(struct sm_state *sm)
51 struct sm_state *tmp;
53 sm_msg("Possible values for %s", sm->name);
54 FOR_EACH_PTR(sm->possible, tmp) {
55 printf("%s\n", tmp->state->name);
56 } END_FOR_EACH_PTR(tmp);
57 sm_msg("===");
60 static void match_possible(const char *fn, struct expression *expr, void *info)
62 struct state_list *slist;
63 struct sm_state *tmp;
64 struct expression *arg_expr;
66 arg_expr = get_argument_from_call_expr(expr->args, 0);
67 if (arg_expr->type != EXPR_STRING) {
68 sm_msg("error: the argument to %s is supposed to be a string literal", fn);
69 return;
72 slist = get_all_states(SMATCH_EXTRA);
73 FOR_EACH_PTR(slist, tmp) {
74 if (!strcmp(tmp->name, arg_expr->string->data))
75 print_possible(tmp);
76 } END_FOR_EACH_PTR(tmp);
77 free_slist(&slist);
80 static void match_note(const char *fn, struct expression *expr, void *info)
82 struct expression *arg_expr;
84 arg_expr = get_argument_from_call_expr(expr->args, 0);
85 if (arg_expr->type != EXPR_STRING) {
86 sm_msg("error: the argument to %s is supposed to be a string literal", fn);
87 return;
89 sm_msg("%s", arg_expr->string->data);
92 static void match_debug_on(const char *fn, struct expression *expr, void *info)
94 option_debug = 1;
97 static void match_debug_off(const char *fn, struct expression *expr, void *info)
99 option_debug = 0;
101 void check_debug(int id)
103 my_id = id;
104 add_function_hook("__smatch_all_values", &match_all_values, NULL);
105 add_function_hook("__smatch_value", &match_print_value, NULL);
106 add_function_hook("__smatch_possible", &match_possible, NULL);
107 add_function_hook("__smatch_cur_slist", &match_cur_slist, NULL);
108 add_function_hook("__smatch_note", &match_note, NULL);
109 add_function_hook("__smatch_debug_on", &match_debug_on, NULL);
110 add_function_hook("__smatch_debug_off", &match_debug_off, NULL);