Tracing Function Calls in a program

Apart from writing debug and statements in constructors is there any way by which we can trace the function call stack at any depth?

The issue that we always face is that when program crashes (Web Server running on Linux) we have no idea where it crashes and we have to do the hard way of debugging.

Is there any library / extra code that we can include and that can output the function flow in a program given a scenario.

Sorry I tired a lot of programs but without extra debugging (followed by compilation) we are not sure where the code flows. If it gives us the line number that would be more perfect.

Thanks in advance

See if this thread helps - capturing enter and exit of every function.