This bugzilla service is closed. All entries have been migrated to
Bug 1539 - Eigen GDB pretty printer does not work for Eigen::Block types
Summary: Eigen GDB pretty printer does not work for Eigen::Block types
Status: NEW
Alias: None
Product: Eigen
Classification: Unclassified
Component: Core - general (show other bugs)
Version: 3.3 (current stable)
Hardware: All All
: Normal Feature Request
Assignee: Nobody
Depends on:
Reported: 2018-04-09 08:03 UTC by Allan Leal
Modified: 2019-12-04 17:36 UTC (History)
3 users (show)

Fix the GDB pretty printing behavior for matrix and vector block views (10.09 KB, text/x-python)
2018-04-09 08:03 UTC, Allan Leal
no flags Details

Description Allan Leal 2018-04-09 08:03:09 UTC
Created attachment 848 [details]
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 `` 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)
Comment 1 Nobody 2019-12-04 17:36:52 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance:

Note You need to log in before you can comment on or make changes to this bug.