Build the program with debugging symbols (compile with -g).
Set your limits to allow a coredump file to be created (ulimit -c unlimited).
Run the program and get a core file.
Load the program and core into gdb (gdb <program> <core file>).
Look at the the backtrace (gdb's "where" command).
That's a start. If you have a good IDE with built-in support for debugging, load the program into your IDE, set a breakpoint before where the error occurs and then step through the program.