smatch: add --debug=check_name option to debug only the check
authorDan Carpenter <dan.carpenter@oracle.com>
Thu, 4 Jul 2013 10:27:21 +0000 (4 13:27 +0300)
committerDan Carpenter <dan.carpenter@oracle.com>
Thu, 4 Jul 2013 10:27:21 +0000 (4 13:27 +0300)
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 <dan.carpenter@oracle.com>
smatch.c
smatch.h
smatch_slist.c
smatch_states.c

index fe1114c..3f566da 100644 (file)
--- 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);
index 2d5c7e2..02c460e 100644 (file)
--- 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;
index 7598be4..08175b0 100644 (file)
@@ -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;
 
index 899298a..824542a 100644 (file)
@@ -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())