Eigen3 and Clion: How to display matrix contents in Clion ide?
Asked Answered
D

2

6

I have followed the instructions for updating my GDB for use with Eigen3. However, the CLion IDE is unable to load the contents of eigen matrices in the debug panel.

What should be a quick validation and debug process of results is turning into a time consuming manual print process (or worse: running gdb in interactive mode in cygwin's terminal).

There must be a way to enable eigen to be used with clion's debugger?

Dammar answered 4/2, 2020 at 15:24 Comment(1)
Could you manage to do this? I've tried few things but couldn't make it work.Bourque
A
6

There is quite a simple way @Chris and anyone else looking for a solution using GDB, CLion, I tested it on ubuntu but it should work on any system.

enter image description here enter image description here

Part of the solution is already in the eigen repository, just needs a bit of tweaking.

Eigen printers

What I changed is the python module import logic:

  1. Save printers.py to a newly created printers directory under any directory of your choosing, lets say /any_full_path/printers
  2. make sure you create and empty __init__.py
  3. Create a ~/.gdbinit in your home directory
  4. Copy paste the slightly changed(from the original repo) script below
python
import sys
sys.path.insert(0, '/any_full_path/printers')
from printers import register_eigen_printers
register_eigen_printers(None)
end

Feel free to ask for more screenshots or other clarification, caus that should work simply like a charm.

Archaize answered 16/1, 2022 at 9:26 Comment(1)
1) In my case I had to place .gdbinit in the root directory of my project, not in my home. 2) pay attention to warnings in the GDB tab of the debug window. It can have useful information such as the need to update auto-load safe-path before .gdbinit is taken into accountCrat
B
0

I've managed to make lldb work in CLion using this project on windows: https://github.com/fantaosha/LLDB-Eigen-Pretty-Printer

You need to create .lldbinit in your home directory and add similar line:

command script import "C:\Users\user.lldb-eigen-data-formatter\LLDB_Eigen_Pretty_Printer.py" (ofc this folder and file needs to be cloned as per the readme on github)

Now Clion will import this script bit you will get some errors, you need to remove the question mark in the regular expressions as described here: https://github.com/fantaosha/LLDB-Eigen-Pretty-Printer/issues/4#issuecomment-747329527 Now CLion will be able to show you the matrix, vector etc. values (but without newline - at least on windows).

For gdb specifically it should be what uta answered but I haven't tried it because I'm using lldb. Maybe you can try changing the debugger to lldb if you don't use anything specific related to that. Hope this helps in some way!

Bourque answered 17/12, 2020 at 10:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.