Debugging a C program that crashes
 

A C program that crashes will offer no information about the error:

 #include <stdio.h>

 int main(int argc, char *argv[])                 
 {
   int a[10];
   int i = -872625577;

   a[i] = 1234;
   printf("i = %d\n", i);
   printf("a[i] = %d\n", a[i]);
 }
 

DEMO:   /home/cs255001/demo/tmp/demo.c

How to find the crash location in a C program
 

  • Compile (all) your C program files using the debug (-g) option:

         gcc   -g   Cprog.c        
      

  • Run the executable using a debugger (e.g.: gdb):

         gdb  a.out        
         (gdb) run
      

DEMO:   /home/cs255001/demo/tmp/demo.c

Learn more about GDB
 

Online resource to learn GDB: