User forums > Help

Debugging into <vector> with GDB?

(1/2) > >>

MortenMacFly:
Dear community,

I cannot figure out how to debug into a STL vector so I am asking for help by this post.
I am using the STL vector in a project and during runtime I'd like to inspect the values inside the vector. Hence the only thing I can see in the debugging window is something like:

Value of v: {<_Vector_base<double,std::allocator<double> >> = {
_M_impl = {<allocator<double>> = {<new_allocator<double>> = {<No data fields>}, <No data fields>}, _M_start = 0x3e2cf8, _M_finish = 0x3e2d10, _M_end_of_storage = 0x3e2d18}}, <No data fields>}

but no values. I tried different things but I don't know how to actually display the values of the vector. Can somebody help? Here is a short code-snippet to give a try:

--- Code: ---#include <iostream>
#include <vector>

int main()
{
  std::vector<double> v;

  v.push_back(1.1); v.push_back(2.2); v.push_back(3.3);

  for (unsigned int i=0; i<v.size(); i++)
    std::cout << "| " << v.at(i) << " |" << std::endl;

  return 0;
}

--- End code ---

I must admit that until now I have used DDD for debugging my code and I am using the C::B GDB plugin just for a short time so there might be a very simple answer... (I hope so)...?!

Thanks, Morten.

Urxae:

--- Quote from: MortenMacFly on November 06, 2005, 02:02:01 pm ---Value of v: {<_Vector_base<double,std::allocator<double> >> = {
_M_impl = {<allocator<double>> = {<new_allocator<double>> = {<No data fields>}, <No data fields>}, _M_start = 0x3e2cf8, _M_finish = 0x3e2d10, _M_end_of_storage = 0x3e2d18}}, <No data fields>}

but no values. I tried different things but I don't know how to actually display the values of the vector. Can somebody help?

--- End quote ---

The values are at *_M_start up to (but not including) *_M_finish (so you can basically consider _M_start to be v.begin(), and _M_start to be v.end()).
You should be able to add watches to those addresses, but I'm not sure if there's a way to view the entire array of them in a single watch.

MortenMacFly:

--- Quote from: Urxae on November 06, 2005, 04:09:51 pm ---The values are at *_M_start up to (but not including) *_M_finish
You should be able to add watches to those addresses [...]

--- End quote ---
Thanks, that helps (so far). So it seems that DDD recurses into each element and presents the list of collected values afterwards. It would be nice if one could save "GDB scripts" in the GDB plugin to allow something similar...

Morten.

Urxae:

--- Quote from: MortenMacFly on November 07, 2005, 02:33:40 pm ---It would be nice if one could save "GDB scripts" in the GDB plugin to allow something similar...

--- End quote ---

Sounds like a good feature request to me 8).

Though it might be a bit complicated, depending on how advanced you'd like those scripts to be.

MortenMacFly:

--- Quote from: Urxae on November 07, 2005, 03:12:41 pm ---Sounds like a good feature request to me 8).

--- End quote ---
I am going to think about that ones I figured out some principles of using the GDB without DDD... :lol:

I just gave it a try and unfortunately I am still unable to inspect the value. The problem is that it seems one can only add variables (existing names) to the GDB watches. What I want is the content of an address (the vector address) which is of cause type-specific. I also tried to send direct commands to the Debugger to see the content of the memory but I don't know, how. To close the "Send command to GDB" window after an command has been input is also quite annoying because I guess the default is that you want to send multiple commands (sounds like another feature request).

Could someone give me a simply step-by-step instruction how to obtain the values? I downloaded the >300 pages manual for GDB but couldn't find the command I am looking for... Help! :cry:

Morten.

Navigation

[0] Message Index

[#] Next page

Go to full version