views:

393

answers:

6

I have a class in system-C with some data members as such:

long double x[8];

I'm initializing it in the construction like this:

for (i = 0; i < 8; ++i) {
    x[i] = 0;
}

But the first time I use it in my code I have garbage there.

Because of the way the system is built I can't connect a debugger easily. Are there any methods to set a data breakpoint in the code so that it tells me where in the code the variables were actually changed, but without hooking up a debugger?

Edit: @Prakash: Actually, this is a typo in the question, but not in my code... Thanks!

A: 

Sure, it will be garbage!

The code should have been as

for (i = 0; i < 8; ++i) {
    x[i] = 0;
}

EDIT: Oops, Sorry for underestimating ;)

Prakash
A: 

Just use printk/syslog.

It's old-fashioned, but super duper easy.

Frank Krueger
A: 

@Frank

Actually, that lets me log debug prints to a file. What I'm looking for is something that will let me print something whenever a variable changes, without me explicitly looking for the variable.

Nathan Fellman
A: 

How about Conditional breakpoints? You could try for various conditions like first element value is zero or non zero, etc??

Prakash
A: 

That's assuming I can easily connect a debugger. The whole point is that I only have a library, but the executable that linked it in isn't readily available.

Nathan Fellman
A: 
Adam Rosenfield