title: Stepping into template classes with GDB
body: <p>I'm working on implementing a balanced tree in c++, but the requirement of the assignment is that I have to use template classes. I thought of doing it with ints first and then converting to templates, but the test code we are given use templates by default. </p>
  
  <p>When I compile my code with g++ class.h test.cxx -Wall -g -O0 everything seems to work fine until I get into gdb where it won't step into the template implementation. My template implementation file is included at the end of the header file, and gdb will allow me to set break points within it, but it never actually steps into the function. I've been using gdb through emacs, but it didn't work directly in gdb either. I would expect that step switches over to the template file when GDB gets to a function that is implimented there, but instead it tell's me that the line it thinks it should go to doesn't really exist. Here is a typical session:</p>
  
  <pre><code>(gdb) break set.template:7
  Breakpoint 3 at 0x400c46: file set.template, line 7.
  (gdb) run
  The program being debugged has been started already.
  Start it from the beginning? (y or n) y
  Starting program: /home/students/jeffris/csci2270/btree/debug
  
  Breakpoint 1, main () at debug.cxx:9
  (gdb) step
  
  Breakpoint 3, set (this=0x7fffffffe550) at set.template:7
  Line number 7 out of range; set.template has 1 lines.
  (gdb) 
  set()
  Line number 8 out of range; set.template has 1 lines.
  (gdb)  
  Line number 9 out of range; set.template has 1 lines.
  (gdb) 
  Line number 10 out of range; set.template has 1 lines.
  (gdb) 
  main () at debug.cxx:10
  (gdb) 
  main_savitch_11::set&lt;int&gt;::empty (this=0x7fffffffe550) at set.template:70
  Line number 70 out of range; set.template has 1 lines.
  (gdb) 
  empty
  Line number 71 out of range; set.template has 1 lines.
  (gdb)  
  Line number 72 out of range; set.template has 1 lines.
  (gdb) 
  </code></pre>
  
  <p>I've seen several posts around the web of other people having similar trouble but the threads all died off without resolution. I've tried a several ways of compiling the code including in individual pieces and then linking it all together, but no dice. Everyone else in my class has the same problem but has contented themselves using cout statements to debug which is very slow going way to debug with 10 functions calling each other. Has anyone else experienced this and found a resolution? </p>