http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55917



             Bug #: 55917

           Summary: Impossible to find/debug unhandled exceptions in an

                    std::thread

    Classification: Unclassified

           Product: gcc

           Version: 4.7.2

            Status: UNCONFIRMED

          Severity: normal

          Priority: P3

         Component: libstdc++

        AssignedTo: unassig...@gcc.gnu.org

        ReportedBy: tob...@ringis.se





If an unhandled exception occurs in an std::thread, the stack is unwound before

std::terminate is called, which makes it impossible to find the location of the

exception.



I emailed gcc-help about this about a year ago, and learned that a fix was

supposed to be applied for 4.7, but that fix didn't work out. Here's my post:



  http://gcc.gnu.org/ml/gcc-help/2011-11/msg00140.html



The reason for the unwound stack is that libstdc++'s function that calls the

user's thread function contains a try/catch all statement.  The supposed fix

was to use noexcept on the internal thread main function, and the reason why it

did not work out is described here:



  http://gcc.gnu.org/ml/gcc-help/2013-01/msg00068.html



I've tested 4.6, 4.7 and a 4.8 snapshot with identical results.  See the

attached test program tmp4.cpp. Compile with:



  g++ -std=c++0x -g tmp4.cpp -lpthread



Run in gdb:



~> gdb a.out

[...]

(gdb) r

Starting program: /home/tobias/a.out 

[Thread debugging using libthread_db enabled]

Using host libthread_db library "/lib64/libthread_db.so.1".

[New Thread 0x7ffff7fd0700 (LWP 10278)]

terminate called after throwing an instance of 'std::runtime_error'

  what():  foo



Program received signal SIGABRT, Aborted.

[Switching to Thread 0x7ffff7fd0700 (LWP 10278)]

0x000000318f036285 in raise () from /lib64/libc.so.6

Missing separate debuginfos, use: debuginfo-install

glibc-2.14.90-24.fc16.9.x86_64 libgcc-4.6.3-2.fc16.x86_64

libstdc++-4.6.3-2.fc16.x86_64

(gdb) bt

#0  0x000000318f036285 in raise () from /lib64/libc.so.6

#1  0x000000318f037b9b in abort () from /lib64/libc.so.6

#2  0x00000031964bbc5d in __gnu_cxx::__verbose_terminate_handler() ()

   from /usr/lib64/libstdc++.so.6

#3  0x00000031964b9e16 in ?? () from /usr/lib64/libstdc++.so.6

#4  0x00000031964b9e43 in std::terminate() () from /usr/lib64/libstdc++.so.6

#5  0x0000003196470b0b in ?? () from /usr/lib64/libstdc++.so.6

#6  0x000000318fc07d90 in start_thread () from /lib64/libpthread.so.0

#7  0x000000318f0f119d in clone () from /lib64/libc.so.6

(gdb) 



As you can see, neither the thread's main function, nor foo() is in the

backtrace.

Reply via email to