#!/usr/bin/perl open(ANALYSED, "analyze_file $ARGV[0] |") || die "Can't analyse $ARGV[0]: $!\n"; @LINES = ; open(INPUT, "$ARGV[0]") || die "Can't open $ARGV[0]: $!\n"; $count = 1; $inset = 0; $infunc = 0; while(){ $temp = $LINES[$inset]; $temp =~ s/,.*//; if($count == $temp){ $inset++; $infunc = 1; } $line = $_; if($infunc == 1){ if(/\{/){ $infunc = 2; } } if($line =~ /\}[^;]/){ $infunc = 0; } if($infunc == 2){ #################### # Really not perfect... #################### if($line =~ /[\(\)]/){$match[0] = 1;} else{$match[0] = 0;} if($line =~ !(/^[ \t]*\w+ \w+[ \t]*=/)){$match[1] = 1;} else{$match[1] = 0;} if($line =~ !(/struct/)){$match[2] = 1;} else{$match[2] = 0;} if($line =~ !(/\\[ \t]*$/)){$match[3] = 1;} else{$match[3] = 0;} if($line =~ !(/ifdef/)){$match[4] = 1;} else{$match[4] = 0;} if($line =~ !(/==/)){$match[5] = 1;} else{$match[5] = 0;} # This rule is a little complicated $temp = $_; $temp =~ s/[^\(\)]//g; if($temp =~ !/^\)/){$match[6] = 1;} else{$match[6] = 0;} if($line =~ /^[ \t]*\/\*/){$match[7] = 1;} else{$match[7] = 0;} if($line =~ /return [^a-zA-Z_].*\(/){$match[8] = 1;} else{$match[8] = 0;} if($line =~ /if[ \t]*\(/){$match[9] = 1;} else{$match[9] = 0;} if($line =~ /kmalloc/){$match[10] = 1;} else{$match[10] = 0;} if($line =~ /for[ \t]*\(/){$match[11] = 1;} else{$match[11] = 0;} if($line =~ /^[ \t]*[^ \t]+[ \t]*=/){$match[12] = 1;} else{$match[12] = 0;} #################### $summary = 0; if($match[0] && $match[1] && $match[2] && $match[3] && $match[4] && $match[5] && $match[6]){$summary = 1;} elsif($match[7]){$summary = 2;} elsif($match[8]){$summary = 3;} elsif($match[9]){$summary = 4;} elsif($match[10]){$summary = 5;} elsif($match[11]){$summary = 6;} elsif($match[12]){$summary = 7;} if($summary > 0){ $infunc = 3; print "\t/* Inserted by functrace [$summary: @match] */\n"; $location = $LINES[$inset - 1]; $location =~ s/.*,//; chomp($location); print "\tprintk(KERN_INFO \"Calling $location\\n\");\n"; print "\t/* End insert */\n\n"; } } print "$line"; $count++; }