Author Topic: Showing vector elements in debugger  (Read 34488 times)

Offline nji

  • Multiple posting newcomer
  • *
  • Posts: 54
Showing vector elements in debugger
« on: June 22, 2017, 09:31:46 am »
I'm using codeblocks in its actual release (16.01) with tdm mingw 4.9.2 @ Win7Prof64.
When debugging I need to see the contents of a std::vector<double>.
For example: myVector [2].
No matter if I add myVector to the watches ... or then "properties" ("watch as array"),
or if I watch myVector [2] directly ... no success in showing the value,
only quite useless internal information.
Of course I found some threads about that in the forum, but all seem quite old,
some quite arrogant, pointing to nowhere, and very confusing for a newbie like me.
Looks like codeblock is not able to show the info from gdb (Although vector etc.
are c++ standard since years!)
And therefore a python script is needed. And for that python has to be "activated"
while building gdb itself (which is not the case for the windows binaries).
While the latter one seems refused by mingw developers because python project
doesn't cooperate. A cul-de-sac.
And even if all this would work, one would have to do further
steps to build and include gdb-command scripts etc.
If I get it right.
CAN THIS BE POSSIBLE?
Or is it a joke?
In the year 2017 you have to printf to debug a c++ standard element, when using
codeblock/ gcc?
It would be nice if someone could lighten the matter up.
Are there simple steps ... for all the ones who want to change from M$.
Or will the next release of codeblocks do it all by itself?
The situation as it presents now (and not only this example) is quite deterrent.
Which is a pity.
Thank you for hints.
« Last Edit: June 22, 2017, 09:36:35 am by nji »

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: Showing vector elements in debugger
« Reply #1 on: June 22, 2017, 11:25:51 am »
What i have done and it seems to work:
1) Use a python enabled gdb. I don't know but i think the tdm gcc has python enabled
2) In Settings->Debugger->GDB/CDB debugger->Default->Debugger initilization commands:
 
Code
python
import sys
sys.path.insert(0, 'PATH_TO_TDM\share\gcc-4.9.2\python')
from libstdcxx.v6.printers import register_libstdcxx_printers
end
3) make sure you have deactivated "Enable watch scripts"

If you have trouble:
Activate full debugger logging: In Settings->Debugger->GDB/CDB debugger->Common->Full (Debug) log
and post the log here inside code tags (the # symbol in the new post editor)

Quote
CAN THIS BE POSSIBLE?
Or is it a joke?
In the year 2017 you have to printf to debug a c++ standard element, when using
codeblock/ gcc?
See it as learning.. If you know the things behind all this you will get a better programmer

Quote
Or will the next release of codeblocks do it all by itself?
Don't know... The team abandoned the internal scripting and decided to use the gdb internal python scripting. If you use a compiler that has no python support cb could not do anything about this... In general this are gdb problems and not really codeblocks problems ;)

Offline nji

  • Multiple posting newcomer
  • *
  • Posts: 54
Re: Showing vector elements in debugger
« Reply #2 on: June 22, 2017, 11:48:45 am »
What i have done and it seems to work:
1) Use a python enabled gdb. I don't know but i think the tdm gcc has python enabled
No unfortunately NOT.
If I do the test from http://wiki.codeblocks.org/index.php?title=Pretty_Printers
my gdb says that python scripting is deactivated.
And if I search deeper for a python activated gdb I get lost. More and more problems arise.
(Install special versions of mingw etc.)
As I said already - a cul de sac this way.

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: Showing vector elements in debugger
« Reply #3 on: June 22, 2017, 01:01:41 pm »
From this side, it tells me that tdm gcc has python enabled gdb

http://tdm-gcc.tdragon.net/index.php/

This should be the download link
http://sourceforge.net/projects/tdm-gcc/files/GDB/gdb32-7.9.1-tdm-1.zip/download
it should be possible to simply copy this version over your installed version..

Offline nji

  • Multiple posting newcomer
  • *
  • Posts: 54
Re: Showing vector elements in debugger
« Reply #4 on: June 22, 2017, 01:28:03 pm »
In the actual codeblock package (v. 16.01) there is gdb v. 7.6.1, and there python is NOT enabled.
Due to your hint to the tdm site, (up from?) v. 7.9.1. python is enabled.

OK ... I copied the new version of gdb over the installed version und entered the new name gdb(server)32.exe instead of gdb(server).exe into cb's setting. Then startet the db and added "diffVector [2]" to the watch window. The output:
(__gnu_cxx::__alloc_traits<std::allocator<double> >::value_type &) @0x147f660: <error reading variable>

diffVector shows same as before.

Code
Active debugger config: GDB/CDB debugger:Default
Building to ensure sources are up-to-date
Selecting target:
Debug
Adding source dir: D:\Guido\develop\TestMovieIn\
Adding source dir: D:\Guido\develop\TestMovieIn\
Adding file: D:\Guido\develop\TestMovieIn\bin\Debug\TestMovieIn.exe
Changing directory to: D:/Guido/develop/TestMovieIn/.
Set variable: PATH=.;D:\Guido\develop\opencv\build_codeblocks\install\x86\mingw\lib;C:\Program Files (x86)\CodeBlocks\MinGW\bin;C:\Program Files (x86)\CodeBlocks\MinGW;C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\Common Files\Microsoft Shared\Windows Live;C:\Windows\System32;C:\Windows;C:\Windows\System32\wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Program Files (x86)\Windows Live\Shared

[debug]Command-line: C:\Program Files (x86)\CodeBlocks\MinGW\bin\gdb32.exe -nx -fullname -quiet  -args D:/Guido/develop/TestMovieIn/bin/Debug/TestMovieIn.exe
[debug]Working dir : D:\Guido\develop\TestMovieIn

Starting debugger: C:\Program Files (x86)\CodeBlocks\MinGW\bin\gdb32.exe -nx -fullname -quiet  -args D:/Guido/develop/TestMovieIn/bin/Debug/TestMovieIn.exe
done

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

Setting breakpoints

[debug]Reading symbols from D:/Guido/develop/TestMovieIn/bin/Debug/TestMovieIn.exe...
[debug]done.
[debug](gdb) >>>>>>cb_gdb:
[debug]> show version
[debug]GNU gdb (GDB) 7.9.1
[debug]Copyright (C) 2015 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 "mingw32".
[debug]Type "show configuration" for configuration details.
[debug]For bug reporting instructions, please see:
[debug]<http://www.gnu.org/software/gdb/bugs/>.
[debug]Find the GDB manual and other documentation resources online at:
[debug]<http://www.gnu.org/software/gdb/documentation/>.
[debug]For help, type "help".
[debug]Type "apropos word" to search for commands related to "word".
[debug]>>>>>>cb_gdb:
[debug]> set confirm off

Debugger name and version: GNU gdb (GDB) 7.9.1

[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 new-console on
[debug]>>>>>>cb_gdb:
[debug]> set disassembly-flavor att
[debug]>>>>>>cb_gdb:
[debug]> catch throw
[debug]Catchpoint 1 (throw)
[debug]>>>>>>cb_gdb:
[debug]> python
import sys
sys.path.insert(0, 'C:\Program Files (x86)\CodeBlocks\MinGW\share\gcc-4.9.2\python')
from libstdcxx.v6.printers import register_libstdcxx_printers
end
[debug]>>>>>>>>>>cb_gdb:
[debug]> directory D:/Guido/develop/TestMovieIn/
[debug]Source directories searched: D:/Guido/develop/TestMovieIn;$cdir;$cwd
[debug]>>>>>>cb_gdb:
[debug]> break "D:/Guido/develop/TestMovieIn/main.cpp:38"
[debug]Breakpoint 2 at 0x401579: file D:\Guido\develop\TestMovieIn\main.cpp, line 38.
[debug]>>>>>>cb_gdb:
[debug]> run
[debug]Starting program: D:\Guido\develop\TestMovieIn\bin\Debug\TestMovieIn.exe

Child process PID: 4544

[debug][New Thread 4544.0x114c]
[debug][New Thread 4544.0x13dc]
[debug][Switching to Thread 4544.0x13dc]
[debug]Breakpoint 2, ComputePart (source=..., diffVector=..., nLap=@0x55f2ce: 20, nThreads=@0x4d1fe48: 1, nThreadNo=@0x55f2c8: 0) at D:\Guido\develop\TestMovieIn\main.cpp:38
[debug]D:\Guido\develop\TestMovieIn\main.cpp:38:1231:beg:0x401579
[debug]>>>>>>cb_gdb:

At D:\Guido\develop\TestMovieIn\main.cpp:38

[debug]> info locals
[debug]capt = <incomplete type>
[debug]refS = {width = 1280, height = 720}
[debug]frame = {flags = 1124007936, dims = 0, rows = 0, cols = 0, data = 0x0, datastart = 0x0, dataend = 0x0, datalimit = 0x0, allocator = 0x0, u = 0x0, size = {p = 0x4d1fcb0}, step = {p = 0x4d1fcd8, buf = {0, 0}}}
[debug]s = {<cv::Vec<double, 4>> = {<cv::Matx<double, 4, 1>> = {val = {0, 0, 0, 0}}, <No data fields>}, <No data fields>}
[debug]frameRes = {flags = 1124007936, dims = 0, rows = 0, cols = 0, data = 0x0, datastart = 0x0, dataend = 0x0, datalimit = 0x0, allocator = 0x0, u = 0x0, size = {p = 0x4d1fce8}, step = {p = 0x4d1fd10, buf = {0, 0}}}
[debug]frameDuo = {_M_elems = {{flags = 1124007936, dims = 0, rows = 0, cols = 0, data = 0x0, datastart = 0x0, dataend = 0x0, datalimit = 0x0, allocator = 0x0, u = 0x0, size = {p = 0x4d1fd20}, step = {p = 0x4d1fd48, buf = {0, 0}}}, {flags = 1124007936, dims = 0, rows = 0, cols = 0, data = 0x0, datastart = 0x0, dataend = 0x0, datalimit = 0x0, allocator = 0x0, u = 0x0, size = {p = 0x4d1fd58}, step = {p = 0x4d1fd80, buf = {0, 0}}}}}
[debug]frameNum = 0
[debug]>>>>>>cb_gdb:
[debug]> info args
[debug]source = {static npos = <optimized out>, _M_dataplus = {<std::allocator<char>> = {<__gnu_cxx::new_allocator<char>> = {<No data fields>}, <No data fields>}, _M_p = 0x55f27c "26229.wmv"}}
[debug]diffVector = @0x28fecc: {<std::_Vector_base<double, std::allocator<double> >> = {_M_impl = {<std::allocator<double>> = {<__gnu_cxx::new_allocator<double>> = {<No data fields>}, <No data fields>}, _M_start = 0x1c19678, _M_finish = 0x1c19678, _M_end_of_storage = 0x1c80850}}, <No data fields>}
[debug]nLap = @0x55f2ce: 20
[debug]nThreads = @0x4d1fe48: 1
[debug]nThreadNo = @0x55f2c8: 0
[debug]>>>>>>cb_gdb:
[debug]> whatis diffVector
[debug]type = std::vector<double, std::allocator<double> > &
[debug]>>>>>>cb_gdb:
[debug]> output diffVector
[debug](std::vector<double, std::allocator<double> > &) @0x28fecc: {<std::_Vector_base<double, std::allocator<double> >> = {_M_impl = {<std::allocator<double>> = {<__gnu_cxx::new_allocator<double>> = {<No data fields>}, <No data fields>}, _M_start = 0x1c19678, _M_finish = 0x1c19678, _M_end_of_storage = 0x1c80850}}, <No data fields>}>>>>>>cb_gdb:
[debug]> whatis diffVector [2]
[debug]type = std::vector<double, std::allocator<double> >::reference
[debug]>>>>>>cb_gdb:
[debug]> output diffVector [2]
[debug](__gnu_cxx::__alloc_traits<std::allocator<double> >::value_type &) @0x147f660: 1.3795933261199322e-306>>>>>>cb_gdb:
« Last Edit: June 22, 2017, 03:16:36 pm by nji »

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: Showing vector elements in debugger
« Reply #5 on: June 22, 2017, 04:11:41 pm »

If you look in the log:
Code
s = {<cv::Vec<double, 4>> = {<cv::Matx<double, 4, 1>> = {val = {0, 0, 0, 0}}, <No data fields>}, <No data fields>}
there seems that the matrix is deducted right, so the printing seems to work..


and there seems to be the right value:
Code
 whatis diffVector
[debug]type = std::vector<double, std::allocator<double> > &
[debug]>>>>>>cb_gdb:
[debug]> output diffVector
[debug](std::vector<double, std::allocator<double> > &) @0x28fecc: {<std::_Vector_base<double, std::allocator<double> >> = {_M_impl = {<std::allocator<double>> = {<__gnu_cxx::new_allocator<double>> = {<No data fields>}, <No data fields>}, _M_start = 0x1c19678, _M_finish = 0x1c19678, _M_end_of_storage = 0x1c80850}}, <No data fields>}>>>>>>cb_gdb:

so you still get some different output from the script.
Probably you have to update the python script:
https://gcc.gnu.org/svn/gcc/trunk/libstdc++-v3/python/libstdcxx/v6/

this is what i get with this test code:
Code
  vector<double> test;
    test.push_back( 22.44 );
    test.push_back( 1.3795933261199322e-306 );
Code
[debug]> whatis test
[debug]type = std::vector<double>
[debug]>>>>>>cb_gdb:
[debug]> output test
[debug]std::vector of length 2, capacity 2 = {22.440000000000001, 1.3795933261199322e-306}>>>>>>cb_gdb:


Offline nji

  • Multiple posting newcomer
  • *
  • Posts: 54
Re: Showing vector elements in debugger
« Reply #6 on: June 22, 2017, 06:26:27 pm »
Could you please try what happens when you add
Code
 test [1]
to the watch?

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: Showing vector elements in debugger
« Reply #7 on: June 22, 2017, 07:03:17 pm »
Code
[debug]> whatis test[1]
[debug]type = double
[debug]>>>>>>cb_gdb:
[debug]> output test[1]
[debug]1.3795933261199322e-306>>>>>>cb_gdb:

i hope you don't use the space in the watch window, like here in the code section

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: Showing vector elements in debugger
« Reply #8 on: June 22, 2017, 07:05:21 pm »
jep, you are using a space... this is wrong. Don't use a space in the watch name and you should be fine
Code
[debug]> whatis diffVector [2]
[debug]type = std::vector<double, std::allocator<double> >::reference
Code
whatis diffVector
is as gdb says a reference...

Offline nji

  • Multiple posting newcomer
  • *
  • Posts: 54
Re: Showing vector elements in debugger
« Reply #9 on: June 22, 2017, 07:38:34 pm »
Space or not space ... this is ... NOT ... the question  ;)

What I mean:
It doesn't matter if I add "test[1]" to the watch window (in c:b) or "test [1]" ... both don't work.
Could you please check at you?

Code
[debug]> whatis test[1]
[debug]type = std::vector<double, std::allocator<double> >::reference
[debug]>>>>>>cb_gdb:
[debug]> output test[1]
[debug](__gnu_cxx::__alloc_traits<std::allocator<double> >::value_type &) @0x19de910: <error reading variable>>>>>>>cb_gdb:

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: Showing vector elements in debugger
« Reply #10 on: June 22, 2017, 08:05:09 pm »
how does your code looks?
have you updated the scripts?

[edit:] you are right, the space makes no difference...

have you tested my simple example code from the top?
« Last Edit: June 22, 2017, 08:09:21 pm by BlueHazzard »

Offline nji

  • Multiple posting newcomer
  • *
  • Posts: 54
Re: Showing vector elements in debugger
« Reply #11 on: June 22, 2017, 08:27:15 pm »
It's exactly your code snipplet from above.
I updated the scripts.
test is shown correctly in debugger and in watches, while test[1] is not:

Code
[debug]> whatis test[1]
[debug]type = std::vector<double, std::allocator<double> >::reference
[debug]>>>>>>cb_gdb:
[debug]> output test[1]
[debug](__gnu_cxx::__alloc_traits<std::allocator<double> >::value_type &) @0x19de910: <error reading variable>>>>>>>cb_gdb:
[debug]> whatis test
[debug]type = std::vector<double>
[debug]>>>>>>cb_gdb:
[debug]> output test
[debug]std::vector of length 2, capacity 2 = {22.440000000000001, 1.3795933261199322e-306}>>>>>>cb_gdb:

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Showing vector elements in debugger
« Reply #12 on: June 22, 2017, 08:33:02 pm »
The problem is in gdb (or the pretty printers). It tells you that it cannot read the value of this expression.
(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 nji

  • Multiple posting newcomer
  • *
  • Posts: 54
Re: Showing vector elements in debugger
« Reply #13 on: June 22, 2017, 08:40:33 pm »
How can this be?
I downloaded the newest gdb (from link above) and scripts.
And "test[1]" is not a too complex expression ... an error in gdb/ scripts should have shown before.
What about python?

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: Showing vector elements in debugger
« Reply #14 on: June 22, 2017, 08:46:25 pm »
if this matters, i have this gdb version: GNU gdb (GDB) 7.10.50.20160130-git
probably i got it from here: http://forums.codeblocks.org/index.php/topic,11301.0.html
« Last Edit: June 22, 2017, 08:48:24 pm by BlueHazzard »