Skip to content
GitLab
    • Why GitLab
    • Pricing
    • Contact Sales
    • Explore
  • Why GitLab
  • Pricing
  • Contact Sales
  • Explore
  • Sign in
  • Get free trial
  • libeigenlibeigen
  • eigeneigen
  • Issues
  • #1539

Eigen GDB pretty printer does not work for Eigen::Block types

Submitted by Allan Leal

Assigned to Nobody

Link to original bugzilla bug (#1539)
Version: 3.3 (current stable)

Description

Created attachment 848
Fix the GDB pretty printing behavior for matrix and vector block views

When using GDB pretty printers to print views in Eigen matrices and vectors, the contents of the view is not displayed nicely as it is done for Eigen::Matrix, Eigen::Array, etc.

For example:

MatrixXd A = MatrixXd::Random(10, 10);  
  
auto Aview = A.topLeftCorner(3, 3);  

Printing Aview variable (or inspecting it in an IDE like Eclipse, QtCreator, etc.) does not print useful state.

In the attachment to this bug, there is a modified printers.py file that allows matrix and vector blocks to be printed nicely.

The modifications were:

def cast_eigen_block_to_matrix(val):  
	# Get the type of the variable (and convert to a string)  
	# Example: 'const Eigen::Block<Eigen::Block<Eigen::Matrix<double, -1, -1, 0, -1, -1>, -1, -1, false> const, -1, -1, false>'  
	type = str(val.type)  
  
	# Extract the Eigen::Matrix type from the Block:  
	# From the previous example: Eigen::Matrix<double, -1, -1, 0, -1, -1>  
	begin = type.find('Eigen::Matrix<')  
	end = type.find('>', begin) + 1  
  
	# Convert the Eigen::Block to an Eigen::Matrix  
	return val.cast(gdb.lookup_type(type[begin:end]))  
  
def build_eigen_dictionary ():  
	pretty_printers_dict[re.compile('^Eigen::Quaternion<.*>$')] = lambda val: EigenQuaternionPrinter(val)  
	pretty_printers_dict[re.compile('^Eigen::Matrix<.*>$')] = lambda val: EigenMatrixPrinter("Matrix", val)  
	pretty_printers_dict[re.compile('^Eigen::Block<.*>$')] = lambda val: EigenMatrixPrinter("Matrix", cast_eigen_block_to_matrix(val))  
	pretty_printers_dict[re.compile('^Eigen::VectorBlock<.*>$')] = lambda val: EigenMatrixPrinter("Matrix", cast_eigen_block_to_matrix(val))  
	pretty_printers_dict[re.compile('^Eigen::SparseMatrix<.*>$')] = lambda val: EigenSparseMatrixPrinter(val)  
	pretty_printers_dict[re.compile('^Eigen::Array<.*>$')]  = lambda val: EigenMatrixPrinter("Array",  val)  

Attachment 848, "Fix the GDB pretty printing behavior for matrix and vector block views":
printers.py

Edited Dec 05, 2019 by Eigen Bugzilla
Assignee
Assign to
Time tracking