title: How to print every executed line in GDB automatically until a given breakpoint is reached?
body: <p>I would like to be able to set a breakpoint in GDB, and have it run to that point - and in the process, print out lines it has "stepped through".</p>
  
  <p>Here is an example, based on this simple file with a <code>main</code> and a function, and two breakpoints for each: </p>
  
  <pre><code>$ cat &gt; test.c &lt;&lt;EOF
  #include "stdio.h"
  
  int count=0;
  
  void doFunction(void) {
    // two steps forward
    count += 2;
    // one step back
    count--;
  }
  
  int main(void) {
    // some pointless init commands;
    count = 1;
    count += 2;
    count = 0;
    //main loop
    while(1) {
      doFunction();
      printf("%d\n", count);
    }
  }
  EOF
  
  $ gcc -g -Wall test.c -o test.exe
  $ chmod +x test.exe
  $ gdb -se test.exe
  ...
  Reading symbols from /path/to/test.exe...done.
  (gdb) b main
  Breakpoint 1 at 0x80483ec: file test.c, line 14.
  (gdb) b doFunction
  Breakpoint 2 at 0x80483c7: file test.c, line 7.
  </code></pre>
  
  <p>To start the session, I need to run (<code>r</code>) the program, which will then stop at first breakpoint (<code>main</code>):</p>
  
  <pre><code>(gdb) r
  Starting program: /path/to/test.exe 
  
  Breakpoint 1, main () at test.c:14
  14    count = 1;
  (gdb) 
  </code></pre>
  
  <p>At this point - I can, for instance, hit continue (<code>c</code>); and the process will run through, not outputing anything, and break at the requested line: </p>
  
  <pre><code>(gdb) c
  Continuing.
  
  Breakpoint 2, doFunction () at test.c:7
  7     count += 2;
  (gdb)
  </code></pre>
  
  <p>On the other hand, instead of continue - I can go line by line, either by using step (<code>s</code>) or next (<code>n</code>); for instance:</p>
  
  <pre><code>14    count = 1;
  (gdb) n
  15    count += 2;
  (gdb) s
  16    count = 0;
  (gdb) s
  19      doFunction();
  (gdb) s
  
  Breakpoint 2, doFunction () at test.c:7
  7     count += 2;
  (gdb) s
  9     count--;
  (gdb) s
  10  }
  (gdb) s
  main () at test.c:20
  20      printf("%d\n", count);
  (gdb) s
  ...
  (gdb) s
  _IO_vfprintf_internal (s=Cannot access memory at address 0xe5853361
  ) at vfprintf.c:210
  210 vfprintf.c: No such file or directory.
      in vfprintf.c
  (gdb) s
  245 in vfprintf.c
  (gdb) s
  210 in vfprintf.c
  (gdb) n
  245 in vfprintf.c
  ...
  (gdb) n
  2006    in vfprintf.c
  (gdb) n
  __printf (format=0x80484f0 "%d\n") at printf.c:39
  39  printf.c: No such file or directory.
      in printf.c
  (gdb) n
  main () at test.c:21
  21    }
  (gdb) n
  19      doFunction();
  (gdb) n
  
  Breakpoint 2, doFunction () at test.c:7
  7     count += 2;
  (gdb) 
  </code></pre>
  
  <p>Anyways, I am aware that I can keep <kbd>Enter</kbd> pressed, and the last entered command (step or next) will repeat (<em>left a bit longer session in the second case, to show that 'next' remains on same level, 'step' steps inside the functions being called</em>). However, as it can be seen, depending on whether step or next runs, it may take a while until a result is reached - and so, I don't want to sit for 10 minutes with my hand stuck on the Enter button :) </p>
  
  <p>So, my question is - can I somehow instruct <code>gdb</code> to run to 'breakpoint 2' without further user intervention - while printing out the lines it goes through, as if step (or next) was pressed?</p>