Using GDB with Eigen C++ library
Asked Answered
S

3

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.

Susumu answered 1/8, 2014 at 17:18 Comment(0)
V
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.

Vociferous answered 1/8, 2014 at 20:32 Comment(6)
Is there something similar for lldb on mac os x?Hypogastrium
I'm not aware of lldb script yet, but it should be difficult to adapt the gdb one to lldb.Vociferous
link in the answer is deadApe
Can you explain how to install this python file?Profit
It's explained in the file itself!Vociferous
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 btwCalcariferous
S
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.

Sunbonnet answered 20/2, 2015 at 8:25 Comment(0)
V
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.

Vociferous answered 1/8, 2014 at 20:32 Comment(6)
Is there something similar for lldb on mac os x?Hypogastrium
I'm not aware of lldb script yet, but it should be difficult to adapt the gdb one to lldb.Vociferous
link in the answer is deadApe
Can you explain how to install this python file?Profit
It's explained in the file itself!Vociferous
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 btwCalcariferous
B
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.

Brad answered 11/6, 2022 at 20:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.