add Eigen::Array support to GDB pretty printers

This commit is contained in:
Rhys Ulerich 2012-02-11 20:50:21 -06:00
parent 7de3478027
commit ef448da57b

View File

@ -47,10 +47,14 @@ import itertools
class EigenMatrixPrinter: class EigenMatrixPrinter:
"Print Eigen Matrix of some kind" "Print Eigen Matrix or Array of some kind"
def __init__(self, val): def __init__(self, variety, val):
"Extract all the necessary information" "Extract all the necessary information"
# Save the variety (presumably "Matrix" or "Array") for later usage
self.variety = variety
# The gdb extension does not support value template arguments - need to extract them by hand # The gdb extension does not support value template arguments - need to extract them by hand
type = val.type type = val.type
if type.code == gdb.TYPE_CODE_REF: if type.code == gdb.TYPE_CODE_REF:
@ -135,7 +139,7 @@ class EigenMatrixPrinter:
return self._iterator(self.rows, self.cols, self.data, self.rowMajor) return self._iterator(self.rows, self.cols, self.data, self.rowMajor)
def to_string(self): def to_string(self):
return "Eigen::Matrix<%s,%d,%d,%s> (data ptr: %s)" % (self.innerType, self.rows, self.cols, "RowMajor" if self.rowMajor else "ColMajor", self.data) return "Eigen::%s<%s,%d,%d,%s> (data ptr: %s)" % (self.variety, self.innerType, self.rows, self.cols, "RowMajor" if self.rowMajor else "ColMajor", self.data)
class EigenQuaternionPrinter: class EigenQuaternionPrinter:
"Print an Eigen Quaternion" "Print an Eigen Quaternion"
@ -184,7 +188,8 @@ class EigenQuaternionPrinter:
def build_eigen_dictionary (): def build_eigen_dictionary ():
pretty_printers_dict[re.compile('^Eigen::Quaternion<.*>$')] = lambda val: EigenQuaternionPrinter(val) pretty_printers_dict[re.compile('^Eigen::Quaternion<.*>$')] = lambda val: EigenQuaternionPrinter(val)
pretty_printers_dict[re.compile('^Eigen::Matrix<.*>$')] = lambda val: EigenMatrixPrinter(val) pretty_printers_dict[re.compile('^Eigen::Matrix<.*>$')] = lambda val: EigenMatrixPrinter("Matrix", val)
pretty_printers_dict[re.compile('^Eigen::Array<.*>$')] = lambda val: EigenMatrixPrinter("Array", val)
def register_eigen_printers(obj): def register_eigen_printers(obj):
"Register eigen pretty-printers with objfile Obj" "Register eigen pretty-printers with objfile Obj"