title: How can I break on multiple clang/ubsan warnings in gdb?
body: <p>Take the following test program (compiled with clang 3.4 and run under gdb 7.6.1):</p>
  
  <pre><code>#include &lt;limits.h&gt;
  #include &lt;stdio.h&gt;
  
  int main(void)
  {
      int a = INT_MAX + 1;
      int b = INT_MAX + 2;
      printf("Result: a = %d, b = %d\n", a, b);
  }
  </code></pre>
  
  <p>I would like to be able to use gdb to automatically stop at the <strong>second</strong> occurrence of undefined behaviour here (<code>int b = ...</code>).</p>
  
  <p>If I compile with:</p>
  
  <pre><code>clang -fsanitize=undefined -O0 -ggdb3 -o test test.c
  </code></pre>
  
  <p>...then running the program under gdb just results in it running to completion:</p>
  
  <pre><code>test.c:6:21: runtime error: signed integer overflow: 2147483647 + 1 cannot be represented in type 'int'
  test.c:7:21: runtime error: signed integer overflow: 2147483647 + 2 cannot be represented in type 'int'
  Result: a = -2147483648, b = -2147483647
  [Inferior 1 (process 24185) exited normally]
  </code></pre>
  
  <p>But if I use:</p>
  
  <pre><code>clang -fsanitize=undefined-trap -fsanitize-undefined-trap-on-error -O0 -ggdb3 -o test test.c
  </code></pre>
  
  <p>...then I can't continue past the first occurrence:</p>
  
  <pre><code>Program received signal SIGILL, Illegal instruction.
  0x0000000000400556 in main () at test.c:6
  6       int a = INT_MAX + 1;
  (gdb) c
  Continuing.
  
  Program terminated with signal SIGILL, Illegal instruction.
  The program no longer exists.
  </code></pre>
  
  <p>Is it possible to get gdb to break when (and only when) undefined behaviour is flagged, but to let the program continue otherwise? I'm after a technique that will work not just on this example, but in general, where the offending line might be inside a loop, the values may be determined at runtime, etc.</p>