Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 import gdb
00039 import re
00040 import itertools
00041
00042
00043 class EigenMatrixPrinter:
00044 "Print Eigen Matrix of some kind"
00045
00046 def __init__(self, val):
00047 "Extract all the necessary information"
00048
00049 type = val.type
00050 if type.code == gdb.TYPE_CODE_REF:
00051 type = type.target()
00052 self.type = type.unqualified().strip_typedefs()
00053 tag = self.type.tag
00054 regex = re.compile('<.*>')
00055 m = regex.findall(tag)[0][1:-1]
00056 template_params = m.split(',')
00057 template_params = map(lambda x:x.replace(" ", ""), template_params)
00058
00059 if template_params[1] == '-0x00000000000000001' or template_params[1] == '-0x000000001':
00060 self.rows = val['m_storage']['m_rows']
00061 else:
00062 self.rows = int(template_params[1])
00063
00064 if template_params[2] == '-0x00000000000000001' or template_params[2] == '-0x000000001':
00065 self.cols = val['m_storage']['m_cols']
00066 else:
00067 self.cols = int(template_params[2])
00068
00069 self.options = 0
00070 if len(template_params) > 3:
00071 self.options = template_params[3];
00072
00073 self.rowMajor = (int(self.options) & 0x1)
00074
00075 self.innerType = self.type.template_argument(0)
00076
00077 self.val = val
00078
00079
00080 self.data = self.val['m_storage']['m_data']
00081 if self.data.type.code == gdb.TYPE_CODE_STRUCT:
00082 self.data = self.data['array']
00083 self.data = self.data.cast(self.innerType.pointer())
00084
00085 class _iterator:
00086 def __init__ (self, rows, cols, dataPtr, rowMajor):
00087 self.rows = rows
00088 self.cols = cols
00089 self.dataPtr = dataPtr
00090 self.currentRow = 0
00091 self.currentCol = 0
00092 self.rowMajor = rowMajor
00093
00094 def __iter__ (self):
00095 return self
00096
00097 def next(self):
00098
00099 row = self.currentRow
00100 col = self.currentCol
00101 if self.rowMajor == 0:
00102 if self.currentCol >= self.cols:
00103 raise StopIteration
00104
00105 self.currentRow = self.currentRow + 1
00106 if self.currentRow >= self.rows:
00107 self.currentRow = 0
00108 self.currentCol = self.currentCol + 1
00109 else:
00110 if self.currentRow >= self.rows:
00111 raise StopIteration
00112
00113 self.currentCol = self.currentCol + 1
00114 if self.currentCol >= self.cols:
00115 self.currentCol = 0
00116 self.currentRow = self.currentRow + 1
00117
00118
00119 item = self.dataPtr.dereference()
00120 self.dataPtr = self.dataPtr + 1
00121 if (self.cols == 1):
00122 return ('[%d]' % (row,), item)
00123 elif (self.rows == 1):
00124 return ('[%d]' % (col,), item)
00125 return ('[%d,%d]' % (row, col), item)
00126
00127 def children(self):
00128
00129 return self._iterator(self.rows, self.cols, self.data, self.rowMajor)
00130
00131 def to_string(self):
00132 return "Eigen::Matrix<%s,%d,%d,%s> (data ptr: %s)" % (self.innerType, self.rows, self.cols, "RowMajor" if self.rowMajor else "ColMajor", self.data)
00133
00134 class EigenQuaternionPrinter:
00135 "Print an Eigen Quaternion"
00136
00137 def __init__(self, val):
00138 "Extract all the necessary information"
00139
00140 type = val.type
00141 if type.code == gdb.TYPE_CODE_REF:
00142 type = type.target()
00143 self.type = type.unqualified().strip_typedefs()
00144 self.innerType = self.type.template_argument(0)
00145 self.val = val
00146
00147
00148 self.data = self.val['m_coeffs']['m_storage']['m_data']['array']
00149 self.data = self.data.cast(self.innerType.pointer())
00150
00151 class _iterator:
00152 def __init__ (self, dataPtr):
00153 self.dataPtr = dataPtr
00154 self.currentElement = 0
00155 self.elementNames = ['x', 'y', 'z', 'w']
00156
00157 def __iter__ (self):
00158 return self
00159
00160 def next(self):
00161 element = self.currentElement
00162
00163 if self.currentElement >= 4:
00164 raise StopIteration
00165
00166 self.currentElement = self.currentElement + 1
00167
00168 item = self.dataPtr.dereference()
00169 self.dataPtr = self.dataPtr + 1
00170 return ('[%s]' % (self.elementNames[element],), item)
00171
00172 def children(self):
00173
00174 return self._iterator(self.data)
00175
00176 def to_string(self):
00177 return "Eigen::Quaternion<%s> (data ptr: %s)" % (self.innerType, self.data)
00178
00179 def build_eigen_dictionary ():
00180 pretty_printers_dict[re.compile('^Eigen::Quaternion<.*>$')] = lambda val: EigenQuaternionPrinter(val)
00181 pretty_printers_dict[re.compile('^Eigen::Matrix<.*>$')] = lambda val: EigenMatrixPrinter(val)
00182
00183 def register_eigen_printers(obj):
00184 "Register eigen pretty-printers with objfile Obj"
00185
00186 if obj == None:
00187 obj = gdb
00188 obj.pretty_printers.append(lookup_function)
00189
00190 def lookup_function(val):
00191 "Look-up and return a pretty-printer that can print va."
00192
00193 type = val.type
00194
00195 if type.code == gdb.TYPE_CODE_REF:
00196 type = type.target()
00197
00198 type = type.unqualified().strip_typedefs()
00199
00200 typename = type.tag
00201 if typename == None:
00202 return None
00203
00204 for function in pretty_printers_dict:
00205 if function.search(typename):
00206 return pretty_printers_dict[function](val)
00207
00208 return None
00209
00210 pretty_printers_dict = {}
00211
00212 build_eigen_dictionary ()