js' blog

Finding the origin of an unhandled exception
Created: 23.09.2013 10:09 UTC

As you might have read here before, ObjFW gained support to show backtraces on unhandled exceptions some time ago. This makes it easier to find where an exception was thrown first, as there are a lot of places where exceptions are caught, some cleanup done and then rethrown. Using just gdb, only the place of the last rethrow would be shown in the backtrace, but due to ObjFW generating a backtrace when the exception is created and storing it inside the exception object, it is possible to find out where the exception was created.

However, if you run the application in gdb now, you get ObjFW's nice output of the backtrace from when the exception was created, which contains the addresses and function names, but not the source lines. So this seems like a step forward (getting the place where the exception was created) followed by a step backward (no source line anymore) at first.

But this is not the case. When running an application inside gdb, you can still get the source line, even if the backtrace is outputted by ObjFW and not by gdb. The trick is to use ObjFW to output the backtrace and gdb to resolve an address to a source line. In order to view the source line in gdb, just use list *0xdeadbeef, where 0xdeadbeef is the address as outputted by ObjFW. Notice the * before the address, it is important and may not be omitted.

I hope this explains how you can use ObjFW's ability to output a backtrace in conjunction with gdb to easily find out the source code that created the exception.