title: C++ How to identify SIGNAL 11 error location
body: <p>I´m running a multi-threaded C++ program in a Linux system 
  (Kernel 2.6.23). My code is compiled using G++ version 4.7.4.</p>
  
  <p>I added the following code to catch segmentation faults:</p>
  
  <pre><code>void segFaultHandler(int sig)
  {
    void *array[10];
    size_t size;
  
    size = backtrace(array, 10);
    fprintf(stderr, "Error: signal %d:\n", sig);
    backtrace_symbols_fd(array, size, STDERR_FILENO);
    exit(1);
  }
  </code></pre>
  
  <p>And on main:</p>
  
  <pre><code>main()
  {
      signal(SIGSEGV, segFaultHandler);
  
      try {
  
           program code here...
  
      catch(const std::exception&amp; ex)
      {
          std::cerr &lt;&lt; "Error occurred: " &lt;&lt; ex.what() &lt;&lt; std::endl;
      }
      catch(...)
      {
          std::cerr &lt;&lt; "Unknown failure occurred. Possible memory corruption" &lt;&lt; std::endl;
      }
  
      return 0;
  }
  </code></pre>
  
  <p>When running, my program is crashing with the following output:</p>
  
  <pre><code>Error: signal 11:
  /home/cross/bin/aeirtu[0x807406e]
  [0xffffe420]
  /lib/libc.so.6(memcpy+0x2f)[0xb7d9bcbf]
  /usr/gcc-4.7.4/lib/libstdc++.so.6(_ZNSt15basic_streambufIcSt11char_traitsIcEE6xsputnEPKci+0x73)[0xb7f26933]
  </code></pre>
  
  <p>It is not a easy debug as my program crashes only sometimes, so I need a tool to get the crash source and fix it.</p>
  
  <p>From the given output, how can I trace back the function and piece of code that caused the crash ? </p>