mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-08-11 11:19:02 +08:00
add Eigen::Array support to GDB pretty printers
This commit is contained in:
parent
7de3478027
commit
ef448da57b
@ -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:
|
||||||
@ -61,7 +65,7 @@ class EigenMatrixPrinter:
|
|||||||
m = regex.findall(tag)[0][1:-1]
|
m = regex.findall(tag)[0][1:-1]
|
||||||
template_params = m.split(',')
|
template_params = m.split(',')
|
||||||
template_params = map(lambda x:x.replace(" ", ""), template_params)
|
template_params = map(lambda x:x.replace(" ", ""), template_params)
|
||||||
|
|
||||||
if template_params[1] == '-0x00000000000000001' or template_params[1] == '-0x000000001':
|
if template_params[1] == '-0x00000000000000001' or template_params[1] == '-0x000000001':
|
||||||
self.rows = val['m_storage']['m_rows']
|
self.rows = val['m_storage']['m_rows']
|
||||||
else:
|
else:
|
||||||
@ -77,9 +81,9 @@ class EigenMatrixPrinter:
|
|||||||
self.options = template_params[3];
|
self.options = template_params[3];
|
||||||
|
|
||||||
self.rowMajor = (int(self.options) & 0x1)
|
self.rowMajor = (int(self.options) & 0x1)
|
||||||
|
|
||||||
self.innerType = self.type.template_argument(0)
|
self.innerType = self.type.template_argument(0)
|
||||||
|
|
||||||
self.val = val
|
self.val = val
|
||||||
|
|
||||||
# Fixed size matrices have a struct as their storage, so we need to walk through this
|
# Fixed size matrices have a struct as their storage, so we need to walk through this
|
||||||
@ -96,12 +100,12 @@ class EigenMatrixPrinter:
|
|||||||
self.currentRow = 0
|
self.currentRow = 0
|
||||||
self.currentCol = 0
|
self.currentCol = 0
|
||||||
self.rowMajor = rowMajor
|
self.rowMajor = rowMajor
|
||||||
|
|
||||||
def __iter__ (self):
|
def __iter__ (self):
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def next(self):
|
def next(self):
|
||||||
|
|
||||||
row = self.currentRow
|
row = self.currentRow
|
||||||
col = self.currentCol
|
col = self.currentCol
|
||||||
if self.rowMajor == 0:
|
if self.rowMajor == 0:
|
||||||
@ -121,7 +125,7 @@ class EigenMatrixPrinter:
|
|||||||
self.currentCol = 0
|
self.currentCol = 0
|
||||||
self.currentRow = self.currentRow + 1
|
self.currentRow = self.currentRow + 1
|
||||||
|
|
||||||
|
|
||||||
item = self.dataPtr.dereference()
|
item = self.dataPtr.dereference()
|
||||||
self.dataPtr = self.dataPtr + 1
|
self.dataPtr = self.dataPtr + 1
|
||||||
if (self.cols == 1): #if it's a column vector
|
if (self.cols == 1): #if it's a column vector
|
||||||
@ -129,17 +133,17 @@ class EigenMatrixPrinter:
|
|||||||
elif (self.rows == 1): #if it's a row vector
|
elif (self.rows == 1): #if it's a row vector
|
||||||
return ('[%d]' % (col,), item)
|
return ('[%d]' % (col,), item)
|
||||||
return ('[%d,%d]' % (row, col), item)
|
return ('[%d,%d]' % (row, col), item)
|
||||||
|
|
||||||
def children(self):
|
def children(self):
|
||||||
|
|
||||||
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"
|
||||||
|
|
||||||
def __init__(self, val):
|
def __init__(self, val):
|
||||||
"Extract all the necessary information"
|
"Extract all the necessary information"
|
||||||
# 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
|
||||||
@ -159,18 +163,18 @@ class EigenQuaternionPrinter:
|
|||||||
self.dataPtr = dataPtr
|
self.dataPtr = dataPtr
|
||||||
self.currentElement = 0
|
self.currentElement = 0
|
||||||
self.elementNames = ['x', 'y', 'z', 'w']
|
self.elementNames = ['x', 'y', 'z', 'w']
|
||||||
|
|
||||||
def __iter__ (self):
|
def __iter__ (self):
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def next(self):
|
def next(self):
|
||||||
element = self.currentElement
|
element = self.currentElement
|
||||||
|
|
||||||
if self.currentElement >= 4: #there are 4 elements in a quanternion
|
if self.currentElement >= 4: #there are 4 elements in a quanternion
|
||||||
raise StopIteration
|
raise StopIteration
|
||||||
|
|
||||||
self.currentElement = self.currentElement + 1
|
self.currentElement = self.currentElement + 1
|
||||||
|
|
||||||
item = self.dataPtr.dereference()
|
item = self.dataPtr.dereference()
|
||||||
self.dataPtr = self.dataPtr + 1
|
self.dataPtr = self.dataPtr + 1
|
||||||
return ('[%s]' % (self.elementNames[element],), item)
|
return ('[%s]' % (self.elementNames[element],), item)
|
||||||
@ -178,13 +182,14 @@ class EigenQuaternionPrinter:
|
|||||||
def children(self):
|
def children(self):
|
||||||
|
|
||||||
return self._iterator(self.data)
|
return self._iterator(self.data)
|
||||||
|
|
||||||
def to_string(self):
|
def to_string(self):
|
||||||
return "Eigen::Quaternion<%s> (data ptr: %s)" % (self.innerType, self.data)
|
return "Eigen::Quaternion<%s> (data ptr: %s)" % (self.innerType, self.data)
|
||||||
|
|
||||||
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"
|
||||||
@ -195,22 +200,22 @@ def register_eigen_printers(obj):
|
|||||||
|
|
||||||
def lookup_function(val):
|
def lookup_function(val):
|
||||||
"Look-up and return a pretty-printer that can print va."
|
"Look-up and return a pretty-printer that can print va."
|
||||||
|
|
||||||
type = val.type
|
type = val.type
|
||||||
|
|
||||||
if type.code == gdb.TYPE_CODE_REF:
|
if type.code == gdb.TYPE_CODE_REF:
|
||||||
type = type.target()
|
type = type.target()
|
||||||
|
|
||||||
type = type.unqualified().strip_typedefs()
|
type = type.unqualified().strip_typedefs()
|
||||||
|
|
||||||
typename = type.tag
|
typename = type.tag
|
||||||
if typename == None:
|
if typename == None:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
for function in pretty_printers_dict:
|
for function in pretty_printers_dict:
|
||||||
if function.search(typename):
|
if function.search(typename):
|
||||||
return pretty_printers_dict[function](val)
|
return pretty_printers_dict[function](val)
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
pretty_printers_dict = {}
|
pretty_printers_dict = {}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user