db: tools for printing raw SQL instead of human readable info for the db
[smatch.git] / smatch_scripts / db / fill_db_return_states.pl
blob003ba83e3b126b538845ecb22f28c417690b565f
1 #!/usr/bin/perl -w
3 use strict;
4 use DBI;
6 my $warns = shift;
8 if (!defined($warns)) {
9 print "usage: $0 <warns.txt>\n";
10 exit(1);
13 my $db = DBI->connect("dbi:SQLite:smatch_db.sqlite", "", "", {AutoCommit => 0});
14 $db->do("PRAGMA synchronous = OFF");
15 $db->do("PRAGMA cache_size = 800000");
16 $db->do("PRAGMA journal_mode = OFF");
18 $db->do("delete from return_states;");
20 my $type;
21 my $param;
22 my ($file_and_line, $file, $dummy, $func, $return_id, $return_value, $key, $value, $gs);
23 my $static;
25 open(WARNS, "<$warns");
26 while (<WARNS>) {
28 if ($_ =~ /info: return_marker/) {
29 # net/ipv4/inet_diag.c:363 bitstring_match() info: return_marker 1 '1' static
30 $type = 0; # INTERNAL
31 $value = '';
32 ($file_and_line, $func, $dummy, $dummy, $return_id, $return_value, $gs) = split(/ /, $_);
33 $key = "";
34 $param = -1;
35 } elsif ($_ =~ /info: returns_locked/) {
36 # net/ipv4/inet_diag.c:363 bitstring_match() info: returns_locked 1 '0' 'spin_lock:lock' static
37 $type = 9; # LOCK_HELD
38 $value = '';
39 ($file_and_line, $func, $dummy, $dummy, $return_id, $return_value, $key, $gs) = split(/ /, $_);
40 $param = -1;
41 } elsif ($_ =~ /info: returns_released/) {
42 # net/ipv4/inet_diag.c:363 bitstring_match() info: returns_locked 1 '0' 'spin_lock:lock' static
43 $type = 10; # LOCK_RELEASED
44 $value = '';
45 ($file_and_line, $func, $dummy, $dummy, $return_id, $return_value, $key, $gs) = split(/ /, $_);
46 $param = -1;
47 } elsif ($_ =~ /info: returns_user_data/) {
48 # net/netfilter/ipset/ip_set_hash_netiface.c:402 ip_set_get_h32() info: returns_user_data 1 '' static
49 $type = 3; # USER_DATA
50 $key = '';
51 $value = '';
52 ($file_and_line, $func, $dummy, $dummy, $return_id, $return_value, $gs) = split(/ /, $_);
53 $param = -1;
54 } elsif ($_ =~ /info: return_allocation /) {
55 # drivers/net/usb/hso.c:2374 hso_create_device() info: return_allocation 2 'min-max' '456' static
56 $type = 2; # BUF_SIZE
57 $key = '';
58 ($file_and_line, $func, $dummy, $dummy, $return_id, $dummy) = split(/ /, $_);
59 ($dummy, $return_value, $dummy, $value, $gs) = split(/'/, $_);
60 $param = -1;
61 } elsif ($_ =~ /info: return_value /) {
62 # test.c:15 alloc_foo() info: return_value 1 '4096-s64max' '$$->x' '1' global
63 $type = 5; # RETURN_VALUE
64 ($file_and_line, $func, $dummy, $dummy, $return_id, $dummy) = split(/ /, $_);
65 ($dummy, $return_value, $dummy, $key, $dummy, $value, $gs) = split(/'/, $_);
66 $param = -1;
67 } elsif ($_ =~ /info: return_value_param /) {
68 # test.c:11 set_int() info: return_value_param 0 0 '' '*$$' '1' global
69 $type = 1; # PARAM_VALUE
70 ($file_and_line, $func, $dummy, $dummy, $return_id, $param, $dummy) = split(/ /, $_);
71 ($dummy, $return_value, $dummy, $key, $dummy, $value, $gs) = split(/'/, $_);
72 } elsif ($_ =~ /info: return_param_limit /) {
73 # crypto/zlib.c:52 zlib_comp_exit() info: return_param_limit 1 0 '' '$$' '4096-s64max' static
74 $type = 11; # LIMITED_VALUE
75 ($file_and_line, $func, $dummy, $dummy, $return_id, $param, $dummy) = split(/ /, $_);
76 ($dummy, $return_value, $dummy, $key, $dummy, $value, $gs) = split(/'/, $_);
77 } elsif ($_ =~ /info: return_param_filter /) {
78 # crypto/af_alg.c:267 af_alg_accept() info: return_param_filter 3 1 '(-12)' '$$->state' '3' global
79 $type = 13; # FILTER_VALUE
80 ($file_and_line, $func, $dummy, $dummy, $return_id, $param, $dummy) = split(/ /, $_);
81 ($dummy, $return_value, $dummy, $key, $dummy, $value, $gs) = split(/'/, $_);
82 } elsif ($_ =~ /info: return_param_add /) {
83 # crypto/af_alg.c:267 af_alg_accept() info: return_param_add 3 1 '(-12)' '$$->state' '3' global
84 $type = 12; # ADDED_VALUE
85 ($file_and_line, $func, $dummy, $dummy, $return_id, $param, $dummy) = split(/ /, $_);
86 ($dummy, $return_value, $dummy, $key, $dummy, $value, $gs) = split(/'/, $_);
87 } else {
88 next;
91 ($file, $dummy) = split(/:/, $file_and_line);
93 $func =~ s/\(\)//;
94 $return_value =~ s/'//g;
95 $key =~ s/'//g;
96 $value =~ s/'//g;
98 $static = 0;
99 if ($gs =~ /static/) {
100 $static = 1;
103 $db->do("insert into return_states values ('$file', '$func', $return_id, '$return_value', $static, $type, $param, '$key', '$value')\n");
106 $db->commit();
107 $db->disconnect();