From 71ae39b2d3415ab7a21e7ef1f849baaba82d100f Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Mon, 11 Feb 2013 15:00:39 +0300 Subject: [PATCH] db: move return_states to raw SQL Instead of printing human readable text and parsing it with fill_db_return_states.pl, just print raw SQL and parse it with fill_db_sql.pl. Signed-off-by: Dan Carpenter --- check_user_data.c | 4 +- smatch_db.c | 3 +- smatch_extra.c | 5 +- smatch_param_filter.c | 10 ++- smatch_param_limit.c | 16 ++--- smatch_param_set.c | 5 +- smatch_parse_call_math.c | 10 +-- smatch_scripts/db/fill_db_return_states.pl | 107 ----------------------------- 8 files changed, 25 insertions(+), 135 deletions(-) delete mode 100755 smatch_scripts/db/fill_db_return_states.pl diff --git a/check_user_data.c b/check_user_data.c index efbeddf1..e114e90e 100644 --- a/check_user_data.c +++ b/check_user_data.c @@ -320,8 +320,8 @@ static void struct_member_callback(char *fn, char *global_static, int param, cha static void print_returned_user_data(int return_id, char *return_ranges, struct expression *expr, struct state_list *slist) { if (is_user_data(expr)) { - sm_msg("info: returns_user_data %d '%s' %s", - return_id, return_ranges, global_static()); + sql_insert_return_states(return_id, return_ranges, USER_DATA, + -1, "", ""); } } diff --git a/smatch_db.c b/smatch_db.c index da9de6d0..eb8f8343 100644 --- a/smatch_db.c +++ b/smatch_db.c @@ -535,8 +535,7 @@ static void global_variable(struct symbol *sym) static void match_return_info(int return_id, char *return_ranges, struct expression *expr, struct state_list *slist) { - sm_msg("info: return_marker %d '%s' %s", return_id, return_ranges, - global_static()); + sql_insert_return_states(return_id, return_ranges, INTERNAL, -1, "", ""); } static int return_id; diff --git a/smatch_extra.c b/smatch_extra.c index 7399974f..0c405de7 100644 --- a/smatch_extra.c +++ b/smatch_extra.c @@ -1181,8 +1181,9 @@ static void returned_member_callback(int return_id, char *return_ranges, char *p { if (estate_is_whole(state)) return; - sm_msg("info: return_value %d '%s' '%s' '%s' %s", return_id, - return_ranges, printed_name, state->name, global_static()); + + sql_insert_return_states(return_id, return_ranges, RETURN_VALUE, -1, + printed_name, state->name); } static void match_call_info(struct expression *expr) diff --git a/smatch_param_filter.c b/smatch_param_filter.c index 192d29f9..ab58d49d 100644 --- a/smatch_param_filter.c +++ b/smatch_param_filter.c @@ -113,9 +113,8 @@ static void print_one_mod_param(int return_id, char *return_ranges, if (!filter) return; - sm_msg("info: return_param_filter %d %d '%s' '%s' '%s' %s", - return_id, param, return_ranges, - param_name, filter, global_static()); + sql_insert_return_states(return_id, return_ranges, FILTER_VALUE, param, + param_name, filter); } static void print_one_extra_param(int return_id, char *return_ranges, @@ -132,9 +131,8 @@ static void print_one_extra_param(int return_id, char *return_ranges, if (!param_name) return; - sm_msg("info: return_param_filter %d %d '%s' '%s' '%s' %s", - return_id, param, return_ranges, - param_name, show_rl(estate_rl(sm->state)), global_static()); + sql_insert_return_states(return_id, return_ranges, FILTER_VALUE, param, + param_name, sm->state->name); } static void print_return_value_param(int return_id, char *return_ranges, struct expression *expr, struct state_list *slist) diff --git a/smatch_param_limit.c b/smatch_param_limit.c index fae9500a..0a0b78ef 100644 --- a/smatch_param_limit.c +++ b/smatch_param_limit.c @@ -115,10 +115,10 @@ static void print_return_value_param(int return_id, char *return_ranges, struct old = get_state_slist(start_states, SMATCH_EXTRA, tmp->name, tmp->sym); if (old && estates_equiv(old, tmp->state)) continue; - sm_msg("info: return_param_limit %d %d '%s' '$$' '%s' %s", - return_id, param, return_ranges, - tmp->state->name, global_static()); - continue; + sql_insert_return_states(return_id, return_ranges, + LIMITED_VALUE, param, "$$", + tmp->state->name); + continue; } state = filter_my_sm(my_sm); @@ -127,16 +127,14 @@ static void print_return_value_param(int return_id, char *return_ranges, struct /* This represents an impossible state. I screwd up. Bail. */ if (!estate_rl(state)) continue; - sm_msg("info: return_param_limit %d %d '%s' '$$' '%s' %s", - return_id, param, return_ranges, - state->name, global_static()); + sql_insert_return_states(return_id, return_ranges, + LIMITED_VALUE, param, "$$", + state->name); } END_FOR_EACH_PTR(tmp); free_slist(&extra_slist); } - - static void extra_mod_hook(const char *name, struct symbol *sym, struct smatch_state *state) { struct smatch_state *orig_vals; diff --git a/smatch_param_set.c b/smatch_param_set.c index dd215eb0..6d3f7eec 100644 --- a/smatch_param_set.c +++ b/smatch_param_set.c @@ -70,9 +70,8 @@ static void print_one_return_value_param(int return_id, char *return_ranges, if (!param_name) return; - sm_msg("info: return_param_add %d %d '%s' '%s' '%s' %s", - return_id, param, return_ranges, - param_name, implied_rl, global_static()); + sql_insert_return_states(return_id, return_ranges, ADDED_VALUE, param, + param_name, implied_rl); } static void print_return_value_param(int return_id, char *return_ranges, struct expression *expr, struct state_list *slist) diff --git a/smatch_parse_call_math.c b/smatch_parse_call_math.c index ab4fb30d..de6f97cc 100644 --- a/smatch_parse_call_math.c +++ b/smatch_parse_call_math.c @@ -461,8 +461,9 @@ static void match_returns_call(int return_id, char *return_ranges, struct expres sm_msg("sname = %s", sname); if (!sname) return; - sm_msg("info: return_allocation %d '%s' '%s' %s", - return_id, return_ranges, sname, global_static()); + + sql_insert_return_states(return_id, return_ranges, BUF_SIZE, -1, "", + sname); } static void print_returned_allocations(int return_id, char *return_ranges, struct expression *expr, struct state_list *slist) @@ -487,8 +488,9 @@ static void print_returned_allocations(int return_id, char *return_ranges, struc state = get_state_slist(slist, my_id, name, sym); if (!state || !state->data) goto free; - sm_msg("info: return_allocation %d '%s' '%s' %s", - return_id, return_ranges, state->name, global_static()); + + sql_insert_return_states(return_id, return_ranges, BUF_SIZE, -1, "", + state->name); free: free_string(name); } diff --git a/smatch_scripts/db/fill_db_return_states.pl b/smatch_scripts/db/fill_db_return_states.pl deleted file mode 100755 index 003ba83e..00000000 --- a/smatch_scripts/db/fill_db_return_states.pl +++ /dev/null @@ -1,107 +0,0 @@ -#!/usr/bin/perl -w - -use strict; -use DBI; - -my $warns = shift; - -if (!defined($warns)) { - print "usage: $0 \n"; - exit(1); -} - -my $db = DBI->connect("dbi:SQLite:smatch_db.sqlite", "", "", {AutoCommit => 0}); -$db->do("PRAGMA synchronous = OFF"); -$db->do("PRAGMA cache_size = 800000"); -$db->do("PRAGMA journal_mode = OFF"); - -$db->do("delete from return_states;"); - -my $type; -my $param; -my ($file_and_line, $file, $dummy, $func, $return_id, $return_value, $key, $value, $gs); -my $static; - -open(WARNS, "<$warns"); -while () { - - if ($_ =~ /info: return_marker/) { - # net/ipv4/inet_diag.c:363 bitstring_match() info: return_marker 1 '1' static - $type = 0; # INTERNAL - $value = ''; - ($file_and_line, $func, $dummy, $dummy, $return_id, $return_value, $gs) = split(/ /, $_); - $key = ""; - $param = -1; - } elsif ($_ =~ /info: returns_locked/) { - # net/ipv4/inet_diag.c:363 bitstring_match() info: returns_locked 1 '0' 'spin_lock:lock' static - $type = 9; # LOCK_HELD - $value = ''; - ($file_and_line, $func, $dummy, $dummy, $return_id, $return_value, $key, $gs) = split(/ /, $_); - $param = -1; - } elsif ($_ =~ /info: returns_released/) { - # net/ipv4/inet_diag.c:363 bitstring_match() info: returns_locked 1 '0' 'spin_lock:lock' static - $type = 10; # LOCK_RELEASED - $value = ''; - ($file_and_line, $func, $dummy, $dummy, $return_id, $return_value, $key, $gs) = split(/ /, $_); - $param = -1; - } elsif ($_ =~ /info: returns_user_data/) { - # net/netfilter/ipset/ip_set_hash_netiface.c:402 ip_set_get_h32() info: returns_user_data 1 '' static - $type = 3; # USER_DATA - $key = ''; - $value = ''; - ($file_and_line, $func, $dummy, $dummy, $return_id, $return_value, $gs) = split(/ /, $_); - $param = -1; - } elsif ($_ =~ /info: return_allocation /) { - # drivers/net/usb/hso.c:2374 hso_create_device() info: return_allocation 2 'min-max' '456' static - $type = 2; # BUF_SIZE - $key = ''; - ($file_and_line, $func, $dummy, $dummy, $return_id, $dummy) = split(/ /, $_); - ($dummy, $return_value, $dummy, $value, $gs) = split(/'/, $_); - $param = -1; - } elsif ($_ =~ /info: return_value /) { - # test.c:15 alloc_foo() info: return_value 1 '4096-s64max' '$$->x' '1' global - $type = 5; # RETURN_VALUE - ($file_and_line, $func, $dummy, $dummy, $return_id, $dummy) = split(/ /, $_); - ($dummy, $return_value, $dummy, $key, $dummy, $value, $gs) = split(/'/, $_); - $param = -1; - } elsif ($_ =~ /info: return_value_param /) { - # test.c:11 set_int() info: return_value_param 0 0 '' '*$$' '1' global - $type = 1; # PARAM_VALUE - ($file_and_line, $func, $dummy, $dummy, $return_id, $param, $dummy) = split(/ /, $_); - ($dummy, $return_value, $dummy, $key, $dummy, $value, $gs) = split(/'/, $_); - } elsif ($_ =~ /info: return_param_limit /) { - # crypto/zlib.c:52 zlib_comp_exit() info: return_param_limit 1 0 '' '$$' '4096-s64max' static - $type = 11; # LIMITED_VALUE - ($file_and_line, $func, $dummy, $dummy, $return_id, $param, $dummy) = split(/ /, $_); - ($dummy, $return_value, $dummy, $key, $dummy, $value, $gs) = split(/'/, $_); - } elsif ($_ =~ /info: return_param_filter /) { - # crypto/af_alg.c:267 af_alg_accept() info: return_param_filter 3 1 '(-12)' '$$->state' '3' global - $type = 13; # FILTER_VALUE - ($file_and_line, $func, $dummy, $dummy, $return_id, $param, $dummy) = split(/ /, $_); - ($dummy, $return_value, $dummy, $key, $dummy, $value, $gs) = split(/'/, $_); - } elsif ($_ =~ /info: return_param_add /) { - # crypto/af_alg.c:267 af_alg_accept() info: return_param_add 3 1 '(-12)' '$$->state' '3' global - $type = 12; # ADDED_VALUE - ($file_and_line, $func, $dummy, $dummy, $return_id, $param, $dummy) = split(/ /, $_); - ($dummy, $return_value, $dummy, $key, $dummy, $value, $gs) = split(/'/, $_); - } else { - next; - } - - ($file, $dummy) = split(/:/, $file_and_line); - - $func =~ s/\(\)//; - $return_value =~ s/'//g; - $key =~ s/'//g; - $value =~ s/'//g; - - $static = 0; - if ($gs =~ /static/) { - $static = 1; - } - - $db->do("insert into return_states values ('$file', '$func', $return_id, '$return_value', $static, $type, $param, '$key', '$value')\n"); -} - -$db->commit(); -$db->disconnect(); -- 2.11.4.GIT