title: gdb freezes in malloc
body: <p>Suppose I have some C program like this:</p>
  
  <pre><code>#include &lt;stdlib.h&gt;
  #include &lt;stdbool.h&gt;
  
  int main()
  {
      while (true) {
          void *p = malloc(1000);
          free(p);
      }
      return 0;
  }
  </code></pre>
  
  <p>and I attach to it with <code>gdb</code> like this <code>gdb a.out PID</code>. <code>gdb</code> successfully attaches to it but that I try to do something like <code>call printf("bla bla bla")</code> <code>gdb</code> freezes and if I press <code>Ctrl^C</code> I get this:</p>
  
  <pre><code>(gdb) call printf("bla bla bla")
  ^C
  Program received signal SIGINT, Interrupt.
  __lll_lock_wait_private () at ../nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.S:95
  95  ../nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.S: No such file or directory.
  The program being debugged was signaled while in a function called from GDB.
  GDB remains in the frame where the signal was received.
  To change this behavior use "set unwindonsignal on".
  Evaluation of the expression containing the function
  (malloc) will be abandoned.
  When the function is done executing, GDB will silently stop.
  </code></pre>
  
  <p>I suppose that this happens because my <code>a.out</code> was creating an object and acquired a lock inside <code>malloc.c</code> and in this moment I connected with <code>gdb</code> and tried to create string "bla bla bla" using <code>malloc</code>.</p>
  
  <p>My question is how can I detect that I'm inside <code>malloc.c</code> and let my program finish this execution? I need to do it not inside command line but using some sort of gdb scripting (I only can execute commands inside <code>gdb</code> with <code>-ex</code> option).</p>