1 #!/usr/bin/perl -w 2 3 use strict; 4 use DBI; 5 6 my $db_file = shift; 7 if (!$db_file) { 8 print "usage: copy_function_pointers.pl <db file>\n"; 9 exit(0); 10 } 11 12 my $db = DBI->connect("dbi:SQLite:$db_file", "", "", {AutoCommit => 0}); 13 14 my ($select, $function, $ptr); 15 16 $select = $db->prepare('SELECT DISTINCT function, ptr FROM function_ptr WHERE function LIKE "% %";'); 17 18 my %ptrs; 19 20 $select->execute(); 21 while (($function, $ptr) = $select->fetchrow_array()) { 22 $ptrs{"$function"}{'ptr'} = $ptr; 23 $ptrs{"$function"}{'done'} = 0; 24 } 25 26 sub copy_functions($); 27 sub copy_functions($) 28 { 29 my $src = shift; 30 31 if ($ptrs{"$src"}{'done'}) { 32 return; 33 } 34 $ptrs{"$src"}{'done'} = 1; 35 36 my $select = $db->prepare('SELECT distinct file, function FROM function_ptr WHERE ptr = ?;'); 37 my $insert = $db->prepare('INSERT OR IGNORE INTO function_ptr VALUES (?, ?, ?, 1);'); 38 39 $select->execute($src); 40 while (my ($file, $function) = $select->fetchrow_array()) { 41 if ($function =~ / /) { 42 copy_functions($function); 43 next; 44 } 45 46 $insert->execute($file, $function, $ptrs{"$src"}{'ptr'}); 47 } 48 } 49 50 foreach my $key (keys(%ptrs)) { 51 copy_functions($key); 52 } 53 54 $db->commit(); 55 $db->disconnect();