(assuming you are asking how to do this in gdb)
In gdb, backtrace (or bt) is the command you want to use after you encounter an error. It will print full stack trace.
After that you can use "frame" and various "info" commands to switch frames and examine things.