2

I'm trying to debug with GDB using conditional breakpoints on an Eigen object. For instance, I'd like to break when any values in my vector are nonzero. I would do this in GDB:

break cpp/File.cpp:143 if (v != 0).any()

However, this doesn't work. GDB gives this:

Could not find operator!=

even though this is perfectly valid syntax. Moreover, a conditional breakpoint like

break cpp/File.cpp:143 if v[0] != 0

gives this error in GDB:

Error in testing breakpoint condition:
Couldn't get registers: No such process.
An error occurred while in a function called from GDB.
Evaluation of the expression containing the function
(Eigen::DenseCoeffsBase<Eigen::Array<int, 3, 1, 0, 3, 1>, 1>::operator[](long)) will be abandoned.
When the function is done executing, GDB will silently stop.

The code was compiled with -O0 -g -fno-inline. How do I debug the contents of an Eigen object?

Eric Taw
  • 321
  • 3
  • 12
  • Thanks. I'm compiling with the Eigen source, not with the library. – Eric Taw May 29 '19 at 17:53
  • @JesperJuhl Just for clarification: Eigen is header-only, i.e., not compiled separately. Eric: Can you provide a [mcve]? – chtz May 29 '19 at 20:13

1 Answers1

0

According to this question, (sometimes) GDB seems to have problems with overloaded operators. You could try one of these alternatives:

if (! v.isZero())

if (! v.cwiseEqual(0).all()) 

And instead of if v[0] != 0 you could try one of these:

 if (v.data()[0] != 0)

 if (v.coeff(0) != 0)
chtz
  • 17,329
  • 4
  • 26
  • 56