This forum has been archived. All content is frozen. Please use KDE Discuss instead.

debugging help ?

Tags: None
(comma "," separated)
HWJ
Registered Member
Posts
18
Karma
0

debugging help ?

Fri Feb 20, 2009 1:28 pm
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.
User avatar
bjacob
Registered Member
Posts
658
Karma
3

RE: debugging help ?

Fri Feb 20, 2009 1:41 pm
HWJ wrote: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.


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:

Code: Select all
gcc -g3 -I /path/to/eigen2 myprogram.cpp -o myprogram


Launch gdb on your program:

Code: Select all
gdb ./myprogram


Tell gdb to run your program:

Code: Select all
run


Once your program has crashed on the failed assertion, ask gdb to produce the backtrace:

Code: Select all
bt


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!
User avatar
bjacob
Registered Member
Posts
658
Karma
3

RE: debugging help ?

Fri Feb 20, 2009 1:45 pm
HWJ wrote: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.


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!
HWJ
Registered Member
Posts
18
Karma
0

RE: debugging help ?

Fri Feb 20, 2009 1:59 pm
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.
HWJ
Registered Member
Posts
18
Karma
0

RE: debugging help ?

Fri Feb 20, 2009 2:07 pm
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.
User avatar
bjacob
Registered Member
Posts
658
Karma
3

RE: debugging help ?

Fri Feb 20, 2009 2:18 pm
HWJ wrote:g++ -fno-inline -I /usr/include/eigen2 Eigen2_EX0.C


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!
User avatar
bjacob
Registered Member
Posts
658
Karma
3

RE: debugging help ?

Fri Feb 20, 2009 2:23 pm
HWJ wrote: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.


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!


Bookmarks



Who is online

Registered users: Bing [Bot], Evergrowing, Google [Bot], rblackwell