Author Topic: Debugging vectors with GDB  (Read 5224 times)

Danikar

  • Guest
Debugging vectors with GDB
« on: August 30, 2008, 02:11:56 am »
I am trying to debug so code where I want to see the values that are contained in a particular vector while I am stepping through the code. However, when I set a watch on a vector variable it gives me memory addresses and etc, but the the values.

Is there a way to view the contents of the vector in the watch window? Or is there any way at all? Thanks.

I am migrating from VS2005. Finally decided I wanted a IDE that could use on any OS that I am using. =)

Thanks in advanced for any help, it is greatly appreciated.

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2778
Re: Debugging vectors with GDB
« Reply #1 on: August 30, 2008, 04:20:17 pm »
At the lowest level you could enter a gdb command like:
"p *array-variable@length"

See: http://www.yolinux.com/TUTORIALS/GDB-Commands.html
 containing a useful example of a "print vector" gdbinit script.
 
or write a CB script to do it for you. Search on: "script" in
http://wiki.codeblocks.org/index.php?title=Special:Allpages
All articles - CodeBlocks

Example debugger scripts are in SVN trunk/src/scripts
http://svn.berlios.de/wsvn/codeblocks/trunk/src/scripts/gdb_types.script?rev=5200&sc=1

Wiki:
http://wiki.codeblocks.org/index.php?title=Debugger_scripts
Debugg
« Last Edit: August 30, 2008, 04:27:34 pm by Pecan »

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5491
Re: Debugging vectors with GDB
« Reply #2 on: September 01, 2008, 12:38:27 pm »
One important thing, I did a very quick test on a console app (debug target) with the following contents for main.cpp :

Quote
#include <iostream>
#include <vector>

int main()
{
    std::vector<int> Test;
    Test.push_back(1);
    Test.push_back(2);
    Test.push_back(3);
    Test.push_back(4);
    std::cout << "Hello World" << std::endl;
    return 0;
}

==> on my linux box I have the following results

1) when the debugger plug-in is configured to evaluate the variable under the cursor, it is not feasible to right click on the 'Test' variable to add it to the watches
  ==> I manually added it ;-)
2) tooltip : evaluate under cursor gives for 'Test' : Cannot evaluate function -- may be inlined
3) 'Test' in the watches gives : evaluate under cursor gives for 'Test' : Cannot evaluate function -- may be inlined
4) Watches : Local variables -> Test gives : <std::_Vector_base<int, std::allocator<int> >>     <no data field>
.
.
.
5) trying to dock the watches windows ===> CB CRASH

So although the gdb_types.script contains support for the vector (as requested by the OP), I doesn't seem to work.

@Everyone : please write scripts to enhance the debugging/watches experience ;-)