Hello,
I am using a C++ library that provides an object that, for the sake of simplicity, is more or less like this:
class ExampleSO {
public double* narray;
};
I have an instance of ExampleSO
whose narray
is about 200. Some other method ExampleSO::method()
does a lot of arithmetic functions with this array and assigns it to different array elements:
ExampleSO::method() {
// a lot of operations
narray[50] = narray[1] * narray[2] / narray[40];
// and so on
This code is generated by another program and it uses a bunch of defines to handle the array elements, so the code looks like this:
#define A narray[0]
#define X narray[1]
#define Y narray[2]
// ...
#define Z narray[40]
// ....
#define U narray[50]
// ... more, until narray[199]
ExampleSO::method() {
// a lot of operations
U = X * Y / Z;
// and so on
}
My problem is that eventually some array elements are NaN and I am trying to debug the code to see why. I have already found out some of them, which are mainly caused by divisions by zero, others by exponentiation by very small numbers (small as in between 0 and +/-0.1).
With my little knowledge of gdb magic, I managed to see the array elements by display *(this->narray) @ 200
, but this array is very big and therefore, unreadable.
So debugging this piece of code has turned out to be a bundersome task, because the #defines
hide me the position of the element, the array is way too big and because so many elements become NaN that I get lost.
My question is: what ideas/suggestions do you have to help me debug this code? Perhaps a conditional breakpoint when the first array element becomes NaN would be useful? How could I do that with such structure?
Thanks!