summaryrefslogtreecommitdiffstats
path: root/tapset/test/ctostp.sh
blob: 132f204c604a51e5f91301f2404d33abe11d2110 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# usage
if [ $# -ne 2 ]; then
   echo -ne " \033[1mUsage:\033[0m ctostp src dest\n"
   echo -ne "   \033[1msrc:\033[0m\n"
   echo -ne "\tthe  source  directory containing  the\n"
   echo -ne "\tC files used to generate the stp files\n" 
   echo -ne "   \033[1mdest:\033[0m\n"
   echo -ne "\tthe   directory  that  will  store the\n"
   echo -ne "\tresulting  stp files\n"
   exit
fi
# strip trailing /
src=` echo $1|sed -e 's/\/$//'`
dest=`echo $2|sed -e 's/\/$//'`
# do some sanity checks
if [ `ls $src/*.c|wc -l` -le 0 ]; then
   echo "ERROR: No C files found in $src"
   exit
fi
if [ ! -d $dest ]; then
   echo "ERROR: $dest does not exist!"
   exit
else
   #clear it out
   rm -f $dest/*
fi
# ctostp
for file in `ls $src/*.c`
do
   while read line
   do
      if [ `echo $line|grep ___________|wc -l` -eq 1 ]
      then
         fn=`basename $file|cut -d"." -f1`
         echo "probe kernel.syscall.$fn {"     >> $dest/$fn.stp
         echo "   if(execname()==\"e_$fn\") {" >> $dest/$fn.stp
      fi
      # ugly? yes. effective? yes.
      if [[ `echo $line|grep dmsg|wc -l` -eq 1
      && `echo $line|grep char|wc -l` -eq 0 ]]; then
         func=`echo $line|cut -d"\"" -f2`
         var=` echo $line|cut -d"\"" -f4`
         if [ `echo $var|grep void|wc -l` -eq 1 ] 
         then
            echo "      log(\"$func: $var = \".sprint(0))"    >> $dest/$fn.stp
         else 
            echo "      log(\"$func: $var = \".sprint($var))" >> $dest/$fn.stp
         fi
      fi
   done < $file
   #close it up
   echo "   }"   >> $dest/$fn.stp
   echo -e "}\n" >> $dest/$fn.stp
done