*new* check_macros: find macro precedence bugs
[smatch.git] / check_debug.c
blobd717688611e869c4f8bfa17cf447a4eef7ad39fd
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_note(const char *fn, struct expression *expr, void *info)
51 struct expression *arg_expr;
53 arg_expr = get_argument_from_call_expr(expr->args, 0);
54 if (arg_expr->type != EXPR_STRING) {
55 sm_msg("error: the argument to %s is supposed to be a string literal", fn);
56 return;
58 sm_msg("%s", arg_expr->string->data);
61 static void match_debug_on(const char *fn, struct expression *expr, void *info)
63 option_debug = 1;
66 static void match_debug_off(const char *fn, struct expression *expr, void *info)
68 option_debug = 0;
70 void check_debug(int id)
72 my_id = id;
73 add_function_hook("__smatch_all_values", &match_all_values, NULL);
74 add_function_hook("__smatch_value", &match_print_value, NULL);
75 add_function_hook("__smatch_cur_slist", &match_cur_slist, NULL);
76 add_function_hook("__smatch_note", &match_note, NULL);
77 add_function_hook("__smatch_debug_on", &match_debug_on, NULL);
78 add_function_hook("__smatch_debug_off", &match_debug_off, NULL);