Debugging Eigen in VSCode
Asked Answered
S

1

7

During debugging I'd like to have access to eigen matrices and vectors values. It seems that once I have a .natvis file, a custom view of c++ object could be created. There is a .natvis file for Eigen here, however I don't know a way to integrate it with VSCode. I also tried a gdb extension but didn't work out.

Current debugger view

How can I do that? Or what other solution do I have?

Subscapular answered 19/10, 2019 at 14:48 Comment(2)
@SumitDey I think I have done something wrong then! It is working now.Subscapular
@SumitDey Would you mind writing a tutorial for that so I can mark your answer as right answer?Subscapular
V
3

GDB Extension

It is basic but supports fixed size as well as dynamic size matrices, and should suffice for ordinary use cases. Result: Expect to view Eigen matrices on VS Code as the sample here.


Setup (linux)

  1. Copy / create required files:
wget -P ~/gdbExtensions/ "https://bitbucket.org/eigen/eigen/raw/default/debug/gdb/printers.py"
touch ~/gdbExtensions/__init__.py
  1. Add extension to the .gdbinit (replace <USER> with username; basically provide absolute path to ~/gdbExtensions):
echo -en "\
python \n\
import sys \n\
sys.path.insert(0, '/home/<USER>/gdbExtensions') \n\
from printers import register_eigen_printers \n\
register_eigen_printers (None) \n\
end\n" >> ~/.gdbinit

The above info is available in the file documentation.

Villasenor answered 10/12, 2019 at 16:37 Comment(2)
Above links are no longer functioning. The gdb debug printers.py can be found here instead: gitlab.com/libeigen/eigen/-/tree/master/debug/gdb. See also the question: #25085965.Landreth
When will the .gdbinit be executed? It seems that the .gdbinit file does not work.Vizor

© 2022 - 2024 — McMap. All rights reserved.