Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GDB Can't Display Boost uBLAS Matrix?

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!

like image 959
Richard Avatar asked Feb 25 '12 21:02

Richard


2 Answers

One can call

V.operator()(1,1)

in gdb

like image 198
Pushpendre Avatar answered Oct 20 '22 07:10

Pushpendre


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
like image 21
bames53 Avatar answered Oct 20 '22 08:10

bames53