File indexing completed on 2024-04-21 05:41:53
0001 # Copyright 2014 Alex Merry <alex.merry@kde.org> 0002 # 0003 # Permission to use, copy, modify, and distribute this software 0004 # and its documentation for any purpose and without fee is hereby 0005 # granted, provided that the above copyright notice appear in all 0006 # copies and that both that the copyright notice and this 0007 # permission notice and warranty disclaimer appear in supporting 0008 # documentation, and that the name of the author not be used in 0009 # advertising or publicity pertaining to distribution of the 0010 # software without specific, written prior permission. 0011 # 0012 # The author disclaims all warranties with regard to this 0013 # software, including all implied warranties of merchantability 0014 # and fitness. In no event shall the author be liable for any 0015 # special, indirect or consequential damages or any damages 0016 # whatsoever resulting from loss of use, data or profits, whether 0017 # in an action of contract, negligence or other tortious action, 0018 # arising out of or in connection with the use or performance of 0019 # this software. 0020 0021 import gdb.printing 0022 0023 """Qt5 Type Information 0024 0025 Since the QTypeInfo information is not necessarily available at debug time, this 0026 module contains useful type information about standard and Qt types (such as 0027 whether a type is movable) that is necessary for the operation of the printers. 0028 This information allows the QList printer, for example, to determine how the 0029 elements are stored in the list. 0030 """ 0031 0032 primitive_types = set([ 0033 'HB_FixedPoint', 0034 'HB_GlyphAttributes', 0035 'QCharAttributes', 0036 'QFlag', 0037 'QIncompatibleFlag', 0038 'QRegExpAnchorAlternation', 0039 'QRegExpAtom', 0040 'QRegExpCharClassRange', 0041 'QStaticPlugin', 0042 'QStringRef', 0043 'QTzType', 0044 'QUuid' 0045 ]) 0046 """Primitive (non-template) types. 0047 0048 This does not need to include compiler-primitive types (like int). 0049 0050 If you use the Q_DECLARE_TYPEINFO macro with Q_PRIMITIVE_TYPE flag, you 0051 should add the type to this set. This is particularly important for 0052 types that are the same size as a pointer or smaller. 0053 """ 0054 0055 primitive_tpl_types = set(['QFlags']) 0056 """Primitive template types. 0057 0058 If you use the Q_DECLARE_TYPEINFO_BODY macro with Q_PRIMITIVE_TYPE flag 0059 on a type with template parameters, you should add the type to this 0060 set. This is particularly important for types that are the same size as 0061 a pointer or smaller. 0062 0063 Entries should just be the base typename, without any template 0064 parameters (eg: "QFlags", rather than "QFlags<T>"). 0065 """ 0066 0067 movable_types = set([ 0068 'QBasicTimer', 0069 'QBitArray', 0070 'QByteArray', 0071 'QChar', 0072 'QCharRef', 0073 'QCustomTypeInfo', 0074 'QDate', 0075 'QDateTime', 0076 'QFileInfo', 0077 'QEasingCurve', 0078 'QFileSystemWatcherPathKey', 0079 'QHashDummyValue', 0080 'QItemSelectionRange', 0081 'QLatin1String', 0082 'QLine', 0083 'QLineF', 0084 'QLocale', 0085 'QLoggingRule', 0086 'QMargins', 0087 'QMarginsF', 0088 'QMetaClassInfo', 0089 'QMetaEnum', 0090 'QMetaMethod', 0091 'QMimeMagicRule', 0092 'QModelIndex', 0093 'QPersistentModelIndex', 0094 'QObjectPrivate::Connection', 0095 'QObjectPrivate::Sender', 0096 'QPoint', 0097 'QPointF', 0098 'QPostEvent', 0099 'QProcEnvKey', 0100 'QProcEnvValue', 0101 'QRect', 0102 'QRectF', 0103 'QRegExp', 0104 'QRegExpAutomatonState', 0105 'QRegExpCharClass', 0106 'QResourceRoot', 0107 'QSize', 0108 'QSizeF', 0109 'QString', 0110 'QStringList', 0111 'QTime', 0112 'QTimeZone::OffsetData', 0113 'QUrl', 0114 'QVariant', 0115 'QXmlStreamAttribute', 0116 'QXmlStreamEntityDeclaration', 0117 'QXmlStreamNamespaceDeclaration', 0118 'QXmlStreamNotationDeclaration' 0119 ]) 0120 """Movable (non-template) types. 0121 0122 If you use the Q_DECLARE_TYPEINFO macro with Q_MOVABLE_TYPE flag, you 0123 should add the type to this set. This is particularly important for 0124 types that are the same size as a pointer or smaller. 0125 """ 0126 0127 movable_tpl_types = set([ 0128 'QExplicitlySharedDataPointer', 0129 'QLinkedList', 0130 'QList', 0131 'QPointer', 0132 'QQueue', 0133 'QSet', 0134 'QSharedDataPointer', 0135 'QSharedPointer', 0136 'QStack', 0137 'QVector', 0138 'QWeakPointer' 0139 ]) 0140 """Movable template types. 0141 0142 If you use the Q_DECLARE_TYPEINFO_BODY macro with Q_MOVABLE_TYPE flag 0143 on a type with template parameters, you should add the type to this 0144 set. This is particularly important for types that are the same size as 0145 a pointer or smaller. 0146 0147 Entries should just be the base typename, without any template 0148 parameters (eg: "QFlags", rather than "QFlags<T>"). 0149 """ 0150 0151 static_types = set() 0152 """Static (non-template) types. 0153 0154 If you define a custom type that is neither primitive nor movable, you 0155 can add the type to this set to indicate this. This is particularly 0156 important for types that are the same size as a pointer or smaller. 0157 """ 0158 0159 static_tpl_types = set() 0160 """Static template types. 0161 0162 If you define a custom type with template parameters that is neither 0163 primitive nor movable, you can add the type to this set to indicate 0164 this. This is particularly important for types that are the same size as 0165 a pointer or smaller. 0166 0167 Entries should just be the base typename, without any template 0168 parameters (eg: "QFlags", rather than "QFlags<T>"). 0169 """ 0170 0171 def type_is_known_primitive(typ): 0172 """Returns True if the given gdb type is known to be primitive.""" 0173 if typ.code == gdb.TYPE_CODE_PTR or typ.code == gdb.TYPE_CODE_INT or typ.code == gdb.TYPE_CODE_FLT or typ.code == gdb.TYPE_CODE_CHAR or typ.code == gdb.TYPE_CODE_BOOL: 0174 return True 0175 pos = typ.name.find('<') 0176 if pos > 0: 0177 return typ.name[0:pos] in primitive_tpl_types 0178 else: 0179 return typ.name in primitive_types 0180 0181 def type_is_known_movable(typ): 0182 """Returns True if the given gdb type is known to be movable.""" 0183 pos = typ.name.find('<') 0184 if pos > 0: 0185 return typ.name[0:pos] in movable_tpl_types 0186 else: 0187 return typ.name in movable_types 0188 0189 def type_is_known_static(typ): 0190 """Returns True if the given gdb type is known to be neither primitive nor movable.""" 0191 pos = typ.name.find('<') 0192 if pos > 0: 0193 return typ.name[0:pos] in static_tpl_types 0194 else: 0195 return typ.name in static_types 0196 0197 meta_type_unknown = 0 0198 """The unknown/invalid meta type ID.""" 0199 meta_type_user = 1024 0200 """The starting value for custom type IDs.""" 0201 meta_type_ids = { 0202 'bool': 1, 0203 'int': 2, 0204 'uint': 3, 0205 'qlonglong': 4, 0206 'qulonglong': 5, 0207 'double': 6, 0208 'QChar': 7, 0209 'QVariantMap': 8, 0210 'QVariantList': 9, 0211 'QString': 10, 0212 'QStringList': 11, 0213 'QByteArray': 12, 0214 'QBitArray': 13, 0215 'QDate': 14, 0216 'QTime': 15, 0217 'QDateTime': 16, 0218 'QUrl': 17, 0219 'QLocale': 18, 0220 'QRect': 19, 0221 'QRectF': 20, 0222 'QSize': 21, 0223 'QSizeF': 22, 0224 'QLine': 23, 0225 'QLineF': 24, 0226 'QPoint': 25, 0227 'QPointF': 26, 0228 'QRegExp': 27, 0229 'QVariantHash': 28, 0230 'QEasingCurve': 29, 0231 'QUuid': 30, 0232 'void*': 31, 0233 'long': 32, 0234 'short': 33, 0235 'char': 34, 0236 'ulong': 35, 0237 'ushort': 36, 0238 'uchar': 37, 0239 'float': 38, 0240 'QObject*': 39, 0241 'signed char': 40, 0242 'QVariant': 41, 0243 'QModelIndex': 42, 0244 'void': 43, 0245 'QRegularExpression': 44, 0246 'QJsonValue': 45, 0247 'QJsonObject': 46, 0248 'QJsonArray': 47, 0249 'QJsonDocument': 48, 0250 'QFont': 64, 0251 'QPixmap': 65, 0252 'QBrush': 66, 0253 'QColor': 67, 0254 'QPalette': 68, 0255 'QIcon': 69, 0256 'QImage': 70, 0257 'QPolygon': 71, 0258 'QRegion': 72, 0259 'QBitmap': 73, 0260 'QCursor': 74, 0261 'QKeySequence': 75, 0262 'QPen': 76, 0263 'QTextLength': 77, 0264 'QTextFormat': 78, 0265 'QMatrix': 79, 0266 'QTransform': 80, 0267 'QMatrix4x4': 81, 0268 'QVector2D': 82, 0269 'QVector3D': 83, 0270 'QVector4D': 84, 0271 'QQuaternion': 85, 0272 'QPolygonF': 86, 0273 'QSizePolicy': 121 0274 } 0275 """Map from type names to meta type IDs.""" 0276 meta_type_names = { 0277 1: 'bool', 0278 2: 'int', 0279 3: 'uint', 0280 4: 'qlonglong', 0281 5: 'qulonglong', 0282 6: 'double', 0283 7: 'QChar', 0284 8: 'QVariantMap', 0285 9: 'QVariantList', 0286 10: 'QString', 0287 11: 'QStringList', 0288 12: 'QByteArray', 0289 13: 'QBitArray', 0290 14: 'QDate', 0291 15: 'QTime', 0292 16: 'QDateTime', 0293 17: 'QUrl', 0294 18: 'QLocale', 0295 19: 'QRect', 0296 20: 'QRectF', 0297 21: 'QSize', 0298 22: 'QSizeF', 0299 23: 'QLine', 0300 24: 'QLineF', 0301 25: 'QPoint', 0302 26: 'QPointF', 0303 27: 'QRegExp', 0304 28: 'QVariantHash', 0305 29: 'QEasingCurve', 0306 30: 'QUuid', 0307 31: 'void*', 0308 32: 'long', 0309 33: 'short', 0310 34: 'char', 0311 35: 'ulong', 0312 36: 'ushort', 0313 37: 'uchar', 0314 38: 'float', 0315 39: 'QObject*', 0316 40: 'signed char', 0317 41: 'QVariant', 0318 42: 'QModelIndex', 0319 43: 'void', 0320 44: 'QRegularExpression', 0321 45: 'QJsonValue', 0322 46: 'QJsonObject', 0323 47: 'QJsonArray', 0324 48: 'QJsonDocument', 0325 64: 'QFont', 0326 65: 'QPixmap', 0327 66: 'QBrush', 0328 67: 'QColor', 0329 68: 'QPalette', 0330 69: 'QIcon', 0331 70: 'QImage', 0332 71: 'QPolygon', 0333 72: 'QRegion', 0334 73: 'QBitmap', 0335 74: 'QCursor', 0336 75: 'QKeySequence', 0337 76: 'QPen', 0338 77: 'QTextLength', 0339 78: 'QTextFormat', 0340 79: 'QMatrix', 0341 80: 'QTransform', 0342 81: 'QMatrix4x4', 0343 82: 'QVector2D', 0344 83: 'QVector3D', 0345 84: 'QVector4D', 0346 85: 'QQuaternion', 0347 86: 'QPolygonF', 0348 121: 'QSizePolicy' 0349 } 0350 """Map from meta type IDs to type names."""