Have you ever compile a c or c++ program using cc or gcc compiler.Then sometimes you might stuck up with segmentation faults.
Segmentation faults occurs when the program refers to an unallocated memory space.
By default the compiler wont show by which instruction the segmentation fault occurs.So you have to go through your entire program to find the culprit.
It is tough to fix a bug even without its line number.
Here is the simple solution to find segmentation faults,
1.Compile the program with “g” flag.
Eg: cc -g filename.c
2.Type gdb a.out
3.It ll take you to the gdb prompt.
5.Give your input values.
6.When there is a segmentation fault the program will stop there.
7.You can see the instruction which causes the segmentation fault.
8.Type “backtrace” without quotes to trace back the segmentation fault.It ll show a number a frames
which are all the reason for segmentation fault.
9.Type “frame frameno” without quotes (to check a particular instruction).
10.There you can find the values of variables by “print variablename” command.
thats all friends,No more worries about segmentation fault.