Why can't mingw + gdb display the backlink correctly from within the sigsegv handler?

I am debugging a process that is very slow when executed from gdb on Windows (mingw32), so I decided to run it until it crashes without gdb, then add a debugger. I have set up a signal handler for sigsegv that shows its pid and waits, so when I see the message, I load gdb and use the "attach" command with that pid. The problem is gdb is showing me a useless line back at this point. Here's an example:

void my_sigsegv_handler(int) {
    std::cerr << "Segmentation fault! pid=" << GetCurrentProcessId();
    std::cin.get(); // wait for gdb
}
int main() {
    signal(SIGSEGV,my_sigsegv_handler);
    int *p = 0;
    std::cout << *p; // boom!
}

      

Compiled with "mingw32-g ++ -g -O0", the output from the gdb "bt" command (after selecting the desired stream):

#0  0x764e73ea in ?? ()
#1  0x7646f489 in ?? ()
#2  0x75edc3b3 in ?? ()
#3  0x75edc2bc in ?? ()
#4  0x75edc472 in ?? ()
#5  0x00415502 in __gnu_cxx::stdio_sync_filebuf<char, std::char_traits<char> >::uflow() ()
#6  0x00434f32 in std::istream::get() ()
#7  0x004016d5 in my_sigsegv_handler () at C:\Users\usuario\zinjai\sin_titulo.cpp:8
#8  0x004010f9 in _gnu_exception_handler (exception_data=0x28fa88) at ../mingwrt-4.0.3-1-mingw32-src/src/libcrt/crt/crt1.c:137
#9  0x76469d57 in ?? ()
#10 0x77100727 in ?? ()
#11 0x770c9d45 in ?? ()
#12 0x00000000 in ?? ()

      

Note that this example does not damage the stack when generating a segfault. In fact, I can debug it anyway just by continuing execution. If I click, enter a signal handler, it goes back to where it was generated (main function) and the problem is not solved, but this time gdb has to catch it. But I would like now how it works.

If I use the same method in gnu / linux I see what I want to see here:

#5  0x00007f6809bf349e in std::istream::get() () from /usr/lib64/libstdc++.so.6
#6  0x00000000004008cd in my_signal_handler () at /home/zaskar/.zinjai/sin_titulo.cpp:6
#7  <signal handler called>
#8  0x00000000004008f9 in main (argc=1, argv=0x7fffa0613108) at /home/zaskar/.zinjai/sin_titulo.cpp:11

      

So the question is, why can't gdb show me the correct backtrace from processing the signal handler? Or what am I doing wrong? Is there a better way to solve it?

+3


source to share





All Articles