When you are a computer science student doing a practical exam, a can be your worst nightmare, that is if you don't know how to debug it. And with the case of most VTU students the previous statement holds good. This page is dedicated to giving you probably the most primitive method to debug segmentation faults.

The minute you get a segmentation fault. Do as follows
1) Get to shell prompt and type 'ulimit -c unlimited'. This command sets the to an unlimited size. Otherwise this is disabled.

2) Compile your program with the -ggdb option. e.g

cc -ggdb <filename> or c++ -ggdb <filename>

3) Run the program and you will get a message saying 'Segmentation Fault(core dumped)'. If you are using Redhat GNU/Linux or any of its derivatives look for a core file with the name 'core.< process number >' otherwise look for a file called 'core'.

4) Now type the command 'gdb < executable name > < core file name >'. This should start up the GNU debugger gdb. There will be a lot of junk on the screen when all the junk stops coming then there will be the gold. The offending line will be displayed. You can type 'print < variable name >' to look at the contents of the variables.

5) Once you know the contents of the variables you should be in a better position to debug your program.

6) You can type q to exit the debugger.