Print this page
11506 smatch resync


   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 int local_debug;
  23 static int my_id;
  24 char *trace_variable;
  25 
  26 static void match_all_values(const char *fn, struct expression *expr, void *info)
  27 {
  28         struct stree *stree;
  29 
  30         stree = get_all_states_stree(SMATCH_EXTRA);
  31         __print_stree(stree);
  32         free_stree(&stree);
  33 }
  34 
  35 static void match_cur_stree(const char *fn, struct expression *expr, void *info)
  36 {
  37         __print_cur_stree();
  38 }
  39 
  40 static void match_state(const char *fn, struct expression *expr, void *info)
  41 {


 181 static void match_print_implied_max(const char *fn, struct expression *expr, void *info)
 182 {
 183         struct expression *arg;
 184         sval_t sval;
 185         char *name;
 186 
 187         arg = get_argument_from_call_expr(expr->args, 0);
 188         name = expr_to_str(arg);
 189 
 190         if (get_implied_max(arg, &sval))
 191                 sm_msg("implied max: %s = %s", name, sval_to_str(sval));
 192         else
 193                 sm_msg("implied max: %s = <unknown>", name);
 194 
 195         free_string(name);
 196 }
 197 
 198 static void match_user_rl(const char *fn, struct expression *expr, void *info)
 199 {
 200         struct expression *arg;
 201         struct range_list *rl;
 202         char *name;
 203 
 204         arg = get_argument_from_call_expr(expr->args, 0);
 205         name = expr_to_str(arg);
 206 
 207         get_user_rl(arg, &rl);
 208         sm_msg("user rl: '%s' = '%s'", name, show_rl(rl));
 209 
 210         free_string(name);
 211 }
 212 
 213 static void match_capped(const char *fn, struct expression *expr, void *info)
 214 {
 215         struct expression *arg;
 216         char *name;
 217 
 218         arg = get_argument_from_call_expr(expr->args, 0);
 219         name = expr_to_str(arg);
 220         sm_msg("'%s' = '%s'", name, is_capped(arg) ? "capped" : "not capped");
 221         free_string(name);


 367 {
 368         struct expression *arg;
 369         struct range_list *rl;
 370         char *name;
 371 
 372         arg = get_argument_from_call_expr(expr->args, 0);
 373         get_implied_strlen(arg, &rl);
 374 
 375         name = expr_to_str(arg);
 376         sm_msg("strlen: '%s' %s characters", name, show_rl(rl));
 377         free_string(name);
 378 }
 379 
 380 static void match_buf_size(const char *fn, struct expression *expr, void *info)
 381 {
 382         struct expression *arg, *comp;
 383         struct range_list *rl;
 384         int elements, bytes;
 385         char *name;
 386         char buf[256] = "";

 387         int n;
 388         sval_t sval;
 389 
 390         arg = get_argument_from_call_expr(expr->args, 0);
 391 
 392         elements = get_array_size(arg);
 393         bytes = get_array_size_bytes_max(arg);
 394         rl = get_array_size_bytes_rl(arg);
 395         comp = get_size_variable(arg);
 396 
 397         name = expr_to_str(arg);
 398         n = snprintf(buf, sizeof(buf), "buf size: '%s' %d elements, %d bytes", name, elements, bytes);
 399         free_string(name);
 400 
 401         if (!rl_to_sval(rl, &sval))
 402                 n += snprintf(buf + n, sizeof(buf) - n, " (rl = %s)", show_rl(rl));
 403 
 404         if (comp) {
 405                 name = expr_to_str(comp);
 406                 snprintf(buf + n, sizeof(buf) - n, "[size_var=%s]", name);
 407                 free_string(name);
 408         }
 409         sm_msg("%s", buf);
 410 }
 411 
 412 static void match_note(const char *fn, struct expression *expr, void *info)
 413 {
 414         struct expression *arg_expr;
 415 
 416         arg_expr = get_argument_from_call_expr(expr->args, 0);
 417         if (arg_expr->type != EXPR_STRING) {
 418                 sm_error("the argument to %s is supposed to be a string literal", fn);
 419                 return;
 420         }
 421         sm_msg("%s", arg_expr->string->data);
 422 }
 423 
 424 static void print_related(struct sm_state *sm)
 425 {
 426         struct relation *rel;


 487         option_debug_check = arg->string->data;
 488         sm_msg("arg = '%s'", option_debug_check);
 489 }
 490 
 491 static void match_debug_off(const char *fn, struct expression *expr, void *info)
 492 {
 493         option_debug_check = (char *)"";
 494         option_debug = 0;
 495 }
 496 
 497 static void match_local_debug_on(const char *fn, struct expression *expr, void *info)
 498 {
 499         local_debug = 1;
 500 }
 501 
 502 static void match_local_debug_off(const char *fn, struct expression *expr, void *info)
 503 {
 504         local_debug = 0;
 505 }
 506 
 507 static void match_debug_implied_on(const char *fn, struct expression *expr, void *info)
 508 {
 509         option_debug_implied = 1;
 510 }
 511 
 512 static void match_debug_implied_off(const char *fn, struct expression *expr, void *info)
 513 {
 514         option_debug_implied = 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) {


 627 
 628         sm_prefix();
 629         sm_printf("merge tree: %s -> %s", name, sm->state->name);
 630         print_left_right(sm);
 631         sm_printf("\n");
 632 
 633 free:
 634         free_string(name);
 635 }
 636 
 637 static void match_print_stree_id(const char *fn, struct expression *expr, void *info)
 638 {
 639         sm_msg("stree_id %d", __stree_id);
 640 }
 641 
 642 static void match_mtag(const char *fn, struct expression *expr, void *info)
 643 {
 644         struct expression *arg;
 645         char *name;
 646         mtag_t tag = 0;

 647 
 648         arg = get_argument_from_call_expr(expr->args, 0);
 649         name = expr_to_str(arg);
 650         get_mtag(arg, &tag);
 651         sm_msg("mtag: '%s' => tag: %lld", name, tag);
 652         free_string(name);
 653 }
 654 
 655 static void match_mtag_data_offset(const char *fn, struct expression *expr, void *info)
 656 {
 657         struct expression *arg;
 658         char *name;
 659         mtag_t tag = 0;
 660         int offset = -1;
 661 
 662         arg = get_argument_from_call_expr(expr->args, 0);
 663         name = expr_to_str(arg);
 664         expr_to_mtag_offset(arg, &tag, &offset);
 665         sm_msg("mtag: '%s' => tag: %lld, offset: %d", name, tag, offset);
 666         free_string(name);
 667 }
 668 
















 669 static void match_state_count(const char *fn, struct expression *expr, void *info)
 670 {
 671         sm_msg("state_count = %d\n", sm_state_counter);
 672 }
 673 
 674 static void match_mem(const char *fn, struct expression *expr, void *info)
 675 {
 676         show_sname_alloc();
 677         show_ptrlist_alloc();
 678         sm_msg("%lu pools", get_pool_count());
 679         sm_msg("%d strees", unfree_stree);
 680         show_smatch_state_alloc();
 681         show_sm_state_alloc();
 682 }
 683 
 684 static void match_exit(const char *fn, struct expression *expr, void *info)
 685 {
 686         exit(0);
 687 }
 688 


 737         add_function_hook("__smatch_hard_max", &match_print_hard_max, NULL);
 738         add_function_hook("__smatch_fuzzy_max", &match_print_fuzzy_max, NULL);
 739         add_function_hook("__smatch_absolute", &match_print_absolute, NULL);
 740         add_function_hook("__smatch_absolute_min", &match_print_absolute_min, NULL);
 741         add_function_hook("__smatch_absolute_max", &match_print_absolute_max, NULL);
 742         add_function_hook("__smatch_real_absolute", &match_real_absolute, NULL);
 743         add_function_hook("__smatch_sval_info", &match_sval_info, NULL);
 744         add_function_hook("__smatch_member_name", &match_member_name, NULL);
 745         add_function_hook("__smatch_possible", &match_possible, NULL);
 746         add_function_hook("__smatch_cur_stree", &match_cur_stree, NULL);
 747         add_function_hook("__smatch_strlen", &match_strlen, NULL);
 748         add_function_hook("__smatch_buf_size", &match_buf_size, NULL);
 749         add_function_hook("__smatch_note", &match_note, NULL);
 750         add_function_hook("__smatch_dump_related", &match_dump_related, NULL);
 751         add_function_hook("__smatch_compare", &match_compare, NULL);
 752         add_function_hook("__smatch_debug_on", &match_debug_on, NULL);
 753         add_function_hook("__smatch_debug_check", &match_debug_check, NULL);
 754         add_function_hook("__smatch_debug_off", &match_debug_off, NULL);
 755         add_function_hook("__smatch_local_debug_on", &match_local_debug_on, NULL);
 756         add_function_hook("__smatch_local_debug_off", &match_local_debug_off, NULL);
 757         add_function_hook("__smatch_debug_implied_on", &match_debug_implied_on, NULL);
 758         add_function_hook("__smatch_debug_implied_off", &match_debug_implied_off, NULL);
 759         add_function_hook("__smatch_intersection", &match_intersection, NULL);
 760         add_function_hook("__smatch_type", &match_type, NULL);
 761         add_implied_return_hook("__smatch_type_rl_helper", &match_type_rl_return, NULL);
 762         add_function_hook("__smatch_merge_tree", &match_print_merge_tree, NULL);
 763         add_function_hook("__smatch_stree_id", &match_print_stree_id, NULL);
 764         add_function_hook("__smatch_mtag", &match_mtag, NULL);
 765         add_function_hook("__smatch_mtag_data", &match_mtag_data_offset, NULL);
 766         add_function_hook("__smatch_state_count", &match_state_count, NULL);
 767         add_function_hook("__smatch_mem", &match_mem, NULL);
 768         add_function_hook("__smatch_exit", &match_exit, NULL);

 769 
 770         add_hook(free_old_stree, AFTER_FUNC_HOOK);
 771         add_hook(trace_var, STMT_HOOK_AFTER);
 772 }


   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_sm_state_alloc(void);
  26 
  27 int local_debug;
  28 static int my_id;
  29 char *trace_variable;
  30 
  31 static void match_all_values(const char *fn, struct expression *expr, void *info)
  32 {
  33         struct stree *stree;
  34 
  35         stree = get_all_states_stree(SMATCH_EXTRA);
  36         __print_stree(stree);
  37         free_stree(&stree);
  38 }
  39 
  40 static void match_cur_stree(const char *fn, struct expression *expr, void *info)
  41 {
  42         __print_cur_stree();
  43 }
  44 
  45 static void match_state(const char *fn, struct expression *expr, void *info)
  46 {


 186 static void match_print_implied_max(const char *fn, struct expression *expr, void *info)
 187 {
 188         struct expression *arg;
 189         sval_t sval;
 190         char *name;
 191 
 192         arg = get_argument_from_call_expr(expr->args, 0);
 193         name = expr_to_str(arg);
 194 
 195         if (get_implied_max(arg, &sval))
 196                 sm_msg("implied max: %s = %s", name, sval_to_str(sval));
 197         else
 198                 sm_msg("implied max: %s = <unknown>", name);
 199 
 200         free_string(name);
 201 }
 202 
 203 static void match_user_rl(const char *fn, struct expression *expr, void *info)
 204 {
 205         struct expression *arg;
 206         struct range_list *rl = NULL;
 207         char *name;
 208 
 209         arg = get_argument_from_call_expr(expr->args, 0);
 210         name = expr_to_str(arg);
 211 
 212         get_user_rl(arg, &rl);
 213         sm_msg("user rl: '%s' = '%s'", name, show_rl(rl));
 214 
 215         free_string(name);
 216 }
 217 
 218 static void match_capped(const char *fn, struct expression *expr, void *info)
 219 {
 220         struct expression *arg;
 221         char *name;
 222 
 223         arg = get_argument_from_call_expr(expr->args, 0);
 224         name = expr_to_str(arg);
 225         sm_msg("'%s' = '%s'", name, is_capped(arg) ? "capped" : "not capped");
 226         free_string(name);


 372 {
 373         struct expression *arg;
 374         struct range_list *rl;
 375         char *name;
 376 
 377         arg = get_argument_from_call_expr(expr->args, 0);
 378         get_implied_strlen(arg, &rl);
 379 
 380         name = expr_to_str(arg);
 381         sm_msg("strlen: '%s' %s characters", name, show_rl(rl));
 382         free_string(name);
 383 }
 384 
 385 static void match_buf_size(const char *fn, struct expression *expr, void *info)
 386 {
 387         struct expression *arg, *comp;
 388         struct range_list *rl;
 389         int elements, bytes;
 390         char *name;
 391         char buf[256] = "";
 392         int limit_type;
 393         int n;
 394         sval_t sval;
 395 
 396         arg = get_argument_from_call_expr(expr->args, 0);
 397 
 398         elements = get_array_size(arg);
 399         bytes = get_array_size_bytes_max(arg);
 400         rl = get_array_size_bytes_rl(arg);
 401         comp = get_size_variable(arg, &limit_type);
 402 
 403         name = expr_to_str(arg);
 404         n = snprintf(buf, sizeof(buf), "buf size: '%s' %d elements, %d bytes", name, elements, bytes);
 405         free_string(name);
 406 
 407         if (!rl_to_sval(rl, &sval))
 408                 n += snprintf(buf + n, sizeof(buf) - n, " (rl = %s)", show_rl(rl));
 409 
 410         if (comp) {
 411                 name = expr_to_str(comp);
 412                 snprintf(buf + n, sizeof(buf) - n, "[size_var=%s %s]", limit_type_str(limit_type), name);
 413                 free_string(name);
 414         }
 415         sm_msg("%s", buf);
 416 }
 417 
 418 static void match_note(const char *fn, struct expression *expr, void *info)
 419 {
 420         struct expression *arg_expr;
 421 
 422         arg_expr = get_argument_from_call_expr(expr->args, 0);
 423         if (arg_expr->type != EXPR_STRING) {
 424                 sm_error("the argument to %s is supposed to be a string literal", fn);
 425                 return;
 426         }
 427         sm_msg("%s", arg_expr->string->data);
 428 }
 429 
 430 static void print_related(struct sm_state *sm)
 431 {
 432         struct relation *rel;


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










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


 623 
 624         sm_prefix();
 625         sm_printf("merge tree: %s -> %s", name, sm->state->name);
 626         print_left_right(sm);
 627         sm_printf("\n");
 628 
 629 free:
 630         free_string(name);
 631 }
 632 
 633 static void match_print_stree_id(const char *fn, struct expression *expr, void *info)
 634 {
 635         sm_msg("stree_id %d", __stree_id);
 636 }
 637 
 638 static void match_mtag(const char *fn, struct expression *expr, void *info)
 639 {
 640         struct expression *arg;
 641         char *name;
 642         mtag_t tag = 0;
 643         int offset = 0;
 644 
 645         arg = get_argument_from_call_expr(expr->args, 0);
 646         name = expr_to_str(arg);
 647         expr_to_mtag_offset(arg, &tag, &offset);
 648         sm_msg("mtag: '%s' => tag: %llu %d", name, tag, offset);
 649         free_string(name);
 650 }
 651 
 652 static void match_mtag_data_offset(const char *fn, struct expression *expr, void *info)
 653 {
 654         struct expression *arg;
 655         char *name;
 656         mtag_t tag = 0;
 657         int offset = -1;
 658 
 659         arg = get_argument_from_call_expr(expr->args, 0);
 660         name = expr_to_str(arg);
 661         expr_to_mtag_offset(arg, &tag, &offset);
 662         sm_msg("mtag: '%s' => tag: %lld, offset: %d", name, tag, offset);
 663         free_string(name);
 664 }
 665 
 666 static void match_container(const char *fn, struct expression *expr, void *info)
 667 {
 668         struct expression *container, *x;
 669         char *cont, *name, *str;
 670 
 671         container = get_argument_from_call_expr(expr->args, 0);
 672         x = get_argument_from_call_expr(expr->args, 1);
 673 
 674         str = get_container_name(container, x);
 675         cont = expr_to_str(container);
 676         name = expr_to_str(x);
 677         sm_msg("container: '%s' vs '%s' --> '%s'", cont, name, str);
 678         free_string(cont);
 679         free_string(name);
 680 }
 681 
 682 static void match_state_count(const char *fn, struct expression *expr, void *info)
 683 {
 684         sm_msg("state_count = %d\n", sm_state_counter);
 685 }
 686 
 687 static void match_mem(const char *fn, struct expression *expr, void *info)
 688 {
 689         show_sname_alloc();
 690         show_ptrlist_alloc();
 691         sm_msg("%lu pools", get_pool_count());
 692         sm_msg("%d strees", unfree_stree);
 693         show_smatch_state_alloc();
 694         show_sm_state_alloc();
 695 }
 696 
 697 static void match_exit(const char *fn, struct expression *expr, void *info)
 698 {
 699         exit(0);
 700 }
 701 


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


 770         add_function_hook("__smatch_intersection", &match_intersection, NULL);
 771         add_function_hook("__smatch_type", &match_type, NULL);
 772         add_implied_return_hook("__smatch_type_rl_helper", &match_type_rl_return, NULL);
 773         add_function_hook("__smatch_merge_tree", &match_print_merge_tree, NULL);
 774         add_function_hook("__smatch_stree_id", &match_print_stree_id, NULL);
 775         add_function_hook("__smatch_mtag", &match_mtag, NULL);
 776         add_function_hook("__smatch_mtag_data", &match_mtag_data_offset, NULL);
 777         add_function_hook("__smatch_state_count", &match_state_count, NULL);
 778         add_function_hook("__smatch_mem", &match_mem, NULL);
 779         add_function_hook("__smatch_exit", &match_exit, NULL);
 780         add_function_hook("__smatch_container", &match_container, NULL);
 781 
 782         add_hook(free_old_stree, AFTER_FUNC_HOOK);
 783         add_hook(trace_var, STMT_HOOK_AFTER);
 784 }