Transition to template classes using GDB

I am working on implementing a balanced tree in C ++, but the requirement of the assignment is that I have to use template classes. At first I thought about how to do this with ints, and then convert it to templates, but for the test code that is provided to us, templates are used by default.

When I compile my code with g ++ class.h test.cxx -Wall -g -O0, everything works fine until I go to gdb where it will not be part of the template implementation. My template implementation file is included at the end of the header file, and gdb will let me set breakpoints in it, but it never comes into function. I used gdb through emacs, but it did not work directly in gdb. I would expect this step to switch to the template file when GDB gets to the function that is implanted, but instead it tells me that the line it thinks should go to does not actually exist. Here is a typical session:

(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<int>::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) 

I saw several posts on the Internet about other people who faced similar problems, but the threads all died without permission. I tried several ways to compile the code, including in separate parts, and then put it all together, but not in cubes. Everyone else in my class has the same problem, but he is pleased to use cout instructions for debugging, which is very slow to debug 10 functions that call each other. Has anyone else experienced this and found a solution?

+4
source share
1 answer

The problem is this: gdb on the platform you use for debugging cannot find the line set.template for your set.template file. For example, debugging characters seem to indicate the correct line number:

 (gdb) break set.template:7 Breakpoint 3 at 0x400c46: file set.template, line 7. 

But then you get an error message that

 Line number 7 out of range; set.template has 1 lines. 

So, gdb sees your set.template file, but cannot parse it correctly and see line set.template to actually tell what line number to look at. This can happen, for example, if you wrote a file on Linux and then compiled it on Windows. For Linux / Unix, only a line for a new line is required, where, since Windows requires a carriage return + straight line combination. Therefore, open the set.template file in a text editor on the platform on which you are debugging, and make sure that your file is not single-line. There may be other reasons why gdb is suffocating in the lines of your file, but this inability to see the end of the line in your actual code file is mainly the cause of your problems and has nothing to do with the inability to debug templates ... gdb can fine-tune templates .

+3
source

Source: https://habr.com/ru/post/1382123/


All Articles