News:

As usual while waiting for the next release - don't forget to check the nightly builds in the forum.

Main Menu

see content of a vector in debugging

Started by taram, June 07, 2009, 08:02:35 AM

Previous topic - Next topic

taram

hi,

I use c::b (svn 5616)  and in my c::b project I have defined a typdef like this:

typedef vector<string> vstr;

And use it like following:

--------------------------
vstr v;

v.push_back("bla bla");
---------------------------

Everything works fine.

But when I debug, I can not see in the  "Local variabel"  an "understandable" content of the string vector.

When I open the "local watches" I only see "_M_start"  and "_M_finish" etc. with a hex number.




The only thing which is working when I watch a concrete cell of the vector is:


Add watch -->v[0]


then I can see the string of the first element of the string vector.

Is there a way to see all strings of the string vector in the debugger? That would be great.

The "v[0]" (element view) works fine but it would be very convenient to see all strings in the string vector "en block".


Thanks for your help

Martin




O tempora o mores! - Edite, bibite, collegiales, post multa saecula, pocula nulla!

ollydbg

I test your code, found it is even bad in my system(MinGW, WindowsXP), I can't view "v[0]".
See my screenshot


[attachment deleted by admin]
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Jenna

If v[0] works for you, you can try to watch v as array (add it to watch window, edit it and check watch as array).

Jenna

Quote from: ollydbg on June 07, 2009, 08:45:44 AM
I test your code, found it is even bad in my system(MinGW, WindowsXP), I can't view "v[0]".
See my screenshot

You have to use the []-operator in your program, otherwise it gets not compiled in and therefore cannot be used by gdb.

@taram:
watching the variable as array does not work here.

ollydbg

Thanks Jens for your hints.

Here is a workaround.

#include <iostream>
#include <string>
#include <vector>

using namespace std;

typedef vector<string> vstr;

int main()
{
    vstr v;
    v.push_back("bla bla");
    string v0 = v[0];
    cout << "Hello world!" << endl;
    return 0;
}

I can only watch "v0" (see the screen shot)




[attachment deleted by admin]
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

taram

#5
Hi,

first of all, thank all for your help and replies to my question. Sorry for my delayed answer, but I am here in Calgary and -8h behind European time :)

However, here the code which I was using for testing:

#include <iostream>
#include <string>
#include <vector>

using namespace std;

typedef vector<string> vstr;

int main()
{
   vstr v;
   v.push_back("1. bla bla");
   v.push_back("2. bla bla");
   v.push_back("3. bla bla");

   int a[3] ={11, 22, 33};



   for (unsigned int f = 0; f<3; f++)
   {
       cout <<" a[" << f <<"] = " << a[f];
       cout << " and v[" << f << "] = " << v[f] << endl;
   }

   return 0;
}


I played around with "Add watches" and I was not able to get a similar debugger output of a string vector compared to the output of a normal array (see screen-shot-1.png).

The only thing which was working for the string vector was the "element view" i.e. "Add wachtes --> v[0] (see screen-shot-1.png).

But  with this method you have to be very carefully, since if you enter a element which does not exist i.e. out of array range, you will get a "segmentation signal" from Code::Blocks. (see v[3] in "wachtes in screen-shot-1.png and signal in screen-shot-2.png). So for me this "element view" method is not a 100% good way, it is more a 80% provisional solution :)

However, it would be very convenient if the debugger would show the string vector similar like the array (see "a" in watches --> screen-shot-1.png).

Thanks

Martin

PS: @ Jens
special thanks to you for providing debian-repository for Code::Blocks.
I use Debain Lenny, and this is a very convenient way to be up to date with Code::Blocks nightly builds.
Small suggestion for your page http://apt.jenslody.de/ :

instead of this line:

--------------------------------------------------------------------------------------------

...The best and easiest way to add my public-key to apt's trustdb is to install the package jens-lody-debian-keyring with your preferred package-manager or apt-get.  ....

--------------------------------------------------------------------------------------------

write it more explicitly like:

--------------------------------------------------------------------------------------------

... The best and easiest way to add my public-key to apt's trustdb is to install the package jens-lody-debian-keyring with

#apt-get-get install jens-lody-debian-keyring

or

#aptitude  install jens-lody-debian-keyring

--------------------------------------------------------------------------------------------

Since most people do not read a web page they skim it.


[attachment deleted by admin]
O tempora o mores! - Edite, bibite, collegiales, post multa saecula, pocula nulla!

taram

#6
Here screen-shot 2, since max. attachment size is 128kb

Martin

[attachment deleted by admin]
O tempora o mores! - Edite, bibite, collegiales, post multa saecula, pocula nulla!

Jenna

Quote from: taram on June 07, 2009, 10:49:22 PM
However, it would be very convenient if the debugger would show the string vector similar like the array (see "a" in watches --> screen-shot-1.png).
You are right, but that seems to be a gdb issue and a workaround might not be so easy.

Quote from: taram on June 07, 2009, 10:49:22 PM
PS: @ Jens
special thanks to you for providing debian-repository for Code::Blocks.
I use Debain Lenny, and this is a very convenient way to be up to date with Code::Blocks nightly builds.
Small suggestion for your page http://apt.jenslody.de/ :

(Vielen Dank)
Thank you for the suggestion, I just changed my site.

taram

#8
Yes, it may be an GDB issue, but I have less knowledge about it.

However may be in a future nightly build this issue will be solved... may be this issue should be forwarded to a "GDB geek" of the Code::Blocks developer crew.

Cheers

Martin
O tempora o mores! - Edite, bibite, collegiales, post multa saecula, pocula nulla!

taram

#9
may be these links help....

http://www.stanford.edu/~afn/gdb_stl_utils/

http://help.lockergnome.com/linux/GDB-capabilities-exploring-STL-classes--ftopict279673.html

but this is beyond my "doable", since I am a newbe to GBD. hope some of the C::B developers can use this

cheers

Martin
O tempora o mores! - Edite, bibite, collegiales, post multa saecula, pocula nulla!

MortenMacFly

Quote from: taram on June 08, 2009, 02:59:59 AM
Also frisch ans Werk - lets start fresh....
[...]
@ Jens: Schön, daß Du meinen Vorschlag aufgegriffen hast bzgl. Deiner HP. 
Although we do have German admins please do *not* post in German anymore if there is no particular reason. This is and remains an english-only forum. Thanks.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: [url="https://www.codeblocks.org/docs/main_codeblocks_en.html"]https://www.codeblocks.org/docs/main_codeblocks_en.html[/url]
C::B FAQ: [url="https://wiki.codeblocks.org/index.php?title=FAQ"]https://wiki.codeblocks.org/index.php?title=FAQ[/url]

taram

#11
?? I do not understand your concerns?? I know this fact, but there was no additional information in the German sentence and furthermore the translations was given directly behind it.

The other sentence was a thankful personal note to jens.

Further the complete discussion about the problem was/is done in English. If it would be done in German you would be right.

However, it was not my intention to disregard the forum rules, so I modified my entries above.

Cheers

Martin  
O tempora o mores! - Edite, bibite, collegiales, post multa saecula, pocula nulla!

rcoll

Quote from: taram on June 08, 2009, 02:59:59 AM
Yes, it may be an GDB issue, but I have less knowledge about it.

However may be in a future nightly build this issue will be solved... may be this issue should be forwarded to a "GDB geek" of the Code::Blocks developer crew.

Cheers

Martin


No, I doubt it.  The GDB geeks are another group of geeks entirely.  The geeks who develope C::B only use GCC, they don't develope it.  In short, your problem is strictly a GDB problem, not a C::B problem.

I noticed that you never mentioned which version of GCC (and therefore GDB) you are using.  It may be that a newer version has the features you need.

Ringo

taram

thx ringo for your input. I use

- gcc version 4.3.2 (Debian 4.3.2-1.1,Target: i486-linux-gnu)   -- by $gcc -v

- GNU gdb 6.8-debian (This GDB was configured as "i486-linux-gnu".) -- by $gdb -v

I will try to find a deb package for debian lenny and then  update to GCC 4.3.3
   
http://gcc.gnu.org/gcc-4.3/

may be this solve the problem

cheers

Martin




O tempora o mores! - Edite, bibite, collegiales, post multa saecula, pocula nulla!

ollydbg

#14
Quote from: jens on June 07, 2009, 10:12:13 AM
You have to use the []-operator in your program, otherwise it gets not compiled in and therefore cannot be used by gdb.
Hi, Jens. Thanks for the reply.
I understand now. (Oh, My poor English, I need to read twice of these sentence to understand it's meaning :()
If I define v[0], then gdb can also understand v[1].  :D


#include <iostream>
#include <string>
#include <vector>

using namespace std;

typedef vector<string> vstr;

int main()
{
   vstr v;
   v.push_back("bla bla");
   v.push_back("abcdef");

   string v0 = v[0];
   cout << "Hello world!" << endl;
   return 0;
}


See my screen shot.

Edit:
Oh, taram has already mentioned that.

Edit2
If I just add "v" to "watch", then check on the "Watch as array" opiotion. I still can't view any contents. Seems GDB didn't regard "v" as an array beginning address.
We can only use "v[0], v[1]" instead. :D





[attachment deleted by admin]
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.