0

My function f throws an exception, and my program doesn't handle it. In gdb, I can get the backtrace as following

#0  0x00007ffff722ec59 in raise () from /lib64/libc.so.6
#1  0x00007ffff7230368 in abort () from /lib64/libc.so.6
#2  0x00007ffff7b35f85 in __gnu_cxx::__verbose_terminate_handler() () from /lib64/libstdc++.so.6
#3  0x00007ffff7b33ee6 in ?? () from /lib64/libstdc++.so.6
#4  0x00007ffff7b33f13 in std::terminate() () from /lib64/libstdc++.so.6
#5  0x00007ffff7b3413f in __cxa_throw () from /lib64/libstdc++.so.6
#6  0x00000000004006e6 in g () at x.cc:2
#7  0x00000000004006ef in f () at x.cc:6
#8  0x00000000004006fa in main () at x.cc:10

but if I change it to multithread,

std::thread t(f);
t.join();

Here is the backtrace.

#0  0x00007ffff7011c59 in raise () from /lib64/libc.so.6
#1  0x00007ffff7013368 in abort () from /lib64/libc.so.6
#2  0x00007ffff7b35f85 in __gnu_cxx::__verbose_terminate_handler() () from /lib64/libstdc++.so.6
#3  0x00007ffff7b33ee6 in ?? () from /lib64/libstdc++.so.6
#4  0x00007ffff7b33f13 in std::terminate() () from /lib64/libstdc++.so.6
#5  0x00007ffff7b8a345 in ?? () from /lib64/libstdc++.so.6
#6  0x00007ffff73a2f33 in start_thread () from /lib64/libpthread.so.0
#7  0x00007ffff70d0ead in clone () from /lib64/libc.so.6

Here is the test code:

void g() {
    throw 1;
}

void f() {
    g();
}

int main() {
    f();
    return 0;
}

My tools version are:

GNU gdb (GDB) Fedora 7.6.50.20130731-16.fc20
gcc version 4.8.2 20131212 (Red Hat 4.8.2-7) (GCC)

I compiled it with:

g++ x.cc -o x -ggdb -O0 -pthred -std=c++11

My question is How can I get the full backtrace for case 2?

Barry
  • 286,269
  • 29
  • 621
  • 977
zhihuifan
  • 1,093
  • 2
  • 16
  • 30
  • OP has stated in his question that he has already read the duplicate question and that is different from his hereby. – Unheilig May 20 '15 at 02:32
  • @Barry, Could you remove the "dumplicate" flag? – zhihuifan May 22 '15 at 00:58
  • The question is about getting a backtrace for multuple threads and you have that. If you want to ask about why your functions are getting optimized out, that's a different question. – Barry May 22 '15 at 02:21
  • OK. @barry, I have changed the title. can you remove the duplicated flag? – zhihuifan May 25 '15 at 02:18
  • Dude. Just ask a new question. – Barry May 25 '15 at 03:14
  • @Barry, could you tell me when to "ask a new question" or "edit this question" in this case? I don't think it is deserved to ask a new question while a extreme similar question is here already. Per the stackoverflow's suggestion, either "edit this question" or "ask a new question" is a right way to fix this issue. Thanks – zhihuifan May 25 '15 at 05:11

0 Answers0