Author Topic: Feature Request/Help: GDB Vector, nested vector, and strut viewing.[SOLVED]  (Read 10984 times)

Offline PureBlackSin

  • Multiple posting newcomer
  • *
  • Posts: 14
Hi guys, I have been searching the internet for a fix to my problem.

I regularly use vectors (who doesn't) and I was surprised to find that I couldn't directly view them in the debugger. Initially I wasn't too bothered and continued, using various workarounds. I also found a few scripts and homemade addons hanging around the internet which could have potentially helped, and if worst came to the worst I'd reboot and use MSVS to view the vectors, etc.

Out of all the "pretty" things you've made Code::Blocks do (all of which I really like), I'm somewhat surprised that this isn't a stock feature...

If this was a feature I could effectively abandon MSVS and Code::Blocks would cover all my needs.

Any chance this is becoming a feature, or is in the pipeline already and I've managed to not find it? I currently get the nightly builds (I did this in the hope that these would have the feature and the stable release was just lacking it..).

Any information on this would be great as I much prefer your IDE over many of the others! This is the only barrier :P

Cheers!

  
« Last Edit: July 23, 2012, 04:49:00 am by PureBlackSin »

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5247
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Feature Request/Help: GDB Vector, nested vector, and strut viewing.
« Reply #1 on: July 19, 2012, 06:20:13 am »
If you gdb is build with python enabled, you have no problem shown vectors.

See:
http://sourceware.org/gdb/wiki/STLSupport

http://forums.codeblocks.org/index.php/topic,11301.msg77000.html#msg77000

as references.
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.

Offline PureBlackSin

  • Multiple posting newcomer
  • *
  • Posts: 14
Re: Feature Request/Help: GDB Vector, nested vector, and strut viewing.
« Reply #2 on: July 19, 2012, 05:02:32 pm »
Okay, I probably should have mentioned I'm a Linux/Ubuntu user. I tried for a couple of hours and using my google-foo and still couldn't get it working.

I ran this:

svn co svn://gcc.gnu.org/svn/gcc/trunk/libstdc++-v3/python

Created a file in /home called: .gdbinit

Put this in the file:

python
import sys
sys.path.insert(0, '/home/python')
from libstdcxx.v6.printers import register_libstdcxx_printers
register_libstdcxx_printers (None)
end

Still no joy :( I'm assuming that the Code::Blocks 8059 SVN nightly build and GDB 7.4-2012.04-0ubuntu2 combo  is python enabled. The GDB change log seems to suggest that it is python enabled, but I just skimmed it for the word python...

Also, still waiting to find out why this isn't all standard.

More help please!
« Last Edit: July 19, 2012, 05:08:09 pm by PureBlackSin »

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 12121
    • Travis build status
Re: Feature Request/Help: GDB Vector, nested vector, and strut viewing.
« Reply #3 on: July 19, 2012, 05:07:43 pm »
First you need the latest build, because there are some improvements to the way C::B parses the output of GDB.
Then you should disable the "Watch scripts" in the settings of the debugger.
Instead of .gdbinit you can use another file and then you can put "source path_to_file" in the initial commands of the debugger. This works 100%.

Also gcc>=4.5 include the pretty printers in their installation by default, so no additional setup is needed.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline PureBlackSin

  • Multiple posting newcomer
  • *
  • Posts: 14
Re: Feature Request/Help: GDB Vector, nested vector, and strut viewing.
« Reply #4 on: July 19, 2012, 05:21:26 pm »
Okay, I've disabled Watch scripts.
gcc version: 4:4.6.3-1ubuntu5 | So it doesn't look like it's there by default, I'm assuming there is a tickbox that needs to be ticked.

Quote
you can put "source path_to_file" in the initial commands of the debugger. This works 100%.

No idea what you mean by this, I looked though all the options in c::b and couldn't find where I could put this, or what "source path_to_file" should be, is it to the python scripts gained from the SVN checkout? That's what I assumed, still no luck...

Note: just thought I'd point out I'm trying to look at a vector<> of strings.
« Last Edit: July 19, 2012, 05:25:36 pm by PureBlackSin »

Offline PureBlackSin

  • Multiple posting newcomer
  • *
  • Posts: 14
Re: Feature Request/Help: GDB Vector, nested vector, and strut viewing.
« Reply #5 on: July 19, 2012, 06:34:20 pm »
Also just updated to Code::Blocks SVN 813. Still no joy.

Any more help would be appreciated. :P

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 12121
    • Travis build status
Re: Feature Request/Help: GDB Vector, nested vector, and strut viewing.
« Reply #6 on: July 19, 2012, 10:53:43 pm »
813 is not a recent revision...

And here for me it works, by only disabling the watch scripts in the options.
This is on gentoo running gcc-4.7.0, my project doesn't build with 4.6, so I can't test, but I'm sure it will work, too.

Can you paste the full log from the debugger?
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline PureBlackSin

  • Multiple posting newcomer
  • *
  • Posts: 14
Re: Feature Request/Help: GDB Vector, nested vector, and strut viewing.
« Reply #7 on: July 20, 2012, 01:21:43 am »
Yeah! Sure:


Code: [Select]
Building to ensure sources are up-to-date
Selecting target:
Debug
Adding source dir: /host/James/Ubuntu/C-C++/ParseWords/
Adding source dir: /host/James/Ubuntu/C-C++/ParseWords/
Adding file: /host/James/Ubuntu/C-C++/ParseWords/bin/Debug/ParseWords
Changing directory to: /host/James/Ubuntu/C-C++/ParseWords/.
Starting debugger: /usr/bin/gdb -nx -fullname  -quiet  -args /host/James/Ubuntu/C-C++/ParseWords/bin/Debug/ParseWords
done
Setting breakpoints
Debugger name and version: GNU gdb (Ubuntu/Linaro 7.4-2012.04-0ubuntu2) 7.4-2012.04
At /host/James/Ubuntu/C-C++/ParseWords/main.cpp:220


Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 12121
    • Travis build status
Re: Feature Request/Help: GDB Vector, nested vector, and strut viewing.
« Reply #8 on: July 20, 2012, 07:55:21 am »
Try again, but first enable the full logging in the options.
« Last Edit: July 20, 2012, 10:32:20 am by oBFusCATed »
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline PureBlackSin

  • Multiple posting newcomer
  • *
  • Posts: 14
Re: Feature Request/Help: GDB Vector, nested vector, and strut viewing.
« Reply #9 on: July 20, 2012, 10:41:12 am »
Try again, but first enable the full logging in the options.

Opps, yeah, my bad, here's take two :P

Code: [Select]
Building to ensure sources are up-to-date
Selecting target:
Debug
Adding source dir: /host/James/Ubuntu/C-C++/ParseWords/
Adding source dir: /host/James/Ubuntu/C-C++/ParseWords/
Adding file: /host/James/Ubuntu/C-C++/ParseWords/bin/Debug/ParseWords
Changing directory to: /host/James/Ubuntu/C-C++/ParseWords/.

[debug]LD_LIBRARY_PATH=.:
[debug]Command-line: /usr/bin/gdb -nx -fullname  -quiet  -args /host/James/Ubuntu/C-C++/ParseWords/bin/Debug/ParseWords
[debug]Working dir : /host/James/Ubuntu/C-C++/ParseWords

Starting debugger: /usr/bin/gdb -nx -fullname  -quiet  -args /host/James/Ubuntu/C-C++/ParseWords/bin/Debug/ParseWords
done

[debug]> set prompt >>>>>>cb_gdb:
[debug]Skip initializing the scripting!

Setting breakpoints

[debug]Queued:[tty /dev/?]
[debug]Reading symbols from /host/James/Ubuntu/C-C++/ParseWords/bin/Debug/ParseWords...
[debug]done.
[debug](gdb) >>>>>>cb_gdb:
[debug]> show version
[debug]GNU gdb (Ubuntu/Linaro 7.4-2012.04-0ubuntu2) 7.4-2012.04
[debug]Copyright (C) 2012 Free Software Foundation, Inc.
[debug]License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
[debug]This is free software: you are free to change and redistribute it.
[debug]There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
[debug]and "show warranty" for details.
[debug]This GDB was configured as "x86_64-linux-gnu".
[debug]For bug reporting instructions, please see:
[debug]<http://bugs.launchpad.net/gdb-linaro/>.
[debug]>>>>>>cb_gdb:
[debug]> set confirm off

Debugger name and version: GNU gdb (Ubuntu/Linaro 7.4-2012.04-0ubuntu2) 7.4-2012.04

[debug]>>>>>>cb_gdb:
[debug]> set width 0
[debug]>>>>>>cb_gdb:
[debug]> set height 0
[debug]>>>>>>cb_gdb:
[debug]> set breakpoint pending on
[debug]>>>>>>cb_gdb:
[debug]> set print asm-demangle on
[debug]>>>>>>cb_gdb:
[debug]> set unwindonsignal on
[debug]>>>>>>cb_gdb:
[debug]> set print elements 0
[debug]>>>>>>cb_gdb:
[debug]> set disassembly-flavor intel
[debug]>>>>>>cb_gdb:
[debug]> catch throw
[debug]Function "__cxa_throw" not defined.
[debug]Catchpoint 1 (throw)
[debug]>>>>>>cb_gdb:
[debug]> directory /host/James/Ubuntu/C-C++/ParseWords/
[debug]>>>>>>cb_gdb:
[debug]> break "/host/James/Ubuntu/C-C++/ParseWords/main.cpp:220"
[debug]Breakpoint 2 at 0x401fcd: file /host/James/Ubuntu/C-C++/ParseWords/main.cpp, line 220.
[debug]>>>>>>cb_gdb:
[debug]> tty /dev/?
[debug]>>>>>>cb_gdb:
[debug]> run
[debug]/dev/?: No such file or directory.
[debug]During startup program exited with code 1.
[debug]>>>>>>cb_gdb:

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 12121
    • Travis build status
Re: Feature Request/Help: GDB Vector, nested vector, and strut viewing.
« Reply #10 on: July 20, 2012, 11:35:22 am »
I see nothing related to watches here.
Please post a log from a debug session, where a breakpoint is hit and you add a watch to a vector.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline PureBlackSin

  • Multiple posting newcomer
  • *
  • Posts: 14
Re: Feature Request/Help: GDB Vector, nested vector, and strut viewing.
« Reply #11 on: July 20, 2012, 12:33:19 pm »
I see nothing related to watches here.
Please post a log from a debug session, where a breakpoint is hit and you add a watch to a vector.

Terribly sorry, here's the stuff you were looking for:

Code: [Select]
Building to ensure sources are up-to-date
Selecting target:
Debug
Adding source dir: /host/James/Ubuntu/C-C++/ParseWords/
Adding source dir: /host/James/Ubuntu/C-C++/ParseWords/
Adding file: /host/James/Ubuntu/C-C++/ParseWords/bin/Debug/ParseWords
Changing directory to: /host/James/Ubuntu/C-C++/ParseWords/.

[debug]LD_LIBRARY_PATH=.:
[debug]Command-line: /usr/bin/gdb -nx -fullname  -quiet  -args /host/James/Ubuntu/C-C++/ParseWords/bin/Debug/ParseWords
[debug]Working dir : /host/James/Ubuntu/C-C++/ParseWords

Starting debugger: /usr/bin/gdb -nx -fullname  -quiet  -args /host/James/Ubuntu/C-C++/ParseWords/bin/Debug/ParseWords
done

[debug]> set prompt >>>>>>cb_gdb:
[debug]Skip initializing the scripting!

Setting breakpoints

[debug]Reading symbols from /host/James/Ubuntu/C-C++/ParseWords/bin/Debug/ParseWords...done.
[debug](gdb) >>>>>>cb_gdb:
[debug]> show version
[debug]GNU gdb (Ubuntu/Linaro 7.4-2012.04-0ubuntu2) 7.4-2012.04
[debug]Copyright (C) 2012 Free Software Foundation, Inc.
[debug]License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
[debug]This is free software: you are free to change and redistribute it.
[debug]There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
[debug]and "show warranty" for details.
[debug]This GDB was configured as "x86_64-linux-gnu".
[debug]For bug reporting instructions, please see:
[debug]<http://bugs.launchpad.net/gdb-linaro/>.
[debug]>>>>>>cb_gdb:
[debug]> set confirm off

Debugger name and version: GNU gdb (Ubuntu/Linaro 7.4-2012.04-0ubuntu2) 7.4-2012.04

[debug]>>>>>>cb_gdb:
[debug]> set width 0
[debug]>>>>>>cb_gdb:
[debug]> set height 0
[debug]>>>>>>cb_gdb:
[debug]> set breakpoint pending on
[debug]>>>>>>cb_gdb:
[debug]> set print asm-demangle on
[debug]>>>>>>cb_gdb:
[debug]> set unwindonsignal on
[debug]>>>>>>cb_gdb:
[debug]> set print elements 0
[debug]>>>>>>cb_gdb:
[debug]> set disassembly-flavor intel
[debug]>>>>>>cb_gdb:
[debug]> catch throw
[debug]Function "__cxa_throw" not defined.
[debug]Catchpoint 1 (throw)
[debug]>>>>>>cb_gdb:
[debug]> directory /host/James/Ubuntu/C-C++/ParseWords/
[debug]>>>>>>cb_gdb:
[debug]> break "/host/James/Ubuntu/C-C++/ParseWords/main.cpp:220"
[debug]Queued:[tty /dev/pts/1]
[debug]Breakpoint 2 at 0x401fcd: file /host/James/Ubuntu/C-C++/ParseWords/main.cpp, line 220.
[debug]>>>>>>cb_gdb:
[debug]> tty /dev/pts/1
[debug]>>>>>>cb_gdb:
[debug]> run
[debug]Breakpoint 2, ParseThesaurus (inFilename=..., inWordPackageArray=...) at /host/James/Ubuntu/C-C++/ParseWords/main.cpp:220
[debug]/host/James/Ubuntu/C-C++/ParseWords/main.cpp:220:5438:beg:0x401fcd
[debug]>>>>>>cb_gdb:

At /host/James/Ubuntu/C-C++/ParseWords/main.cpp:220

[debug]> whatis ParsedStringArray
[debug]type = std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >
[debug]>>>>>>cb_gdb:
[debug]> output ParsedStringArray
[debug]{<std::_Vector_base<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >> = {_M_impl = {<std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >> = {<__gnu_cxx::new_allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >> = {<No data fields>}, <No data fields>}, _M_start = 0xa3daf0, _M_finish = 0xa55af0, _M_end_of_storage = 0xa5daf0}}, <No data fields>}>>>>>>cb_gdb:

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5247
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Feature Request/Help: GDB Vector, nested vector, and strut viewing.
« Reply #12 on: July 20, 2012, 12:53:28 pm »


Code: [Select]
Building to ensure sources are up-to-date
...

At /host/James/Ubuntu/C-C++/ParseWords/main.cpp:220

[debug]> whatis ParsedStringArray
[debug]type = std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >
[debug]>>>>>>cb_gdb:
[debug]> output ParsedStringArray
[debug]{<std::_Vector_base<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >> = {_M_impl = {<std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >> = {<__gnu_cxx::new_allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >> = {<No data fields>}, <No data fields>}, _M_start = 0xa3daf0, _M_finish = 0xa55af0, _M_end_of_storage = 0xa5daf0}}, <No data fields>}>>>>>>cb_gdb:
From the above log message, I believe that either you use a gdb which does not have python enabled or you stl pretty printer does not load correctly.
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.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 12121
    • Travis build status
Re: Feature Request/Help: GDB Vector, nested vector, and strut viewing.
« Reply #13 on: July 20, 2012, 01:02:00 pm »
Another thing you could try is to stop on a breakpoint and then to execute the following command:
Code: [Select]
info pretty-printer

This will list all available printers.
If the list is empty, the printers have not been installed correctly.
If the command is not supported your gdb doesn't support python.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline PureBlackSin

  • Multiple posting newcomer
  • *
  • Posts: 14
Re: Feature Request/Help: GDB Vector, nested vector, and strut viewing.
« Reply #14 on: July 20, 2012, 09:42:09 pm »
Code: [Select]
Building to ensure sources are up-to-date
Selecting target:
Debug
Adding source dir: /host/James/Ubuntu/C-C++/ParseWords/
Adding source dir: /host/James/Ubuntu/C-C++/ParseWords/
Adding file: /host/James/Ubuntu/C-C++/ParseWords/bin/Debug/ParseWords
Changing directory to: /host/James/Ubuntu/C-C++/ParseWords/.

[debug]LD_LIBRARY_PATH=.:
[debug]Command-line: /usr/bin/gdb -nx -fullname  -quiet  -args /host/James/Ubuntu/C-C++/ParseWords/bin/Debug/ParseWords
[debug]Working dir : /host/James/Ubuntu/C-C++/ParseWords

Starting debugger: /usr/bin/gdb -nx -fullname  -quiet  -args /host/James/Ubuntu/C-C++/ParseWords/bin/Debug/ParseWords
done

[debug]> set prompt >>>>>>cb_gdb:
[debug]Skip initializing the scripting!

Setting breakpoints

[debug]Reading symbols from /host/James/Ubuntu/C-C++/ParseWords/bin/Debug/ParseWords...done.
[debug](gdb) >>>>>>cb_gdb:
[debug]> show version
[debug]GNU gdb (Ubuntu/Linaro 7.4-2012.04-0ubuntu2) 7.4-2012.04
[debug]Copyright (C) 2012 Free Software Foundation, Inc.
[debug]License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
[debug]This is free software: you are free to change and redistribute it.
[debug]There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
[debug]and "show warranty" for details.
[debug]This GDB was configured as "x86_64-linux-gnu".
[debug]For bug reporting instructions, please see:
[debug]<http://bugs.launchpad.net/gdb-linaro/>.
[debug]>>>>>>cb_gdb:
[debug]> set confirm off

Debugger name and version: GNU gdb (Ubuntu/Linaro 7.4-2012.04-0ubuntu2) 7.4-2012.04

[debug]>>>>>>cb_gdb:
[debug]> set width 0
[debug]>>>>>>cb_gdb:
[debug]> set height 0
[debug]>>>>>>cb_gdb:
[debug]> set breakpoint pending on
[debug]>>>>>>cb_gdb:
[debug]> set print asm-demangle on
[debug]>>>>>>cb_gdb:
[debug]> set unwindonsignal on
[debug]>>>>>>cb_gdb:
[debug]> set print elements 0
[debug]>>>>>>cb_gdb:
[debug]> set disassembly-flavor intel
[debug]>>>>>>cb_gdb:
[debug]> catch throw
[debug]Function "__cxa_throw" not defined.
[debug]Catchpoint 1 (throw)
[debug]>>>>>>cb_gdb:
[debug]> directory /host/James/Ubuntu/C-C++/ParseWords/
[debug]>>>>>>cb_gdb:
[debug]> break "/host/James/Ubuntu/C-C++/ParseWords/main.cpp:220"
[debug]Breakpoint 2 at 0x401fcd: file /host/James/Ubuntu/C-C++/ParseWords/main.cpp, line 220.
[debug]>>>>>>cb_gdb:
[debug]> tty /dev/pts/1
[debug]Queued:[tty /dev/pts/1]
[debug]>>>>>>cb_gdb:
[debug]> run
[debug]Breakpoint 2, ParseThesaurus (inFilename=..., inWordPackageArray=...) at /host/James/Ubuntu/C-C++/ParseWords/main.cpp:220
[debug]/host/James/Ubuntu/C-C++/ParseWords/main.cpp:220:5418:beg:0x401fcd
[debug]>>>>>>cb_gdb:

At /host/James/Ubuntu/C-C++/ParseWords/main.cpp:220

[debug]> whatis ParsedStringArray
[debug]type = std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >
[debug]>>>>>>cb_gdb:
[debug]> output ParsedStringArray
[debug]{<std::_Vector_base<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >> = {_M_impl = {<std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >> = {<__gnu_cxx::new_allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >> = {<No data fields>}, <No data fields>}, _M_start = 0xa3daf0, _M_finish = 0xa55af0, _M_end_of_storage = 0xa5daf0}}, <No data fields>}>>>>>>cb_gdb:

> info pretty-printer

[debug]> info pretty-printer
[debug]>>>>>>cb_gdb:

Looks like they are not installed properly...... I'll have a crack and report back, I still can't work out why all this isn't default in the setup...