Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use pretty debugging printers to see Eigen objects in QtCreator?

Tags:

c++

gdb

qt

eigen

I am trying to see the contents of an Eigen vector in the Locals and Expressions window of the QtCreator:

enter image description here

I see that it is a vector with 10 components:

enter image description here

but when I click it open I get:

enter image description here

I tried to use this script to do the trick. I saved it along with an empty __init__.py file into folder ~/Scripts/Eigen and created the .gdbinit file:

python
import sys
sys.path.insert(0, '/home/martin/Scripts/Eigen')
from printers import register_eigen_printers
register_eigen_printers (None)
end

I restarted QtCreator and nothing changed. I have checked the "read .gdbinit at startup" option in QtCreator settings and still nothing.

What is worrying me is that I know that in the past the viewing of Eigen objects worked without me meddling with some scripts.

Please, what am I doing wrong?

I am using:

gcc version 4.8.1
Ubuntu 13.10
gdb 7.6.1-ubuntu
Qt Creator 3.0.0
Based on Qt 5.2.0

and I am compiling using these flags:

g++ -c -pipe -gdwarf-4 -fvar-tracking-assignments -g 
    -Wall -W -fPIE -DQT_QML_DEBUG -DQT_DECLARATIVE_DEBUG

EDIT:

as @ggael suggested, I tried to run the gdb directly:

(gdb) run
Starting program: /home/martin/Projects/TestGrounds/test 
Traceback (most recent call last):
  File "/usr/lib/debug/usr/lib/i386-linux-gnu/libstdc++.so.6.0.18-gdb.py", line 59, in <module>
    from libstdcxx.v6.printers import register_libstdcxx_printers
ImportError: No module named 'libstdcxx'
Traceback (most recent call last):
  File "/usr/lib/debug/usr/lib/i386-linux-gnu/libstdc++.so.6.0.18-gdb.py", line 59, in <module>
    from libstdcxx.v6.printers import register_libstdcxx_printers
ImportError: No module named 'libstdcxx'

And then:

(gdb) print vec
Python Exception <class 'TypeError'> 'map' object is not subscriptable: 
Python Exception <class 'TypeError'> 'map' object is not subscriptable: 
$1 = {<Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> >> = {<Eigen::MatrixBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> >> = {<Eigen::DenseBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> >> = {<Eigen::internal::special_scalar_op_base<Eigen::Matrix<double, -1, 1, 0, -1, 1>, double, double, false>> = {<Eigen::DenseCoeffsBase<Eigen::Matrix<double, -1, 1, 0, -1, 1>, 3>> = {<Eigen::DenseCoeffsBase<Eigen::Matrix<double, -1, 1, 0, -1, 1>, 1>> = {<Eigen::DenseCoeffsBase<Eigen::Matrix<double, -1, 1, 0, -1, 1>, 0>> = {<Eigen::EigenBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> >> = {<No data fields>}, <No data fields>}, <No data fields>}, <No data fields>}, <No data fields>}, <No data fields>}, <No data fields>}, 
    m_storage = {m_data = 0x804e020, m_rows = 10}}, <No data fields>}

Please, could you explain what does this mean? What is libstdcxx?

like image 523
Martin Drozdik Avatar asked Jan 24 '14 19:01

Martin Drozdik


2 Answers

This is a bug in /usr/lib/debug/usr/lib/i386-linux-gnu/libstdc++.so.6.0.18-gdb.py. Make sure you have the lastest version of the gcc4.8 packages, it might be that this issue is already fixed in unbuntu (it is fixed in debian). See this bug entry. In the last ressort you can patch this file so that it searches in the right location.

like image 154
ggael Avatar answered Oct 16 '22 16:10

ggael


Works for me as expected. The output looks like

vec (10 x 1), ColumnMajor   Eigen::VectorXd
    [0] 3.1400000000000001  double
    [1] 3.1400000000000001  double
    [2] 3.1400000000000001  double
    [3] 3.1400000000000001  double
    [4] 3.1400000000000001  double
    [5] 3.1400000000000001  double
    [6] 3.1400000000000001  double
    [7] 3.1400000000000001  double
    [8] 3.1400000000000001  double
    [9] 3.1400000000000001  double

Make sure to use Qt Creator's own pretty-printing system by removing(!) the checkmark in Tools/Options/Debugger/GDB/Load system pretty printers. You also don't need the code you put into your .gdbinit in this case.

like image 38
Aguest Avatar answered Oct 16 '22 16:10

Aguest