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

3

11

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?

Atlantean answered 24/1, 2014 at 19:27 Comment(6)
Boy wouldn't that be nice!?! =)Helmet
It works nicely for we with QtCreator 2.8.1/Qt4.8.6/gcc-4.8/gdb-7.6 (Debian). First, make sure it works when using gdb directly.Tote
Also, the .gdbinit must be in your home (/home/martin/.gdbinit).Tote
What of your used tools (gcc, ...) have you changed from the day when it had worked until now?Tolyl
@Tolyl I think I just upgraded Ubuntu and the debugging window got broken completely. I then installed the latest QtCreator and I got the partial results that I have now.Atlantean
@Tote Yes, I have the .gdbinit in the path you suggest.Atlantean
A
1

The problem was probably in the debugger itself. I tried out many combinations of

  1. load \ do not load .gdbinit
  2. load \ do not load system pretty printers
  3. use \ don't use code model
  4. -gdwarf-x compiler flags

and none of this really mattered. Then I tried a fresh install of Ubuntu 12.04 with old GDB 7.4 and a brand new QtCreator 3.0.1 and it worked! I got the same results for gcc 4.6, gcc 4.7 and gcc 4.8.1.

Then I tried the newest GDB 7.7 on Ubuntu 13.10 and again it worked, while GDB 7.5, GDB 7.6 did not work.

Also a strange thing, std::shared_ptr is correctly viewed only in QtCreator 3.0.1.

std::multimap is not pretty printed in any configuration.

#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <memory>

#include <eigen3/Eigen/Dense>

int main(int argc, char *argv[])
{
    std::vector<int> vec(4, 3);
    std::map<int, std::string> map =        {{1,"one"},{2,"two"},{3,"three"}};
    std::multimap<int, std::string> multi = {{1,"one"},{2,"two"},{3,"three"}};

    Eigen::VectorXd vector = Eigen::VectorXd::Constant(3, 3.14);
    std::shared_ptr<Eigen::VectorXd> pointer(new Eigen::VectorXd(vector));

    std::cout << vector << std::endl;
    return 0;
}

enter image description here

Atlantean answered 26/2, 2014 at 23:24 Comment(0)
T
5

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.

Tote answered 28/1, 2014 at 22:32 Comment(3)
So is it a problem in the gcc? Should I upgrade to 4.8.2?Atlantean
Upgrading might indeed fix the issue.Tote
Thank you for your answer! However the problem was probably in the version of GDB I was using. See https://mcmap.net/q/1022159/-how-to-use-pretty-debugging-printers-to-see-eigen-objects-in-qtcreatorAtlantean
F
2

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.

Footlocker answered 8/2, 2014 at 10:7 Comment(1)
Thank you for your answer. I solved the issue. I don't think it had something to do with the QtCreator settings, see https://mcmap.net/q/1022159/-how-to-use-pretty-debugging-printers-to-see-eigen-objects-in-qtcreatorAtlantean
A
1

The problem was probably in the debugger itself. I tried out many combinations of

  1. load \ do not load .gdbinit
  2. load \ do not load system pretty printers
  3. use \ don't use code model
  4. -gdwarf-x compiler flags

and none of this really mattered. Then I tried a fresh install of Ubuntu 12.04 with old GDB 7.4 and a brand new QtCreator 3.0.1 and it worked! I got the same results for gcc 4.6, gcc 4.7 and gcc 4.8.1.

Then I tried the newest GDB 7.7 on Ubuntu 13.10 and again it worked, while GDB 7.5, GDB 7.6 did not work.

Also a strange thing, std::shared_ptr is correctly viewed only in QtCreator 3.0.1.

std::multimap is not pretty printed in any configuration.

#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <memory>

#include <eigen3/Eigen/Dense>

int main(int argc, char *argv[])
{
    std::vector<int> vec(4, 3);
    std::map<int, std::string> map =        {{1,"one"},{2,"two"},{3,"three"}};
    std::multimap<int, std::string> multi = {{1,"one"},{2,"two"},{3,"three"}};

    Eigen::VectorXd vector = Eigen::VectorXd::Constant(3, 3.14);
    std::shared_ptr<Eigen::VectorXd> pointer(new Eigen::VectorXd(vector));

    std::cout << vector << std::endl;
    return 0;
}

enter image description here

Atlantean answered 26/2, 2014 at 23:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.