Print this page
12166 resync smatch to 0.6.1-rc1-il-3
   1 /*
   2  * Copyright (C) 2009 Dan Carpenter.
   3  *
   4  * This program is free software; you can redistribute it and/or
   5  * modify it under the terms of the GNU General Public License
   6  * as published by the Free Software Foundation; either version 2
   7  * of the License, or (at your option) any later version.
   8  *
   9  * This program is distributed in the hope that it will be useful,
  10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  * GNU General Public License for more details.
  13  *
  14  * You should have received a copy of the GNU General Public License
  15  * along with this program; if not, see http://www.gnu.org/copyleft/gpl.txt
  16  */
  17 


  18 #include "smatch.h"
  19 #include "smatch_slist.h"
  20 #include "smatch_extra.h"
  21 
  22 void show_sname_alloc(void);
  23 void show_data_range_alloc(void);
  24 void show_ptrlist_alloc(void);
  25 void show_rl_ptrlist_alloc(void);
  26 void show_sm_state_alloc(void);
  27 
  28 int local_debug;
  29 static int my_id;
  30 char *trace_variable;
  31 
  32 static void match_all_values(const char *fn, struct expression *expr, void *info)
  33 {
  34         struct stree *stree;
  35 
  36         stree = get_all_states_stree(SMATCH_EXTRA);
  37         __print_stree(stree);


  69                 found = 1;
  70         } END_FOR_EACH_SM(sm);
  71 
  72         if (!found)
  73                 sm_msg("%s '%s' not found", check_arg->string->data, state_arg->string->data);
  74 }
  75 
  76 static void match_states(const char *fn, struct expression *expr, void *info)
  77 {
  78         struct expression *check_arg;
  79         struct sm_state *sm;
  80         int found = 0;
  81 
  82         check_arg = get_argument_from_call_expr(expr->args, 0);
  83         if (check_arg->type != EXPR_STRING) {
  84                 sm_error("the check_name argument to %s is supposed to be a string literal", fn);
  85                 return;
  86         }
  87 
  88         FOR_EACH_SM(__get_cur_stree(), sm) {
  89                 if (strcmp(check_name(sm->owner), check_arg->string->data) != 0)
  90                         continue;
  91                 sm_msg("%s", show_sm(sm));
  92                 found = 1;
  93         } END_FOR_EACH_SM(sm);
  94 
  95         if (found)
  96                 return;
  97 
  98         if (!id_from_name(check_arg->string->data))
  99                 sm_msg("invalid check name '%s'", check_arg->string->data);
 100         else
 101                 sm_msg("%s: no states", check_arg->string->data);
 102 }
 103 
 104 static void match_print_value(const char *fn, struct expression *expr, void *info)
 105 {
 106         struct stree *stree;
 107         struct sm_state *tmp;
 108         struct expression *arg_expr;
 109 


 497         option_debug_check = arg->string->data;
 498         sm_msg("arg = '%s'", option_debug_check);
 499 }
 500 
 501 static void match_debug_off(const char *fn, struct expression *expr, void *info)
 502 {
 503         option_debug_check = (char *)"";
 504         option_debug = 0;
 505 }
 506 
 507 static void match_local_debug_on(const char *fn, struct expression *expr, void *info)
 508 {
 509         local_debug = 1;
 510 }
 511 
 512 static void match_local_debug_off(const char *fn, struct expression *expr, void *info)
 513 {
 514         local_debug = 0;
 515 }
 516 










 517 static void match_about(const char *fn, struct expression *expr, void *info)
 518 {
 519         struct expression *arg;
 520         struct sm_state *sm;
 521         char *name;
 522 
 523         sm_msg("---- about ----");
 524         match_print_implied(fn, expr, NULL);
 525         match_buf_size(fn, expr, NULL);
 526         match_strlen(fn, expr, NULL);
 527         match_real_absolute(fn, expr, NULL);
 528 
 529         arg = get_argument_from_call_expr(expr->args, 0);
 530         name = expr_to_str(arg);
 531         if (!name) {
 532                 sm_msg("info: not a straight forward variable.");
 533                 return;
 534         }
 535 
 536         FOR_EACH_SM(__get_cur_stree(), sm) {


 756         add_function_hook("__smatch_hard_max", &match_print_hard_max, NULL);
 757         add_function_hook("__smatch_fuzzy_max", &match_print_fuzzy_max, NULL);
 758         add_function_hook("__smatch_absolute", &match_print_absolute, NULL);
 759         add_function_hook("__smatch_absolute_min", &match_print_absolute_min, NULL);
 760         add_function_hook("__smatch_absolute_max", &match_print_absolute_max, NULL);
 761         add_function_hook("__smatch_real_absolute", &match_real_absolute, NULL);
 762         add_function_hook("__smatch_sval_info", &match_sval_info, NULL);
 763         add_function_hook("__smatch_member_name", &match_member_name, NULL);
 764         add_function_hook("__smatch_possible", &match_possible, NULL);
 765         add_function_hook("__smatch_cur_stree", &match_cur_stree, NULL);
 766         add_function_hook("__smatch_strlen", &match_strlen, NULL);
 767         add_function_hook("__smatch_buf_size", &match_buf_size, NULL);
 768         add_function_hook("__smatch_note", &match_note, NULL);
 769         add_function_hook("__smatch_dump_related", &match_dump_related, NULL);
 770         add_function_hook("__smatch_compare", &match_compare, NULL);
 771         add_function_hook("__smatch_debug_on", &match_debug_on, NULL);
 772         add_function_hook("__smatch_debug_check", &match_debug_check, NULL);
 773         add_function_hook("__smatch_debug_off", &match_debug_off, NULL);
 774         add_function_hook("__smatch_local_debug_on", &match_local_debug_on, NULL);
 775         add_function_hook("__smatch_local_debug_off", &match_local_debug_off, NULL);


 776         add_function_hook("__smatch_intersection", &match_intersection, NULL);
 777         add_function_hook("__smatch_type", &match_type, NULL);
 778         add_implied_return_hook("__smatch_type_rl_helper", &match_type_rl_return, NULL);
 779         add_function_hook("__smatch_merge_tree", &match_print_merge_tree, NULL);
 780         add_function_hook("__smatch_stree_id", &match_print_stree_id, NULL);
 781         add_function_hook("__smatch_mtag", &match_mtag, NULL);
 782         add_function_hook("__smatch_mtag_data", &match_mtag_data_offset, NULL);
 783         add_function_hook("__smatch_state_count", &match_state_count, NULL);
 784         add_function_hook("__smatch_mem", &match_mem, NULL);
 785         add_function_hook("__smatch_exit", &match_exit, NULL);
 786         add_function_hook("__smatch_container", &match_container, NULL);
 787 
 788         add_hook(free_old_stree, AFTER_FUNC_HOOK);
 789         add_hook(trace_var, STMT_HOOK_AFTER);
 790 }
   1 /*
   2  * Copyright (C) 2009 Dan Carpenter.
   3  *
   4  * This program is free software; you can redistribute it and/or
   5  * modify it under the terms of the GNU General Public License
   6  * as published by the Free Software Foundation; either version 2
   7  * of the License, or (at your option) any later version.
   8  *
   9  * This program is distributed in the hope that it will be useful,
  10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  * GNU General Public License for more details.
  13  *
  14  * You should have received a copy of the GNU General Public License
  15  * along with this program; if not, see http://www.gnu.org/copyleft/gpl.txt
  16  */
  17 
  18 #include <string.h>
  19 
  20 #include "smatch.h"
  21 #include "smatch_slist.h"
  22 #include "smatch_extra.h"
  23 
  24 void show_sname_alloc(void);
  25 void show_data_range_alloc(void);
  26 void show_ptrlist_alloc(void);
  27 void show_rl_ptrlist_alloc(void);
  28 void show_sm_state_alloc(void);
  29 
  30 int local_debug;
  31 static int my_id;
  32 char *trace_variable;
  33 
  34 static void match_all_values(const char *fn, struct expression *expr, void *info)
  35 {
  36         struct stree *stree;
  37 
  38         stree = get_all_states_stree(SMATCH_EXTRA);
  39         __print_stree(stree);


  71                 found = 1;
  72         } END_FOR_EACH_SM(sm);
  73 
  74         if (!found)
  75                 sm_msg("%s '%s' not found", check_arg->string->data, state_arg->string->data);
  76 }
  77 
  78 static void match_states(const char *fn, struct expression *expr, void *info)
  79 {
  80         struct expression *check_arg;
  81         struct sm_state *sm;
  82         int found = 0;
  83 
  84         check_arg = get_argument_from_call_expr(expr->args, 0);
  85         if (check_arg->type != EXPR_STRING) {
  86                 sm_error("the check_name argument to %s is supposed to be a string literal", fn);
  87                 return;
  88         }
  89 
  90         FOR_EACH_SM(__get_cur_stree(), sm) {
  91                 if (!strstr(check_name(sm->owner), check_arg->string->data))
  92                         continue;
  93                 sm_msg("%s", show_sm(sm));
  94                 found = 1;
  95         } END_FOR_EACH_SM(sm);
  96 
  97         if (found)
  98                 return;
  99 
 100         if (!id_from_name(check_arg->string->data))
 101                 sm_msg("invalid check name '%s'", check_arg->string->data);
 102         else
 103                 sm_msg("%s: no states", check_arg->string->data);
 104 }
 105 
 106 static void match_print_value(const char *fn, struct expression *expr, void *info)
 107 {
 108         struct stree *stree;
 109         struct sm_state *tmp;
 110         struct expression *arg_expr;
 111 


 499         option_debug_check = arg->string->data;
 500         sm_msg("arg = '%s'", option_debug_check);
 501 }
 502 
 503 static void match_debug_off(const char *fn, struct expression *expr, void *info)
 504 {
 505         option_debug_check = (char *)"";
 506         option_debug = 0;
 507 }
 508 
 509 static void match_local_debug_on(const char *fn, struct expression *expr, void *info)
 510 {
 511         local_debug = 1;
 512 }
 513 
 514 static void match_local_debug_off(const char *fn, struct expression *expr, void *info)
 515 {
 516         local_debug = 0;
 517 }
 518 
 519 static void match_debug_db_on(const char *fn, struct expression *expr, void *info)
 520 {
 521         debug_db = 1;
 522 }
 523 
 524 static void match_debug_db_off(const char *fn, struct expression *expr, void *info)
 525 {
 526         debug_db = 0;
 527 }
 528 
 529 static void match_about(const char *fn, struct expression *expr, void *info)
 530 {
 531         struct expression *arg;
 532         struct sm_state *sm;
 533         char *name;
 534 
 535         sm_msg("---- about ----");
 536         match_print_implied(fn, expr, NULL);
 537         match_buf_size(fn, expr, NULL);
 538         match_strlen(fn, expr, NULL);
 539         match_real_absolute(fn, expr, NULL);
 540 
 541         arg = get_argument_from_call_expr(expr->args, 0);
 542         name = expr_to_str(arg);
 543         if (!name) {
 544                 sm_msg("info: not a straight forward variable.");
 545                 return;
 546         }
 547 
 548         FOR_EACH_SM(__get_cur_stree(), sm) {


 768         add_function_hook("__smatch_hard_max", &match_print_hard_max, NULL);
 769         add_function_hook("__smatch_fuzzy_max", &match_print_fuzzy_max, NULL);
 770         add_function_hook("__smatch_absolute", &match_print_absolute, NULL);
 771         add_function_hook("__smatch_absolute_min", &match_print_absolute_min, NULL);
 772         add_function_hook("__smatch_absolute_max", &match_print_absolute_max, NULL);
 773         add_function_hook("__smatch_real_absolute", &match_real_absolute, NULL);
 774         add_function_hook("__smatch_sval_info", &match_sval_info, NULL);
 775         add_function_hook("__smatch_member_name", &match_member_name, NULL);
 776         add_function_hook("__smatch_possible", &match_possible, NULL);
 777         add_function_hook("__smatch_cur_stree", &match_cur_stree, NULL);
 778         add_function_hook("__smatch_strlen", &match_strlen, NULL);
 779         add_function_hook("__smatch_buf_size", &match_buf_size, NULL);
 780         add_function_hook("__smatch_note", &match_note, NULL);
 781         add_function_hook("__smatch_dump_related", &match_dump_related, NULL);
 782         add_function_hook("__smatch_compare", &match_compare, NULL);
 783         add_function_hook("__smatch_debug_on", &match_debug_on, NULL);
 784         add_function_hook("__smatch_debug_check", &match_debug_check, NULL);
 785         add_function_hook("__smatch_debug_off", &match_debug_off, NULL);
 786         add_function_hook("__smatch_local_debug_on", &match_local_debug_on, NULL);
 787         add_function_hook("__smatch_local_debug_off", &match_local_debug_off, NULL);
 788         add_function_hook("__smatch_debug_db_on", &match_debug_db_on, NULL);
 789         add_function_hook("__smatch_debug_db_off", &match_debug_db_off, NULL);
 790         add_function_hook("__smatch_intersection", &match_intersection, NULL);
 791         add_function_hook("__smatch_type", &match_type, NULL);
 792         add_implied_return_hook("__smatch_type_rl_helper", &match_type_rl_return, NULL);
 793         add_function_hook("__smatch_merge_tree", &match_print_merge_tree, NULL);
 794         add_function_hook("__smatch_stree_id", &match_print_stree_id, NULL);
 795         add_function_hook("__smatch_mtag", &match_mtag, NULL);
 796         add_function_hook("__smatch_mtag_data", &match_mtag_data_offset, NULL);
 797         add_function_hook("__smatch_state_count", &match_state_count, NULL);
 798         add_function_hook("__smatch_mem", &match_mem, NULL);
 799         add_function_hook("__smatch_exit", &match_exit, NULL);
 800         add_function_hook("__smatch_container", &match_container, NULL);
 801 
 802         add_hook(free_old_stree, AFTER_FUNC_HOOK);
 803         add_hook(trace_var, STMT_HOOK_AFTER);
 804 }