It would be nice if iterators could be dereferenced through ->. Currently only * works. Using -> will give a "There is no member or method" error. Example: $ cat foo.cpp #include <vector> #include <string> #include <iostream> int main(int argc, char **argv) { std::pair<std::string, std::string> p ("first", "second"); std::vector<std::pair<std::string, std::string> > v; v.push_back (p); std::vector<std::pair<std::string, std::string> >::iterator it = v.begin (); std::cout << it->first << " : " << it->second << std::endl; return 0; } $ g++ -g -o foo foo.cpp $ gdb ./foo GNU gdb (GDB) Fedora (7.2-36.fc14) Copyright (C) 2010 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "x86_64-redhat-linux-gnu". For bug reporting instructions, please see: <http://www.gnu.org/software/gdb/bugs/>... Reading symbols from /tmp/foo...done. (gdb) break main Breakpoint 1 at 0x400d74: file foo.cpp, line 7. (gdb) run Starting program: /tmp/foo Breakpoint 1, main (argc=1, argv=0x7fffffffe278) at foo.cpp:7 7 std::pair<std::string, std::string> p ("first", "second"); (gdb) n 8 std::vector<std::pair<std::string, std::string> > v; (gdb) 10 v.push_back (p); (gdb) 12 std::vector<std::pair<std::string, std::string> >::iterator it = v.begin (); (gdb) 14 std::cout << it->first << " : " << it->second << std::endl; (gdb) print it->first There is no member or method named first. (gdb) print (*it).first $1 = "first"
Mark, I don't know if a lot has changed recently, but this appears to have been fixed: gdb 12446 GNU gdb (GDB) 7.2.50.20110125-cvs Copyright (C) 2011 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "x86_64-unknown-linux-gnu". For bug reporting instructions, please see: <http://www.gnu.org/software/gdb/bugs/>... Reading symbols from /home/keiths/tmp/12446...done. (gdb) b main Breakpoint 1 at 0x400d76: file 12446.cc, line 7. (gdb) r Starting program: /home/keiths/tmp/12446 Breakpoint 1, main (argc=1, argv=0x7fffffffe038) at 12446.cc:7 7 std::pair<std::string, std::string> p ("first", "second"); (gdb) n 8 std::vector<std::pair<std::string, std::string> > v; (gdb) 10 v.push_back (p); (gdb) 12 std::vector<std::pair<std::string, std::string> >::iterator it = v.begin (); (gdb) 14 std::cout << it->first << " : " << it->second << std::endl; (gdb) p it->first $1 = "first" Can you verify? [BTW, this is using a fresh copy of libstdc++ pretty printers obtained today.]
(In reply to comment #1) > Mark, I don't know if a lot has changed recently, but this appears to have been > fixed: Yes! I build gdb from source (7.2.50.20110214-cvs) and installed the python libstdc++ pretty printers as described on: http://sourceware.org/gdb/wiki/STLSupport And it works!