title: Displaying each assembly instruction executed in gdb
body: <p>I currently have a tricky bug that occurs in a place where I don't have access to source or symbols, i.e. I can see the instruction and its address where the crash occurs, but that's about it. <strong>What I'd like to do is have <code>gdb</code> run without requiring interaction and display every instruction as it does so</strong>, but I've yet to find a way to do it.</p>
  
  <p>What I'm hoping to achieve is something like this:</p>
  
  <pre><code>(gdb) /* some command */
  0x2818a7c0: push   %ebp
  0x2818a7c1: mov    %esp,%ebp
  0x2818a7c3: push   %ebx
  0x2818a7c4: sub    $0x4,%esp
  ...
  0x28563622: mov    %esi,0x0(%eax)
  Program received signal SIGSEGV, Segmentation fault.
  </code></pre>
  
  <p>What I've been doing is setting up a display for the program counter, like so:</p>
  
  <pre><code>(gdb) display/i $pc
  </code></pre>
  
  <p>And then running through the code with <code>stepi</code>:</p>
  
  <pre><code>(gdb) stepi
  1: x/i $pc  0x2818a7c0: push   %ebp
  </code></pre>
  
  <p>However, the crash is hundreds or thousands of instructions away, and I'd like a way to see each one (together, if preferable), without having to hit "enter" that many times. Also, if I were to do it manually, I'd see a <code>(gdb)</code> prompt between each instruction, which is less than desirable.</p>
  
  <p>One route I've briefly looked into is <a href="http://johnnyjacob.wordpress.com/2009/07/07/gdb-scripting-short-article-for-internal-magazine/" rel="noreferrer">scripting</a>, but my only thought is to setup at <code>main()</code>, have it display and another break (for the next instruction), and then continue, but then I can't use <code>commands</code> within a <code>commands</code> block, so it wouldn't work the way I'm imagining it.</p>
  
  <p>In case it matters, I'm working on FreeBSD.</p>