On Feb 22, 11:54 am, "foxx" <[EMAIL PROTECTED]> wrote:
> I'm moving to g++/gdb from Visual Studio.  But I'm confused about how
> to debug my STL containers:  in VS there is a GUI that lets you
> inspect the containers, for example clicking through a tree viewer to
> see the elements of a list.  What is the GDB equivilent of this?  I
> know for vector you can look at elements directly, myvector[i], but
> what about other container types?
>
> I'm often dealing with nested types like list<list<vector<myobject*> >
>
> so I need a method flexible enough to handle these sensibly.

$ cat test.cc
#include <map>
#include <iostream>

void dump(std::map<int, int> const& m)
{
    for(std::map<int, int>::const_iterator i(m.begin()), j(m.end());
i != j; ++i)
        std::cout << '[' << i->first << "] = " << i->second << '\n';
}

int main()
{
    std::map<int, int> m;
    m[2] = 20;
    m[4] = 40;
}

$ g++ -g -o test test.cc
$ gdb test
GNU gdb Red Hat Linux (6.3.0.0-1.134.fc5rh)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and
you are
welcome to change it and/or distribute copies of it under certain
conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for
details.
This GDB was configured as "i386-redhat-linux-gnu"...Using host
libthread_db library "/lib/libthread_db.so.1".

(gdb) l main
5       {
6           for(std::map<int, int>::const_iterator i(m.begin()), j(m.end());
i != j; ++i)
7               std::cout << '[' << i->first << "] = " << i->second << '\n';
8       }
9
10      int main()
11      {
12          std::map<int, int> m;
13          m[2] = 20;
14          m[4] = 40;
(gdb) b 14
Breakpoint 1 at 0x80489b2: file test.cc, line 14.
(gdb) r
Starting program: /home/myegorus/src/test/test
Reading symbols from shared object read from target memory...done.
Loaded system supplied DSO at 0x1aa000

Breakpoint 1, main () at test.cc:14
14          m[4] = 40;
(gdb) n
15      }
(gdb) call dump(m)
[2] = 20
[4] = 40
(gdb) q
The program is running.  Exit anyway? (y or n) y


_______________________________________________
help-gplusplus mailing list
help-gplusplus@gnu.org
http://lists.gnu.org/mailman/listinfo/help-gplusplus

Reply via email to