Print this page
12724 update smatch to 0.6.1-rc1-il-5


  61                 sm_error("the state_name argument to %s is supposed to be a string literal", fn);
  62                 return;
  63         }
  64 
  65         FOR_EACH_SM(__get_cur_stree(), sm) {
  66                 if (strcmp(check_name(sm->owner), check_arg->string->data) != 0)
  67                         continue;
  68                 if (strcmp(sm->name, state_arg->string->data) != 0)
  69                         continue;
  70                 sm_msg("'%s' = '%s'", sm->name, sm->state->name);
  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 
 112         arg_expr = get_argument_from_call_expr(expr->args, 0);
 113         if (arg_expr->type != EXPR_STRING) {
 114                 sm_error("the argument to %s is supposed to be a string literal", fn);
 115                 return;
 116         }
 117 


 193         char *name;
 194 
 195         arg = get_argument_from_call_expr(expr->args, 0);
 196         name = expr_to_str(arg);
 197 
 198         if (get_implied_max(arg, &sval))
 199                 sm_msg("implied max: %s = %s", name, sval_to_str(sval));
 200         else
 201                 sm_msg("implied max: %s = <unknown>", name);
 202 
 203         free_string(name);
 204 }
 205 
 206 static void match_user_rl(const char *fn, struct expression *expr, void *info)
 207 {
 208         struct expression *arg;
 209         struct range_list *rl = NULL;
 210         bool capped = false;
 211         char *name;
 212 



 213         arg = get_argument_from_call_expr(expr->args, 0);
 214         name = expr_to_str(arg);
 215 
 216         get_user_rl(arg, &rl);
 217         if (rl)
 218                 capped = user_rl_capped(arg);
 219         sm_msg("user rl: '%s' = '%s'%s", name, show_rl(rl), capped ? " (capped)" : "");
 220 
 221         free_string(name);
 222 }
 223 
 224 static void match_capped(const char *fn, struct expression *expr, void *info)
 225 {
 226         struct expression *arg;
 227         char *name;
 228 
 229         arg = get_argument_from_call_expr(expr->args, 0);
 230         name = expr_to_str(arg);
 231         sm_msg("'%s' = '%s'", name, is_capped(arg) ? "capped" : "not capped");
 232         free_string(name);


 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) {
 549                 if (strcmp(sm->name, name) != 0)
 550                         continue;
 551                 sm_msg("%s", show_sm(sm));
 552         } END_FOR_EACH_SM(sm);
 553 }
 554 
 555 static void match_intersection(const char *fn, struct expression *expr, void *info)
 556 {
 557         struct expression *one, *two;
 558         struct range_list *one_rl, *two_rl;
 559         struct range_list *res;


 634         sm = get_sm_state_expr(SMATCH_EXTRA, arg);
 635         if (!sm) {
 636                 sm_msg("no sm state for '%s'", name);
 637                 goto free;
 638         }
 639 
 640         sm_prefix();
 641         sm_printf("merge tree: %s -> %s", name, sm->state->name);
 642         print_left_right(sm);
 643         sm_printf("\n");
 644 
 645 free:
 646         free_string(name);
 647 }
 648 
 649 static void match_print_stree_id(const char *fn, struct expression *expr, void *info)
 650 {
 651         sm_msg("stree_id %d", __stree_id);
 652 }
 653 















 654 static void match_mtag(const char *fn, struct expression *expr, void *info)
 655 {
 656         struct expression *arg;
 657         char *name;
 658         mtag_t tag = 0;
 659         int offset = 0;
 660 
 661         arg = get_argument_from_call_expr(expr->args, 0);
 662         name = expr_to_str(arg);
 663         expr_to_mtag_offset(arg, &tag, &offset);
 664         sm_msg("mtag: '%s' => tag: %llu %d", name, tag, offset);
 665         free_string(name);
 666 }
 667 
 668 static void match_mtag_data_offset(const char *fn, struct expression *expr, void *info)
 669 {
 670         struct expression *arg;
 671         char *name;
 672         mtag_t tag = 0;
 673         int offset = -1;


 678         sm_msg("mtag: '%s' => tag: %lld, offset: %d", name, tag, offset);
 679         free_string(name);
 680 }
 681 
 682 static void match_container(const char *fn, struct expression *expr, void *info)
 683 {
 684         struct expression *container, *x;
 685         char *cont, *name, *str;
 686 
 687         container = get_argument_from_call_expr(expr->args, 0);
 688         x = get_argument_from_call_expr(expr->args, 1);
 689 
 690         str = get_container_name(container, x);
 691         cont = expr_to_str(container);
 692         name = expr_to_str(x);
 693         sm_msg("container: '%s' vs '%s' --> '%s'", cont, name, str);
 694         free_string(cont);
 695         free_string(name);
 696 }
 697 






















 698 static void match_state_count(const char *fn, struct expression *expr, void *info)
 699 {
 700         sm_msg("state_count = %d\n", sm_state_counter);
 701 }
 702 
 703 static void match_mem(const char *fn, struct expression *expr, void *info)
 704 {
 705         show_sname_alloc();
 706         show_data_range_alloc();
 707         show_rl_ptrlist_alloc();
 708         show_ptrlist_alloc();
 709         sm_msg("%lu pools", get_pool_count());
 710         sm_msg("%d strees", unfree_stree);
 711         show_smatch_state_alloc();
 712         show_sm_state_alloc();
 713 }
 714 
 715 static void match_exit(const char *fn, struct expression *expr, void *info)
 716 {
 717         exit(0);


 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 }


  61                 sm_error("the state_name argument to %s is supposed to be a string literal", fn);
  62                 return;
  63         }
  64 
  65         FOR_EACH_SM(__get_cur_stree(), sm) {
  66                 if (strcmp(check_name(sm->owner), check_arg->string->data) != 0)
  67                         continue;
  68                 if (strcmp(sm->name, state_arg->string->data) != 0)
  69                         continue;
  70                 sm_msg("'%s' = '%s'", sm->name, sm->state->name);
  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 
  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         if (__print_states(check_arg->string->data))







  89                 return;
  90 
  91         if (!id_from_name(check_arg->string->data))
  92                 sm_msg("invalid check name '%s'", check_arg->string->data);
  93         else
  94                 sm_msg("%s: no states", check_arg->string->data);
  95 }
  96 
  97 static void match_print_value(const char *fn, struct expression *expr, void *info)
  98 {
  99         struct stree *stree;
 100         struct sm_state *tmp;
 101         struct expression *arg_expr;
 102 
 103         arg_expr = get_argument_from_call_expr(expr->args, 0);
 104         if (arg_expr->type != EXPR_STRING) {
 105                 sm_error("the argument to %s is supposed to be a string literal", fn);
 106                 return;
 107         }
 108 


 184         char *name;
 185 
 186         arg = get_argument_from_call_expr(expr->args, 0);
 187         name = expr_to_str(arg);
 188 
 189         if (get_implied_max(arg, &sval))
 190                 sm_msg("implied max: %s = %s", name, sval_to_str(sval));
 191         else
 192                 sm_msg("implied max: %s = <unknown>", name);
 193 
 194         free_string(name);
 195 }
 196 
 197 static void match_user_rl(const char *fn, struct expression *expr, void *info)
 198 {
 199         struct expression *arg;
 200         struct range_list *rl = NULL;
 201         bool capped = false;
 202         char *name;
 203 
 204         if (option_project != PROJ_KERNEL)
 205                 sm_msg("no user data for project = '%s'", option_project_str);
 206 
 207         arg = get_argument_from_call_expr(expr->args, 0);
 208         name = expr_to_str(arg);
 209 
 210         get_user_rl(arg, &rl);
 211         if (rl)
 212                 capped = user_rl_capped(arg);
 213         sm_msg("user rl: '%s' = '%s'%s", name, show_rl(rl), capped ? " (capped)" : "");
 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);


 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_debug_db_on(const char *fn, struct expression *expr, void *info)
 514 {
 515         debug_db = 1;
 516 }
 517 
 518 static void match_debug_db_off(const char *fn, struct expression *expr, void *info)
 519 {
 520         debug_db = 0;
 521 }
 522 
 523 static void mtag_info(struct expression *expr)
 524 {
 525         mtag_t tag = 0;
 526         int offset = 0;
 527         struct range_list *rl = NULL;
 528 
 529         expr_to_mtag_offset(expr, &tag, &offset);
 530         get_mtag_rl(expr, &rl);
 531         sm_msg("mtag = %llu offset = %d rl = '%s'", tag, offset, show_rl(rl));
 532 }
 533 
 534 static void match_about(const char *fn, struct expression *expr, void *info)
 535 {
 536         struct expression *arg;
 537         struct sm_state *sm;
 538         char *name;
 539 
 540         sm_msg("---- about ----");
 541         match_print_implied(fn, expr, NULL);
 542         match_buf_size(fn, expr, NULL);
 543         match_strlen(fn, expr, NULL);
 544         match_real_absolute(fn, expr, NULL);
 545         mtag_info(expr);
 546 
 547         arg = get_argument_from_call_expr(expr->args, 0);
 548         name = expr_to_str(arg);
 549         if (!name) {
 550                 sm_msg("info: not a straight forward variable.");
 551                 return;
 552         }
 553 
 554         FOR_EACH_SM(__get_cur_stree(), sm) {
 555                 if (strcmp(sm->name, name) != 0)
 556                         continue;
 557                 sm_msg("%s", show_sm(sm));
 558         } END_FOR_EACH_SM(sm);
 559 }
 560 
 561 static void match_intersection(const char *fn, struct expression *expr, void *info)
 562 {
 563         struct expression *one, *two;
 564         struct range_list *one_rl, *two_rl;
 565         struct range_list *res;


 640         sm = get_sm_state_expr(SMATCH_EXTRA, arg);
 641         if (!sm) {
 642                 sm_msg("no sm state for '%s'", name);
 643                 goto free;
 644         }
 645 
 646         sm_prefix();
 647         sm_printf("merge tree: %s -> %s", name, sm->state->name);
 648         print_left_right(sm);
 649         sm_printf("\n");
 650 
 651 free:
 652         free_string(name);
 653 }
 654 
 655 static void match_print_stree_id(const char *fn, struct expression *expr, void *info)
 656 {
 657         sm_msg("stree_id %d", __stree_id);
 658 }
 659 
 660 static void match_bits(const char *fn, struct expression *expr, void *_unused)
 661 {
 662         struct expression *arg;
 663         struct bit_info *info;
 664         char *name;
 665 
 666         arg = get_argument_from_call_expr(expr->args, 0);
 667         name = expr_to_str(arg);
 668 
 669         info = get_bit_info(arg);
 670 
 671         sm_msg("bit info '%s': definitely set 0x%llx.  possibly set 0x%llx.",
 672                name, info->set, info->possible);
 673 }
 674 
 675 static void match_mtag(const char *fn, struct expression *expr, void *info)
 676 {
 677         struct expression *arg;
 678         char *name;
 679         mtag_t tag = 0;
 680         int offset = 0;
 681 
 682         arg = get_argument_from_call_expr(expr->args, 0);
 683         name = expr_to_str(arg);
 684         expr_to_mtag_offset(arg, &tag, &offset);
 685         sm_msg("mtag: '%s' => tag: %llu %d", name, tag, offset);
 686         free_string(name);
 687 }
 688 
 689 static void match_mtag_data_offset(const char *fn, struct expression *expr, void *info)
 690 {
 691         struct expression *arg;
 692         char *name;
 693         mtag_t tag = 0;
 694         int offset = -1;


 699         sm_msg("mtag: '%s' => tag: %lld, offset: %d", name, tag, offset);
 700         free_string(name);
 701 }
 702 
 703 static void match_container(const char *fn, struct expression *expr, void *info)
 704 {
 705         struct expression *container, *x;
 706         char *cont, *name, *str;
 707 
 708         container = get_argument_from_call_expr(expr->args, 0);
 709         x = get_argument_from_call_expr(expr->args, 1);
 710 
 711         str = get_container_name(container, x);
 712         cont = expr_to_str(container);
 713         name = expr_to_str(x);
 714         sm_msg("container: '%s' vs '%s' --> '%s'", cont, name, str);
 715         free_string(cont);
 716         free_string(name);
 717 }
 718 
 719 static void match_expr(const char *fn, struct expression *expr, void *info)
 720 {
 721         struct expression *arg, *str, *new;
 722         char *name, *new_name;
 723 
 724         str = get_argument_from_call_expr(expr->args, 0);
 725         arg = get_argument_from_call_expr(expr->args, 1);
 726         if (!arg || !str)
 727                 return;
 728 
 729         if (str->type != EXPR_STRING)
 730                 return;
 731 
 732         new = gen_expression_from_key(arg, str->string->data);
 733         name = expr_to_str(arg);
 734         new_name = expr_to_str(new);
 735 
 736         sm_msg("str = '%s', arg = '%s' expr = '%s'", str->string->data, name, new_name);
 737 
 738         free_string(new_name);
 739         free_string(name);
 740 }
 741 static void match_state_count(const char *fn, struct expression *expr, void *info)
 742 {
 743         sm_msg("state_count = %d\n", sm_state_counter);
 744 }
 745 
 746 static void match_mem(const char *fn, struct expression *expr, void *info)
 747 {
 748         show_sname_alloc();
 749         show_data_range_alloc();
 750         show_rl_ptrlist_alloc();
 751         show_ptrlist_alloc();
 752         sm_msg("%lu pools", get_pool_count());
 753         sm_msg("%d strees", unfree_stree);
 754         show_smatch_state_alloc();
 755         show_sm_state_alloc();
 756 }
 757 
 758 static void match_exit(const char *fn, struct expression *expr, void *info)
 759 {
 760         exit(0);


 818         add_function_hook("__smatch_member_name", &match_member_name, NULL);
 819         add_function_hook("__smatch_possible", &match_possible, NULL);
 820         add_function_hook("__smatch_cur_stree", &match_cur_stree, NULL);
 821         add_function_hook("__smatch_strlen", &match_strlen, NULL);
 822         add_function_hook("__smatch_buf_size", &match_buf_size, NULL);
 823         add_function_hook("__smatch_note", &match_note, NULL);
 824         add_function_hook("__smatch_dump_related", &match_dump_related, NULL);
 825         add_function_hook("__smatch_compare", &match_compare, NULL);
 826         add_function_hook("__smatch_debug_on", &match_debug_on, NULL);
 827         add_function_hook("__smatch_debug_check", &match_debug_check, NULL);
 828         add_function_hook("__smatch_debug_off", &match_debug_off, NULL);
 829         add_function_hook("__smatch_local_debug_on", &match_local_debug_on, NULL);
 830         add_function_hook("__smatch_local_debug_off", &match_local_debug_off, NULL);
 831         add_function_hook("__smatch_debug_db_on", &match_debug_db_on, NULL);
 832         add_function_hook("__smatch_debug_db_off", &match_debug_db_off, NULL);
 833         add_function_hook("__smatch_intersection", &match_intersection, NULL);
 834         add_function_hook("__smatch_type", &match_type, NULL);
 835         add_implied_return_hook("__smatch_type_rl_helper", &match_type_rl_return, NULL);
 836         add_function_hook("__smatch_merge_tree", &match_print_merge_tree, NULL);
 837         add_function_hook("__smatch_stree_id", &match_print_stree_id, NULL);
 838         add_function_hook("__smatch_bits", &match_bits, NULL);
 839         add_function_hook("__smatch_mtag", &match_mtag, NULL);
 840         add_function_hook("__smatch_mtag_data", &match_mtag_data_offset, NULL);
 841         add_function_hook("__smatch_expr", &match_expr, NULL);
 842         add_function_hook("__smatch_state_count", &match_state_count, NULL);
 843         add_function_hook("__smatch_mem", &match_mem, NULL);
 844         add_function_hook("__smatch_exit", &match_exit, NULL);
 845         add_function_hook("__smatch_container", &match_container, NULL);
 846 
 847         add_hook(free_old_stree, AFTER_FUNC_HOOK);
 848         add_hook(trace_var, STMT_HOOK_AFTER);
 849 }