Sunday, January 24, 2010

Detect 'if' statement

Aim:
1)To compile gcc version 4.4.2,
2)To detect simple 'if-else' statements after reading source file c-parser.c of gcc.
3)Generate exception to handle 'if detection'.
4)Use git commands to point out difference made in newer compiled gcc from existing gcc on system.
To Detect 'if' Statement.

1)WRITE a simple helloworld.c code.

// helloworld.c file contents
#include
FILE *fp;
fp=fopen("/home/swati/temp.txt","w");
fprintf(fp,"\nthis is if detection\n");


2) INCLUDE helloworld.h FILE IN THE SOURCE DIRECTORY
/newgcc/gcc-4.4.2/gcc/.
2.1) Use #include "helloworld.h" in c-parser.c file in this directory.

3) RECOMPILE USING FOLLOWING COMMANDS.
3.1) Change the current directory to 'build' directory.

[swati@localhost ~]$ cd /home/swati/newgcc/objdir/build-i686-pc-linux-gnu/gcc/build/

3.2) Configure with --disable-bootstrap modification.

[swati@localhost build]$ /home/swati/newgcc/gcc-4.4.2/configure --disable-bootstrap--prefix=$insdir

OUTPUT on successful configuration looks like:
configure: creating ./config.status
config.status: creating Makefile

3.3) 'Make' command in BUILD directory will re-make all necessary changes.(.o files created from .c files)

[swati@localhost build]$ make all-gcc


3.4) Select newly configured gcc.

[swati@localhost build]$ export PATH=$insdir/bin/:$PATH

2.5) Compile.

[swati@localhost build]$ gcc /home/swati/hello.c -v
[swati@localhost build]$ ./a.out

OUTPUT on Console:
hello world

OUTPUT of included helloworld.h file:
A new text file temp.txt created in home folder with a newly added line 'this is if detection'.


Hence, 'if' statement is successfully detected ,source code modified and recompiled to reflect the manipulations.
Now, we can proceed to exception generation.




2 comments:

  1. please note that despite the error on make all-gcc command, the changes made in source will reflected successfully. So, any suggestions on error removal?

    ReplyDelete
  2. got rid of the error.. so no bothers..

    ReplyDelete