js' blog

Created: 11.06.2013 23:05 UTC

As I already wrote in the edit of the previous blog entry, __builtin_return_address() will crash on many platforms under certain conditions. As a result, it was disabled on all architectures except PPC (this was the only one that seemed to work reliable with it) and backtrace() was used instead if available. However, backtrace() seems to be only available on systems with glibc and OS X.

Today, I stumbled upon _Unwind_Backtrace(), which is part of libgcc_eh. The disadvantage of this function is that it only works if unwind tables exist and has no fallback like backtrace() does. However, as ObjFW code always has unwind tables since it uses exceptions, this is no problem at all and the ideal solution: It is available on all systems that support ObjFW (because we already need the other _Unwind_* functions for exceptions, it does not work without libgcc_eh or an ABI-compatible replacement lib anyway).

I just implemented backtraces using _Unwind_Backtrace() in ObjFW and removed the code for __builtin_return_address() and backtrace(), as those have no advantage anymore. This means that backtraces are now available on all platforms supported by ObjFW and shown when an exception is not caught!