From 05761776165109a8bd8e471edb96fa01b1020413 Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Thu, 4 Jul 2013 13:27:21 +0300 Subject: [PATCH] smatch: add --debug=check_name option to debug only the check When you have --debug the output is overwhelming, so it's helpful to just debug one check at a time. You have to use the name from check_list.h so for most things it is --debug=check_myname but it could also be --debug=register_comparison. Signed-off-by: Dan Carpenter --- smatch.c | 6 ++++++ smatch.h | 1 + smatch_slist.c | 3 ++- smatch_states.c | 13 +++++++------ 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/smatch.c b/smatch.c index fe1114cb..3f566dac 100644 --- a/smatch.c +++ b/smatch.c @@ -14,6 +14,7 @@ #include "smatch.h" #include "check_list.h" +char *option_debug_check = (char *)""; char *option_project_str = (char *)""; enum project_type option_project = PROJ_NONE; char *data_dir; @@ -131,6 +132,11 @@ void parse_args(int *argcp, char ***argvp) (*argvp)[1] = (*argvp)[0]; found = 1; } + if (!found && !strncmp((*argvp)[1], "--debug=", 8)) { + option_debug_check = (*argvp)[1] + 8; + (*argvp)[1] = (*argvp)[0]; + found = 1; + } OPTION(spammy); OPTION(info); diff --git a/smatch.h b/smatch.h index 2d5c7e22..02c460e7 100644 --- a/smatch.h +++ b/smatch.h @@ -585,6 +585,7 @@ int open_data_file(const char *filename); struct token *get_tokens_file(const char *filename); /* smatch.c */ +extern char *option_debug_check; extern char *option_project_str; extern char *data_dir; extern int option_no_data; diff --git a/smatch_slist.c b/smatch_slist.c index 7598be4b..08175b08 100644 --- a/smatch_slist.c +++ b/smatch_slist.c @@ -365,7 +365,8 @@ struct sm_state *merge_sm_states(struct sm_state *one, struct sm_state *two) copy_possibles(result, one); copy_possibles(result, two); - if (option_debug) { + if (option_debug || + strcmp(check_name(one->owner), option_debug_check) == 0) { struct sm_state *tmp; int i = 0; diff --git a/smatch_states.c b/smatch_states.c index 899298ae..824542aa 100644 --- a/smatch_states.c +++ b/smatch_states.c @@ -108,7 +108,7 @@ struct sm_state *set_state(int owner, const char *name, struct symbol *sym, stru if (read_only) sm_msg("Smatch Internal Error: cur_slist is read only."); - if (option_debug) { + if (option_debug || strcmp(check_name(owner), option_debug_check) == 0) { struct smatch_state *s; s = get_state(owner, name, sym); @@ -207,7 +207,8 @@ void __set_sm(struct sm_state *sm) if (read_only) sm_msg("Smatch Internal Error: cur_slist is read only."); - if (option_debug) { + if (option_debug || + strcmp(check_name(sm->owner), option_debug_check) == 0) { struct smatch_state *s; s = get_state(sm->owner, sm->name, sm->sym); @@ -369,13 +370,13 @@ void set_true_false_states(int owner, const char *name, struct symbol *sym, struct smatch_state *true_state, struct smatch_state *false_state) { - if (option_debug) { + if (option_debug || strcmp(check_name(owner), option_debug_check) == 0) { struct smatch_state *tmp; tmp = get_state(owner, name, sym); - sm_debug("%d set_true_false '%s'. Was %s. Now T:%s F:%s\n", - get_lineno(), name, show_state(tmp), - show_state(true_state), show_state(false_state)); + printf("%d set_true_false '%s'. Was %s. Now T:%s F:%s\n", + get_lineno(), name, show_state(tmp), + show_state(true_state), show_state(false_state)); } if (unreachable()) -- 2.11.4.GIT