Hi there,
I believe that this is a problem a few people have run into and maybe there has been some discussion about this already. If yes, please point me to the appropriate thread...
In my (and my students) programs STL classes are extensively used, mostly std::string, std::vector, std::list and std::map. Debugging source code with CodeBlocks works so far only satisfactorily for std::string, and that only for simply showing the content. From the perspective of a user (e.g. imagine a student learning C++), it would be nice to have some more features, as outlined below.
As G++ doesn't compile inlined template functions unless they are used, I created a header file for my students, that includes a class like this:
class _STLDebugHelper {
public:
_STLDebugHelper() {
std::vector<double> d;
d.size(); d.front(); d.back();
d.push_back(10); d[0] = 2; d.at(0) = 2;
d.begin(); d.end();
std::vector<double>::iterator it;
++it; it++; --it; it--;*it;
// ... same for other STL classes
}
} __STLDebugHelper;
By including the header (in only one of the implementation files) at least the typical STL container functions are available through the debugger.
However, when it comes to displaying and evaluating variables using the debugger and the UI, there are still some features that would be quite helpful:
- local watches of STL container types should be collapsed when first shown in the debugger (try debugging a program with 10 locally declared STL classes or a class with 20 stl type member variables... you need a few minutes just to get an overview of what you are actually looking at)
- locally watched std::string types should show the content like it is done when manually adding a watch for a variable of type std::string
- watching ranges of elements in std::vector in the style of vector[15] - 10 elements = [0, 1, 2, 3, 4, 5, 6, 7, 2,3] should be possible
I believe that these features are rather UI features than something to be directly implemented into GDB. Now, does somebody actively work on enhancing debugging features/display in CodeBlocks? If nobody has the time to look into that, I could maybe help enhancing the debugging capabilities of CodeBlocks, but I would appreciate some help for where to get started (basically some info on which class does the GDB parsing, and how and where the debugging treeview is updated). Also watched variables may need additional properties, such as the number of elements to display (in the case of the std::vector).
Thanks a lot in advance for any improvements regarding the debugger, since I believe it is a very important tool for students and active programmers alike.
Andreas Nicolai
After some testing I could compose a "safe" GDB command to evaluate a std::vector:
p (vec._M_impl._M_start == vec._M_impl._M_end_of_storage) ? "<empty>" : ((start+count) < (vec._M_impl._M_end_of_storage - vec._M_impl._M_start)) ? vec._M_impl._M_start@count : "<index out of range>"
This, however, returns either one of the error strings or the content of the vector range in hex, so one of the following:
"<empty>"
"<index out of range>"
{0x3e4f58, 0x3e5f00, 0x3e5f58, 0x3e5f70, 0x3e6f18, 0x3e6f18, 0x3eae20, 0x3ebdc8, 0x3ebdc8, 0x3e6f30}
regardless of the actual type of the vector (the example above was obtained from a vector<double>).
Using
p /f ...
I will get the content of the vector<double> correctly, but the strings are converted to numbers :-( So, the parsing and conversion of each type would have to be done either in Parse_StlVector or in the CodeBlocks GUI.
Any suggestion about how to do this best?
Btw, the option of floating point format for the watched expression is missing: "Decimal" is misleading (should be "Signed" or "Integer") and "Floating point" should be added.
Bye,
Andreas
hey,
sorry for waking this thread up, but I am wondering what is the status of the proposed solutions for debugging stl!
What I get when I try to watch a string and a vector of this sort
vector<int> bla;
bla.push_back(1);
bla.push_back(2);
bla.push_back(3);
bla.push_back(4);
bla.push_back(5);
string blob="Hello World";
is something like...
[img=http://img231.imageshack.us/img231/5286/debugoutput.png] (http://img231.imageshack.us/my.php?image=debugoutput.png)
what's all this stuff about anyway? shouldn't be something pretty much simpler than this?
Regards
Andre