title: How to execute gdb breakpoint commands in batch mode?
body: <p>I'm trying to use <code>gdb</code> non-interactively - i.e. printing something on every specified breakpoint.</p>
  
  <pre><code>$ cat script.gdb
  set pagination off
  catch syscall
  commands
  bt
  c
  end
  # It's a hack to get backtraces only on call not on return - Linux and x86_64 specific.
  # For sake of this question it can be removed, it will just output more.
  condition $bpnum $rax == -38
  </code></pre>
  
  <p>The problem - non-interactive try with batch mode:</p>
  
  <pre><code>$ gdb /bin/true -batch -x script.gdb
  Catchpoint 1 (any syscall)
  Catchpoint 2 (syscall 'fork' [57])
  
  Catchpoint 1 (call to syscall brk), 0x00007ffff7df2f9c in brk () from /lib64/ld-linux-x86-64.so.2
  </code></pre>
  
  <p>However if I would run it interactively:</p>
  
  <pre><code>$ gdb /bin/true -x script.gdb
  GNU gdb (GDB) 8.1
  
  ...
  
  Reading symbols from /bin/true...
  (no debugging symbols found)...done.
  Catchpoint 1 (any syscall)
  Catchpoint 2 (syscall 'fork' [57])
  (gdb) run
  Starting program: /usr/bin/true
  
  Catchpoint 1 (call to syscall brk), 0x00007ffff7df2f9c in brk () from /lib64/ld-linux-x86-64.so.2
  #0  0x00007ffff7df2f9c in brk () from /lib64/ld-linux-x86-64.so.2
  #1  0x00007ffff7df2488 in _dl_sysdep_start () from /lib64/ld-linux-x86-64.so.2
  #2  0x00007ffff7ddcbc1 in _dl_start () from /lib64/ld-linux-x86-64.so.2
  #3  0x00007ffff7ddc178 in _start () from /lib64/ld-linux-x86-64.so.2
  #4  0x0000000000000001 in ?? ()
  #5  0x00007fffffffe2a5 in ?? ()
  #6  0x0000000000000000 in ?? ()
  
  ...
  
  Catchpoint 1 (call to syscall exit_group), 0x00007ffff7ad7529 in _exit () from /lib64/libc.so.6
  #0  0x00007ffff7ad7529 in _exit () from /lib64/libc.so.6
  #1  0x00007ffff7a50a2b in __run_exit_handlers () from /lib64/libc.so.6
  #2  0x00007ffff7a50ab5 in exit () from /lib64/libc.so.6
  #3  0x000000000040132d in ?? ()
  #4  0x00007ffff7a39c05 in __libc_start_main () from /lib64/libc.so.6
  #5  0x0000000000401406 in ?? ()
  [Inferior 1 (process 35434) exited normally]
  (gdb) quit
  </code></pre>
  
  <p>Then it works as intended - breakpoint commands are executed.</p>
  
  <p>Adding additional <code>-ex c</code> to the non-interactive command will just add another line of <code>Catchpoint 1 ...</code>, but still no backtrace.</p>
  
  <p>Man page and <a href="https://sourceware.org/gdb/onlinedocs/gdb/index.html" rel="nofollow noreferrer">Debugging with GDB</a> is not helpful.</p>
  
  <p>I guess that there has to be some command that would just wait until it's over or maybe a setting somewhere like the <code>pagination</code> one.</p>
  
  <p>I know that I could use something akin to an <code>expect</code> script, but I would like to avoid it. Something like this works:</p>
  
  <pre><code>echo 'run
  quit' | gdb /bin/true -x script.gdb
  </code></pre>