Author Topic: Display 2d Vector in Watches  (Read 6126 times)

Offline nyislander

  • Multiple posting newcomer
  • *
  • Posts: 10
Display 2d Vector in Watches
« on: December 30, 2010, 06:16:29 pm »
C::B 10.02

In debug if I set a breakpoint on the "Pause" and try to display let's say temp[1] in the Watches for the following code I get the message "no available data" under the temp[1] watch.  What am I doing wrong?

Code
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <vector>

using namespace std;

int main()
{ // main

int j = 0, h = 0;
vector< vector< int > > temp (5);

        for (h = 0; h < 5; ++h)
           {for (j = 0; j < 5; ++j){temp[h].push_back(j); cout << setw(2) << temp[h][j];} cout << endl;}
        system("PAUSE");

} // end main

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13406
    • Travis build status
Re: Display 2d Vector in Watches
« Reply #1 on: December 30, 2010, 07:18:01 pm »
Does watches for 1d vector work?
Does watches work for simple variables (int,float)?
(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 nyislander

  • Multiple posting newcomer
  • *
  • Posts: 10
Re: Display 2d Vector in Watches
« Reply #2 on: December 30, 2010, 07:21:14 pm »
Yes, for a 1d vector Watches works.  When I watched 2d & 3d vectors in 8.02 I could see them.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6077
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Display 2d Vector in Watches
« Reply #3 on: December 31, 2010, 01:27:52 am »
works  here (latest debugger branch nightly, windows, gdb with python)
here is the log:
Code
> p temp
$6 = std::vector of length 5, capacity 5 = {std::vector of length 5, capacity 8 = {0, 1, 2, 3, 4}, std::vector of length 5, capacity 8 = {0, 1, 2, 3, 4}, std::vector of length 5, capacity 8 = {0, 1, 2, 3, 4}, std::vector of length 5, capacity 8 = {0, 1, 2, 3, 4}, std::vector of length 5, capacity 8 = {0, 1, 2, 3, 4}}
>>>>>>cb_gdb:
> pvector temp
elem[0]: $7 = std::vector of length 5, capacity 8 = {0, 1, 2, 3, 4}
elem[1]: $8 = std::vector of length 5, capacity 8 = {0, 1, 2, 3, 4}
elem[2]: $9 = std::vector of length 5, capacity 8 = {0, 1, 2, 3, 4}
elem[3]: $10 = std::vector of length 5, capacity 8 = {0, 1, 2, 3, 4}
elem[4]: $11 = std::vector of length 5, capacity 8 = {0, 1, 2, 3, 4}
Vector size = 5
Vector capacity = 5
Element type = std::vector<int, std::allocator<int> >

Code
p temp 
command internally call the python pretty printer.
Code
pvector temp
use the stl container script support.

But the watch window does not parse the output quite well. :(
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: 13406
    • Travis build status
Re: Display 2d Vector in Watches
« Reply #4 on: December 31, 2010, 01:57:34 am »
Watch windows doesn't parse the pretty printer output...

And I suppose that nyislander doesn't have pretty printers...
(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 nyislander

  • Multiple posting newcomer
  • *
  • Posts: 10
Re: Display 2d Vector in Watches
« Reply #5 on: January 05, 2011, 03:56:33 am »
I went back to C::B 8.02 - all is well.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6077
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Display 2d Vector in Watches
« Reply #6 on: January 05, 2011, 04:05:26 am »
I went back to C::B 8.02 - all is well.
1, it seems only vector<int> is supported, so ,if you write vector<wxString>, I think you will get failed.
2, well, it seems there is a tiny bug in parsing the gdb's response string, I personally suggest using the python gdb script, it really support more types. (and can be extended to more user types).
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.