Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Change the install name
[simgrid.git] / tools / xbt_exception_checker
1 #! /bin/bash
2
3 # This little script parse a list of C files, and extract the TRY blocks of it.
4 # Martin Quinson, 2006. 
5 # Demerdierensiesich licence.
6
7 # It can reveal usefull when you have a segfault on exception throwing. This
8 # is often the symptom that something somewhere got out of a TRY block with
9 # return, goto, break or such. This is forbiden because some extra cleanups
10 # must be performed at the end of the block.
11
12 # So, if it happens to you, you may find this script usefull: let it extract
13 # all the TRY blocks of your project, and grep for the forbidden keywords
14 # given above.
15
16 # You obviously have to adapt it to your case. The proper solution would be
17 # to accept the extra -I pathes from the command line. 
18 # Patch welcome ;)
19
20 for file in `find -name '*.c'` ; do
21
22 base=`dirname $file`
23 cmd="cat $file \
24       | cpp -I/home/mquinson/CVSIMPORT/gras/gras/include \
25             -I/home/mquinson/CVSIMPORT/gras/gras/src \
26             -I/home/mquinson/CVSIMPORT/gras/gras/src/include \
27             -I$base \
28             -D__XBT_EX_H__ -D_XBT_LOG_H_ \
29       | sed -n -e '/TRY/,/CATCH/p' \
30       | sed -e 's/^.*TRY.*$/----------------/' -e '/CATCH/d'"
31
32 err=`eval $cmd 2>&1 >/dev/null`
33 if [ -n "$err" ] ; then
34   echo "XXXXXXXXXX ERROR IN FILE $file"
35   echo $err
36 fi
37
38 if [ -n "`eval $cmd 2>/dev/null`" ] ; then
39   echo "XXX FILE $file"
40   eval "$cmd" 2>/dev/null
41 fi
42
43 done