[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4020
  • Last Modified:

g++, gdb: debugging with STL containers

Hello,

I'm in the process of writing a C++ application using gcc, gdb, the STL and the netbeans IDE on Linux. If I watch the value of a template variable, I get something like this:
{_M_t = {_M_impl = {<std::allocator<std::_Rb_tree_node<std::pair<const int, int> > >> = {<__gnu_cxx::new_allocator<std::_Rb_tree_node<std::pair<const int, int> > >> = {<No data fields>}, <No data fields>}, _M_key_compare = {<> = {<No data fields>}, <No data fields>}, _M_header = {_M_color = std::_S_red, _M_parent = 0x8132870, _M_left = 0x8112870, _M_right = 0x8128740}, _M_node_count = 3}}}

This isn't very useful: in Visual Studio on windows, I can see the value of the containers members (even nested templates, I believe), which is very useful.

Is something similar possible with gdb?
Regards,
Sternocera
0
sternocera
Asked:
sternocera
2 Solutions
 
evilrixSenior Software Engineer (Avast)Commented:
>> I can see the value of the containers members (even nested templates, I believe), which is very useful.
Isn't that what gdb is showing you though? Obviously, natively gdb is a text based debugger so it's presentation isn't going to be as nice as Visual Studio. Have you tried using ddd, which is a GUI wrapper for gdb?
http://www.gnu.org/software/ddd/

0
 
sternoceraAuthor Commented:
I'm using netbeans, which provides a graphical frontend to gdb in much the same manner as ddd - I actually have used ddd in the past. I realise that gdb is showing me the literal value of the template, which is memory addresses and such. however, it would be useful if I could see those values automagically, as I can in visual studio.

This would have to be a specific feature of gdb or its extensions, which doesn't seem to be provided by ddd or any other tool I'm aware of,
Regards,
Sternocera
0
 
evilrixSenior Software Engineer (Avast)Commented:
>> This would have to be a specific feature of gdb or its extensions, which doesn't seem to be provided by ddd or any other tool I'm aware of,
Try looking at this: http://staff.science.uva.nl/~gilad/stl/stl_gdb.html
0
 
jkrCommented:
See also the script at http://help.lockergnome.com/linux/GDB-capabilities-exploring-STL-classes-ftopict279673.html
##########################################
# #
# STL GDB evaluators/views/utilities #
# #
##########################################
#
# The new GDB commands:
# are entirely non instrumental
# do not depend on any "inline"(s) - e.g. size(), [], etc
# are extremely tolerant to debugger settings
#
# This file should be "included" in .gdbinit as following:
# source stl-views.gdb or just paste it into your .gdbinit file
#
# The following STL containers are currently supported:
#
# std::vector<T> -- via pvector command
# std::list<T> -- via plist command
# std::map<T,T> -- via pmap command
# std::multimap<T,T> -- via pmap command
# std::set<T> -- via pset command
# std::multiset<T> -- via pset command
# std::deque<T> -- via pdequeue command
# std::stack<T> -- via pstack command
# std::queue<T> -- via pqueue command
# std::priority_queue<T> -- via ppqueue command
# std::bitset<n> -- via pbitset command
# std::string -- via pstring command
# std::widestring -- via pwstring command
#
# The end of this file contains (optional) C++ beautifiers
#
##########################################################################
# #
# CopyRight @ 2008 - Dan C Marinescu - All Rights Reserved under GPL V3. #
# #
# Email: dan_c_marinescu DeleteThis @yahoo.com #
# #
##########################################################################
 
// full script in the above link

Open in new window

0
 
SeanDurkinCommented:
No comment has been added to this question in more than 21 days, so it is now classified as abandoned.

I will leave the following recommendation for this question in the Cleanup Zone:
      Split: evilrix {http:#20873919} & jkr {http:#20875675}

Any objections should be posted here in the next 4 days. After that time, the question will be closed.

Sean
EE Cleanup Volunteer
0

Featured Post

Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now