Question

I have a successfully compiled program using Boost's implementation of uBLAS matricies. Alas, debugging with gdb is proving problematic as I could find no way to see the contents of my matrices while debugging. When I try to see an element of a matrix V (which does exist and is full of data), I get:

(gdb) print V(1,1)
Invalid data type for function to be called.

Is there a way around this?

Thanks!

Was it helpful?

Solution

This is because GDB doesn't support calling the overloaded operator(). It's trying to just call V as a function, and it's not a function. You can write a freestanding function that you pass the matrix to and calls the operator:

int get_element(matrix const &m,int i,int j) {
    return m(i,j);
}

(gdb) p get_element(V,1,1)
(int) $0 = 43.1

and GDB should be able to call that

You can also try to manually examine the representation of V in order to manually pull out the value you want. That's probably going to be hard with types that use a lot of templates or meta-programming though.

If you happen to be working on a platform that is supported by LLDB, it supports calling operator overloads.

struct foo {
    int operator()(int i,int j) {
        return 10;
    }
};

(lldb) p f(1,1)
(int) $0 = 10

OTHER TIPS

One can call

V.operator()(1,1)

in gdb

I found this thread when looking for a solution for this problem. The proposed solution works fine. However, you could also use the at_element method of ublas matrices.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top