Registered Member
|
Hi,
when I have a subscript range error I get a failing assertion. But unfortunately this error message doesn't tell me neither the name of the object nor the line in my source code. That's a bit hard for any non-trivial source code. Of course, the name of the variable isn't available at run time (but see below). I am not sure if one can get hold of the line number of the source code where the exception occurs. One possible help that I included in my matrix lib is to offer a method 'set_name' like VectorXd V(5); ..... V.set_name('V in main') which sets a member like V.__name__ alternatively I can say Vector V(5,"V in main"); When a subscript check error occurs I display this name unless it's the empty string as it is initialized in the constructor. Of course, this member isn't present in NDEBUG mode and the method '.set_name' is a no-op (with full inlining) Just a suggestion. Helmut. |
Registered Member
|
What you want is a debugger Here's an example with GCC and GDB: First compile your program; the default options should produce more than enough debug info, but you can always add "-g3", it sometimes helps:
Launch gdb on your program:
Tell gdb to run your program:
Once your program has crashed on the failed assertion, ask gdb to produce the backtrace:
Now you should see the full backtrace, with line numbers, function names, parameters, everything Sometimes you have to press a key to see the rest of the backtrace.
Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list! |
Registered Member
|
That's not normal! We use the standard assert() macro that's part of the standard library. It is the job of your compiler and its implementation of the standard library, to output at least the function name, file name, and line number. Here with GCC it does. Just one thing: disable all optimization! If you're using MSVC, use the "Debug" mode. You can even go further and forcibly disable all inlining, e.g. with GCC the option would be -fno-inline.
Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list! |
Registered Member
|
Unfortunately this doesn't work for me:
Here my test #include // import most common Eigen types USING_PART_OF_NAMESPACE_EIGEN int main() { VectorXd V(2); V(2)= 2; // force an exception } compiled with gcc-4.3.3 like g++ -fno-inline -I /usr/include/eigen2 Eigen2_EX0.C a.out gives (with or without -fno-inline) a.out: /usr/include/eigen2/Eigen/src/Core/Coeffs.h:202: typename Eigen::ei_traits::Scalar& Eigen::MatrixBase::operator()(int) [with Derived = Eigen::Matrix]: Assertion `index >= 0 && index < size()' failed. There is no reference to my program. Using a debugger is only 'last resort' and will be done only AFTER the code failed. |
Registered Member
|
Sorry the example was wrong (though I wonder what operator() for a vector is)
But even the changed example #include // import most common Eigen types USING_PART_OF_NAMESPACE_EIGEN int main() { VectorXd V(2); V[2]= 2; // force an exception } gives: a.out: /usr/include/eigen2/Eigen/src/Core/Coeffs.h:186: typename Eigen::ei_traits::Scalar& Eigen::MatrixBase::operator[](int) [with Derived = Eigen::Matrix]: Assertion `index >= 0 && index < size()' failed. |
Registered Member
|
Aaah you produced an executable in the old "a.out" format! By default, if you don't pass the -o option to specify output name, g++ will generate an "a.out" executable. That's not just a default filename, that's a wholly different fileformat! You need to produce an ELF executable. To that effect, all you need to do is to pass the -o option, like i showed you in my 1st reply. To check whether your executable is ELF, open it with any text editor, you should see the letters ELF near the beginning.
Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list! |
Registered Member
|
So what's wrong with that? You got the file name, line number, and function name. What more do you want? The backtrace, I suppose. For that you really need to use gdb, and then indeed the a.out vs. ELF might be the reason why you were having trouble, see my previous answer.
Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list! |
Registered users: Bing [Bot], Evergrowing, Google [Bot], rblackwell