5 use Scalar
::Util
qw(looks_like_number);
9 print "usage: $0 <project> <smatch_warns.txt> <db_file>\n";
14 sub get_too_common_functions
($$$)
20 open(FUNCS
, "grep 'SQL_caller_info: ' $warns | grep '%call_marker%' | cut -d \"'\" -f 6 | sort | uniq -c | ");
23 if ($_ =~ /(\d+) (.*)/) {
25 $too_common_funcs{$2} = 1;
32 open(FILE
, "$path/../$project.common_functions");
35 $too_common_funcs{$_} = 1;
39 open(FILE
, ">", "$path/../$project.common_functions");
40 foreach my $func (keys %too_common_funcs) {
50 my $path = $exec_name;
51 $path =~ s/(.*)\/.*/$1/;
56 if (!defined($db_file)) {
60 get_too_common_functions
($path, $project, $warns);
62 my $db = DBI
->connect("dbi:SQLite:$db_file", "", "", {AutoCommit
=> 0});
63 $db->do("PRAGMA cache_size = 800000");
64 $db->do("PRAGMA journal_mode = OFF");
65 $db->do("PRAGMA count_changes = OFF");
66 $db->do("PRAGMA temp_store = MEMORY");
67 $db->do("PRAGMA locking = EXCLUSIVE");
69 foreach my $func (keys %too_common_funcs) {
70 $db->do("insert into common_caller_info values ('unknown', 'too common', '$func', 0, 0, 0, -1, '', '');");
74 my ($fn, $dummy, $sql);
76 open(WARNS
, "<$warns");
78 # test.c:11 frob() SQL_caller_info: insert into caller_info values ('test.c', 'frob', '__smatch_buf_size', %CALL_ID%, 1, 0, -1, '', ');
80 if (!($_ =~ /^.*? \w+\(\) SQL_caller_info: /)) {
83 ($dummy, $dummy, $dummy, $dummy, $dummy, $fn, $dummy) = split(/'/);
85 if ($fn =~ /__builtin_/) {
88 if ($fn =~ /^(printk|memset|memcpy|kfree|printf|dev_err|writel)$/) {
92 ($dummy, $dummy, $sql) = split(/:/, $_, 3);
94 if ($sql =~ /%call_marker%/) {
95 $sql =~ s/%call_marker%//; # don't need this taking space in the db.
98 $sql =~ s/%CALL_ID%/$call_id/;