简体   繁体   English

将 GDB 与 Eigen C++ 库一起使用

[英]Using GDB with Eigen C++ library

I am using the Eigen C++ library downloadable from http://eigen.tuxfamily.org/ .我正在使用可从http://eigen.tuxfamily.org/下载的 Eigen C++ 库。 This is a C++ library for easier handling of Matrices and Arrays. I use g++ compiler and gdb for debugging.这是一个 C++ 库,用于更轻松地处理矩阵和 Arrays。我使用 g++ 编译器和 gdb 进行调试。 However, I found that I am unable to print the content of a Matrix (provided by Eigen) while using gdb.但是,我发现在使用 gdb 时无法打印 Matrix(由 Eigen 提供)的内容。

One trick you can use is the .data() member, it gives you a pointer to the raw array that contains the data.您可以使用的一个技巧是 .data() 成员,它为您提供一个指向包含数据的原始数组的指针。 With that you can print it in GDB like so:有了它,您可以像这样在 GDB 中打印它:

print *X.data()@Length_X

where X is the eigen variable and Length_X is the product of its rows and columns.其中 X 是特征变量,Length_X 是其行和列的乘积。

You have to install a gdb extension that you can find in eigen/debug/gdb/ .您必须安装可以在eigen/debug/gdb/ 中找到的 gdb 扩展。

The comment at the beginning of the file explains how to install it.文件开头的注释解释了如何安装它。

There is a github project specifically for adding eigen printing support to GDB.有一个github项目专门为GDB添加eigen打印支持。

It appears to be based on the code linked in this answer .它似乎基于此答案中链接的代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM