21

I am using the Eigen C++ library downloadable from http://eigen.tuxfamily.org/. This is a C++ library for easier handling of Matrices and Arrays. I use g++ compiler and gdb for debugging. However, I found that I am unable to print the content of a Matrix (provided by Eigen) while using gdb.

3 Answers 3

27

One trick you can use is the .data() member, it gives you a pointer to the raw array that contains the data. With that you can print it in GDB like so:

print *X.data()@Length_X

where X is the eigen variable and Length_X is the product of its rows and columns.

26

You have to install a gdb extension that you can find in eigen/debug/gdb/.

The comment at the beginning of the file explains how to install it.

6
  • Is there something similar for lldb on mac os x? Commented Nov 21, 2016 at 17:51
  • I'm not aware of lldb script yet, but it should be difficult to adapt the gdb one to lldb.
    – ggael
    Commented Nov 23, 2016 at 9:26
  • link in the answer is dead
    – chutsu
    Commented Jan 9, 2018 at 18:05
  • 1
    Can you explain how to install this python file?
    – user650261
    Commented May 25, 2018 at 16:22
  • 2
    I have installed it but it's unclear to me how to use it. Could you provide any info on that? I'm using the eclipse debugger btw
    – C. Binair
    Commented Aug 25, 2021 at 7:23
0

There is a github project specifically for adding eigen printing support to GDB.

It appears to be based on the code linked in this answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.