Author Topic: View variables in arrays and variables in other classes?  (Read 4763 times)

ChiggenWingz

  • Guest
View variables in arrays and variables in other classes?
« on: July 09, 2011, 10:37:14 am »
G'day everyone!

I'm trying to find a way that I can view data that is stored in arrays.

I don't come from a strong programming background, have basically self taught myself and done a games course that taught us a bit of C# using MS Visual C# Express.  I was able to see the values of various arrays in Vis C# and if I programmed my game right, I could navigate through all the classes and see any variable at any point in my program.

After reading around for the past few days and talking to other programmers at work (I work in Quality Assurance), it seems I need to do some sort of memory dump and then I should be able to read the values off that?  Not super sure how to do that, nor am I looking forward to sifting through piles of hex code :(

How do I find the values of my arrays at various points in my program should I use a break point?

-------------

Side note, how do I stop code blocks from jumping over functions that have divide by zero errors when I'm running it in debug mode?  I've spent ages trying to track down issues only to have code blocks jump over sections of my code because there was a divide by zero error and it didn't let me know :(
« Last Edit: July 09, 2011, 01:29:37 pm by ChiggenWingz »

Offline Freem

  • Almost regular
  • **
  • Posts: 219
Re: View variables in arrays and variables in other classes?
« Reply #1 on: July 11, 2011, 09:55:47 am »
For the first question, something that might greatly help us should be to give us what version of C::B you are using. Is it the last official, the nightly or the nightly debugguer branch?

Anyway, you can see them by adding a watch.
But the interface is not the same on all versions so I can't say more.

For your second problem, divide by 0 throw exceptions. Why not correct the problem? (But I don't think you should ask on this point here as it is not related to C::B's use. Or I didn't understand everything.)

Offline Story

  • Single posting newcomer
  • *
  • Posts: 9
Re: View variables in arrays and variables in other classes?
« Reply #2 on: July 14, 2011, 03:47:12 pm »
If you have the debugger running, just type print and the name of the variable you want to print.

The other option is to throw printfs or std::couts everywhere.
« Last Edit: July 14, 2011, 03:48:45 pm by Story »

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: View variables in arrays and variables in other classes?
« Reply #3 on: July 14, 2011, 04:40:34 pm »
After reading around for the past few days and talking to other programmers at work (I work in Quality Assurance), it seems I need to do some sort of memory dump and then I should be able to read the values off that?  Not super sure how to do that, nor am I looking forward to sifting through piles of hex code :(

How do I find the values of my arrays at various points in my program should I use a break point?
Yes, you need a breakpoint...

So the steps are:
1. put a breakpoint, at the place where you want to see the values of the array
2. start the debugger (f8, debug->Start)
3. wait for the debugger and debuggee to reach the breakpoint
4. when breakpoint is reached, open the watches window and add the array as watch
5. right click on the watch and choose properties
6. set the "watch as array" and set the count to the number of items you want to see

For best results use the debugger's branch, the normal version is a bit buggy, when dealing with watches...

Also read this: http://wiki.codeblocks.org/index.php?title=Debugging_with_Code::Blocks
(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!]