title: GNU gdb can not step into template functions (OS X Mavericks)
body: <p>I have installed <code>gdb 7.7</code> (from GNU sources) under OS X Mavericks (10.9.2). I codesigned it, so it works fine whenever I debug a <code>c++</code> file that does not contain templates. However, it is unable to step into template functions (can step into regular functions, but just fails to step into templated ones). When I type <code>step</code> command in a debugging session, it just steps over the function, as if the debugging symbols are not present for the template function. My template function is not even a member function, is just a simple function defined inside the <code>main.cpp</code>.</p>
  
  <p>I compile my program with <code>g++ -g -O0 main.cpp</code> (I use <code>g++4.8.2</code> from <code>macports</code> and not <code>clang++</code>), even tried <code>-fno-inline</code>, still same behaviour, cannot step into template functions. Is this a <code>gdb</code> known problem under OS X Mavericks?  Or, can anyone reproduce the bug?</p>
  
  <p>my code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  template &lt;typename T&gt; // template
  void f(T x)
  {
      std::cout &lt;&lt; "In f:" &lt;&lt; std::endl;
      std::cout &lt;&lt; x &lt;&lt; std::endl;
  }
  
  void g() // non-template
  {
      std::cout &lt;&lt; "It works here!" &lt;&lt; std::endl;
      std::cout &lt;&lt; "Exiting g()..." &lt;&lt; std::endl;
  }
  
  int main() 
  {
      f&lt;double&gt;(12.3); // gdb does not step into f()
      g(); // gdb steps into g()
  }
  </code></pre>
  
  <p>Can not step in <code>f</code> after a breakpoint at <code>f&lt;double&gt;(12.3)</code>.
  If <code>f()</code> is a regular function, such as <code>g()</code> in my code, then it steps into.
  Thanks!</p>
  
  <p>Update: <code>gdb</code> works as it should under any other OS, such as <code>linux/windows/solaris</code>. It seems to be  a problem related to OS X.</p>
  
  <pre><code>Reading symbols from a.out...done.
  (gdb) disassemble main
  Dump of assembler code for function main():
     0x0000000100000d62 &lt;+0&gt;: push   %rbp
     0x0000000100000d63 &lt;+1&gt;: mov    %rsp,%rbp
     0x0000000100000d66 &lt;+4&gt;: movabs $0x402899999999999a,%rax
     0x0000000100000d70 &lt;+14&gt;:    movq   %rax,%xmm0
     0x0000000100000d75 &lt;+19&gt;:    callq  0x100000e44
     0x0000000100000d7a &lt;+24&gt;:    callq  0x100000d0c &lt;g()&gt;
     0x0000000100000d7f &lt;+29&gt;:    mov    $0x0,%eax
     0x0000000100000d84 &lt;+34&gt;:    pop    %rbp
     0x0000000100000d85 &lt;+35&gt;:    retq
  End of assembler dump.
  (gdb)
  </code></pre>
  
  <p>Now we set a breakpoint at the entry of <code>main()</code>  </p>
  
  <pre><code>(gdb) b main
  Breakpoint 1 at 0x100000d66: file src/templated_bug.cpp, line 22.
  (gdb) r
  Starting program: /Users/vlad/template_gdb_bug/a.out
  
  Breakpoint 1, main () at src/templated_bug.cpp:22
  22      f&lt;double&gt;(12.3);
  (gdb) s
  In f:
  12.3
  23      g();
  (gdb) s
  g () at src/templated_bug.cpp:16
  16      cout&lt;&lt;"It works here!"&lt;&lt;endl;
  (gdb) s
  It works here!
  17      cout&lt;&lt;"Exiting g()..."&lt;&lt;endl;
  (gdb) s
  Exiting g()...
  18  }
  (gdb) s
  main () at src/templated_bug.cpp:24
  24  }
  (gdb) s
  [Inferior 1 (process 50945) exited normally]
  (gdb)
  </code></pre>
  
  <p>As you can see, it does not step inside <code>f()</code> but steps inside <code>g()</code>. Moreover,</p>
  
  <pre><code>(gdb) disassemble f
  No symbol "f" in current context.
  </code></pre>
  
  <p>However, for another function <code>g()</code> that is non-template, the symbols are loaded and I can disassemble it.</p>
  
  <pre><code>(gdb) disassemble g
  Dump of assembler code for function g():
     0x0000000100000d0c &lt;+0&gt;: push   %rbp
     0x0000000100000d0d &lt;+1&gt;: mov    %rsp,%rbp
     0x0000000100000d10 &lt;+4&gt;: lea    0x193(%rip),%rsi        # 0x100000eaa
     0x0000000100000d17 &lt;+11&gt;:    mov    0x2ea(%rip),%rax        # 0x100001008
     0x0000000100000d1e &lt;+18&gt;:    mov    %rax,%rdi
     0x0000000100000d21 &lt;+21&gt;:    callq  0x100000e5c
     0x0000000100000d26 &lt;+26&gt;:    mov    0x2e3(%rip),%rdx        # 0x100001010
     0x0000000100000d2d &lt;+33&gt;:    mov    %rdx,%rsi
     0x0000000100000d30 &lt;+36&gt;:    mov    %rax,%rdi
     0x0000000100000d33 &lt;+39&gt;:    callq  0x100000e4a
     0x0000000100000d38 &lt;+44&gt;:    lea    0x17a(%rip),%rsi        # 0x100000eb9
     0x0000000100000d3f &lt;+51&gt;:    mov    0x2c2(%rip),%rax        # 0x100001008
     0x0000000100000d46 &lt;+58&gt;:    mov    %rax,%rdi
     0x0000000100000d49 &lt;+61&gt;:    callq  0x100000e5c
     0x0000000100000d4e &lt;+66&gt;:    mov    0x2bb(%rip),%rdx        # 0x100001010
     0x0000000100000d55 &lt;+73&gt;:    mov    %rdx,%rsi
     0x0000000100000d58 &lt;+76&gt;:    mov    %rax,%rdi
     0x0000000100000d5b &lt;+79&gt;:    callq  0x100000e4a
     0x0000000100000d60 &lt;+84&gt;:    pop    %rbp
     0x0000000100000d61 &lt;+85&gt;:    retq
  End of assembler dump.
  </code></pre>