3 # This script helps finding the origin of unhandled exceptions in the
4 # unit tests. The unit test framework will tell, that an exception has
5 # been caught by the test driver but will not tell, where in the code
8 # This script will run the .test.bin test driver within gdb and will
9 # create a backtrace for every exception caught by the test driver.
11 # NOTE: This works by setting a breakpoint in the std::exception
12 # constructor. This is, where the backtrace is created from. If you do
13 # some funky manipulations with your exceptions, the backtrace might
14 # not point to the throw statement, however this is very unusual. Of
15 # course, this only works, if all your exceptions are derived from
16 # std::exception but that should always be the case.
18 trap 'rm -f .run-test-gdb.cmd' 0 1 2 15
20 # This gdb script will set the breakpoint and will then run the test
21 # driver. Whenever the execution stops, it will print a backtrace and
22 # will then continue execution. This will produce superflous
23 # backtraces for exceptions which are handled correctly. These will be
25 cat >.run-test-gdb.cmd <<EOF
26 break std::exception::exception()
27 run --build_info=yes --log_level=test_suite
34 # The perl script will filter out exceptions which are handled
35 # correctly (cought before the reach the unit test driver). It will
36 # also truncate the backtrace at the first stackframe within the unit
37 # test subsystem since we are only interested in the user code.
38 gdb -batch -x .run-test-gdb.cmd ./.test.bin 2>&1 | perl -e '
50 if (/^(Breakpoint 1, exception|Program received signal )/) {
62 $l[$#l] .= $_ if @l && /^ /;
63 } elsif (/^(Current language: auto;|\[Switching to Thread)/) {
67 if (/: fatal error in /) {
70 last if /^#[0-9]+ +0x[0-9a-f]+ in boost::unit_test::ut_detail::invoker/;
72 unless (/at \/usr\/lib\/gcc\//) {
77 print unless /in \?\?/;
78 $silent=1 if /__gnu_debug::/;