xref: /illumos-gate/usr/src/tools/smatch/src/smatch_data/db/mark_function_ptrs_searchable.pl (revision 2a8bcb4efb45d99ac41c94a75c396b362c414f7f)
1#!/usr/bin/perl -w
2
3use strict;
4use warnings;
5use bigint;
6use DBI;
7use Data::Dumper;
8
9my $db_file = shift;
10my $db = DBI->connect("dbi:SQLite:$db_file", "", "", {AutoCommit => 0});
11
12$db->do("PRAGMA cache_size = 800000");
13$db->do("PRAGMA journal_mode = OFF");
14$db->do("PRAGMA count_changes = OFF");
15$db->do("PRAGMA temp_store = MEMORY");
16$db->do("PRAGMA locking = EXCLUSIVE");
17
18my ($update, $sth, $fn_ptr, $ptr_to_ptr, $count);
19
20$update = $db->prepare_cached('UPDATE function_ptr set searchable = 1 where ptr = ?');
21$sth = $db->prepare('select distinct(ptr) from function_ptr;');
22$sth->execute();
23
24while ($fn_ptr = $sth->fetchrow_array()) {
25    $count = $db->selectrow_array("select count(*) from return_states join function_ptr where return_states.function == function_ptr.function and ptr = '$fn_ptr';");
26    # if there are too many states then bail
27    if ($count > 1000) {
28        next;
29    }
30    # if there are no states at all then don't bother recording
31    if ($count == 0) {
32        next;
33    }
34
35    $update->execute($fn_ptr);
36}
37
38$db->commit();
39$db->disconnect();
40