It depends on the platform, and also depends on how you compile the code. If you compile code with gcc using -fomit-frame-pointer , it is very difficult to get useful backtracking, which usually requires heuristics. If you use any libraries that use this flag, you will also encounter problems - it is often used for highly optimized libraries (for example, the nVidia OpenGL libraries).
This is not a standalone solution, as it is part of a larger engine, but the code is useful:
This includes backtracing with a frame pointer with gcc when it is available, and heuristic backtracking when it is not; this may tend to give false entries in the trace, but to get a countdown for a crash report, this is much better than losing the entire trace.
In other directories that you would like to pay attention to use a different code (character search, signal processing); these links are a good starting point.
Glenn maynard
source share