title: How to debug programs using signals?
body: <pre><code>#include &lt;stdio.h&gt; 
  #include &lt;signal.h&gt;
  
  static volatile sig_atomic_t being_debugged = 1;
  static void int3_handler(int signo) { being_debugged = 0; }
  
  int main()
  {
          signal(SIGTRAP, int3_handler);
          __asm__ __volatile__("int3");
          if (being_debugged) {
          puts("No, I don't want to serve you.");
                  while (1) {
              /* endless loop */ ;
          }
          }
          puts("Yes, real routines go here.");
          return 0;
  }
  </code></pre>
  
  <p>The above will give different output when run inside/outside gdb,because gdb captures the sigtrap signal.</p>
  
  <p>How to make my program behaves the same in gdb?</p>