title: gdb Breakpoint on assert on in multithreaded C program
body: <p>I'm using <code>assert</code> from <code>&lt;cassert&gt;</code> to check invariants in my multithreaded C++11 program. When the assertion fails, I'd like to be able to inspect the state of the failing function, along with still-intact backtrace, variable state, etc. at the time of the failed assertion. The issue seems be some interaction between <code>SIGABRT</code> and my threads, as my <code>std::thread</code>s are <code>pthread_kill</code>ed, presumably by some default signal handler. How can I pause gdb right at the time of the failed assertion?</p>
  
  <p>Here are some things I've tried:</p>
  
  <ol>
  <li><p>set a catchpoint on <code>SIGABRT</code>. This catch does occur, but it's too late (in <code>__pthread_kill</code>).</p></li>
  <li><p>defined <code>__assert_fail</code>, which is <code>extern</code> declared in <code>&lt;assert.h&gt;</code>, and set a gdb breakpoint on it. This is never caught so presumably the pthread is being killed before this is called (?).</p></li>
  </ol>
  
  <p>What's the recommended approach here?</p>