Commit b351cc97953e8a1713bef53be36cab6199a7614b

  • avatar
  • con <qtc-committer @no…a.com> (Committer)
  • Wed Nov 25 16:57:22 CET 2009
  • avatar
  • Friedemann Kleint (Author)
  • Wed Nov 25 16:32:44 CET 2009
Debugger/CDB: Windows 64 integer handling.

Convert CDB unsigned integer values should they appear in hex,
make format flexible.
Use int64 for reformatting integers to be able to accommodate
64 bit values on Windows 64. Add some more integer types.
Do not save decimal type formats. Add menu option to clear
individual formatting. Do not use map[] to query the type formats
(inserting 0 everywhere as a side effect).

Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@nokia.com>
(cherry picked from commit 2b23ea2a8ac8166820b76476b18fd7fd7014e695)
  
402402}
403403
404404// Return hexadecimal pointer value from a CDB pointer value
405// which look like "0x000032a" or "0x00000000`0250124a" on 64-bit systems.
406static bool inline getPointerValue(QString stringValue, quint64 *value)
405// which look like "0x000032a" or "0x00000000`0250124a" or
406// "0x1`0250124a" on 64-bit systems.
407static bool inline getUnsignedHexValue(QString stringValue, quint64 *value)
407408{
408409 *value = 0;
409410 if (!stringValue.startsWith(QLatin1String("0x")))
410411 return false;
411412 stringValue.remove(0, 2);
412413 // Remove 64bit separator
413 if (stringValue.size() > 8 && stringValue.at(8) == QLatin1Char('`'))
414 stringValue.remove(8, 1);
414 if (stringValue.size() > 9) {
415 const int sepPos = stringValue.size() - 9;
416 if (stringValue.at(sepPos) == QLatin1Char('`'))
417 stringValue.remove(sepPos, 1);
418 }
415419 bool ok;
416420 *value = stringValue.toULongLong(&ok, 16);
417421 return ok;
431431 if (blankPos != -1)
432432 stringValue.truncate(blankPos);
433433 quint64 value;
434 return getPointerValue(stringValue, &value) && value == 0u;
434 return getUnsignedHexValue(stringValue, &value) && value == 0u;
435435}
436436
437437// Fix a symbol group value. It is set to the class type for
449449 return value;
450450}
451451
452static inline QString fixValue(const QString &value)
452// Fix display values: Pass through strings, convert unsigned integers
453// to decimal ('0x5454`fedf'), remove inner templates from
454// "0x4343 class list<>".
455static inline QString fixValue(const QString &value, const QString &type)
453456{
454 if (value.size() < 20 || value.endsWith(QLatin1Char('"')))
457 if (value.endsWith(QLatin1Char('"'))) // Pass through strings
455458 return value;
456 return removeInnerTemplateType(value);
459 const int size = value.size();
460 // Unsigned hex numbers
461 if (isIntType(type) && (size > 2 && value.at(1) == QLatin1Char('x'))) {
462 quint64 intValue;
463 if (getUnsignedHexValue(value, &intValue))
464 return QString::number(intValue);
465 }
466 return size < 20 ? value : removeInnerTemplateType(value);
457467}
458468
459469WatchData CdbSymbolGroupContext::watchDataAt(unsigned long index) const
495495 return wd;
496496 }
497497 const QString value = getSymbolString(m_symbolGroup, &IDebugSymbolGroup2::GetSymbolValueTextWide, index);
498 wd.setValue(fixValue(value));
498 wd.setValue(fixValue(value, type));
499499 wd.setChildrenNeeded(); // compensate side effects of above setters
500500 // Figure out children. The SubElement is only a guess unless the symbol,
501501 // is expanded, so, we leave this as a guess for later updates.
743743
744744// Get pointer value of symbol group ("0xAAB")
745745// Note that this is on "00000000`0250124a" on 64bit systems.
746static inline bool getPointerValue(CIDebugSymbolGroup *sg, int index, quint64 *value)
746static inline bool getUnsignedHexValue(CIDebugSymbolGroup *sg, int index, quint64 *value)
747747{
748748 const QString stringValue = getSymbolString(sg, &IDebugSymbolGroup2::GetSymbolValueTextWide, index);
749 return getPointerValue(stringValue, value);
749 return getUnsignedHexValue(stringValue, value);
750750}
751751
752752int CdbSymbolGroupContext::dumpQString(CIDebugDataSpaces *ds, WatchData *wd)
770770 if (!getIntValue(m_symbolGroup, sizeIndex, &size))
771771 return 4;
772772 quint64 array;
773 if (!getPointerValue(m_symbolGroup, arrayIndex, &array))
773 if (!getUnsignedHexValue(m_symbolGroup, arrayIndex, &array))
774774 return 5;
775775 // Fetch
776776 const bool truncated = size > maxLength;
  
588588 return type;
589589}
590590
591template <class IntType> QString reformatInteger(IntType value, int format)
592{
593 switch (format) {
594 case HexadecimalFormat:
595 return ("(hex) ") + QString::number(value, 16);
596 case BinaryFormat:
597 return ("(bin) ") + QString::number(value, 2);
598 case OctalFormat:
599 return ("(oct) ") + QString::number(value, 8);
600 }
601 return QString::number(value); // not reached
602}
603
591604static QString formattedValue(const WatchData &data,
592605 int individualFormat, int typeFormat)
593606{
594607 if (isIntType(data.type)) {
595 int format = individualFormat == -1 ? typeFormat : individualFormat;
596 int value = data.value.toInt();
597 if (format == HexadecimalFormat)
598 return ("(hex) ") + QString::number(value, 16);
599 if (format == BinaryFormat)
600 return ("(bin) ") + QString::number(value, 2);
601 if (format == OctalFormat)
602 return ("(oct) ") + QString::number(value, 8);
603 return data.value;
608 const int format = individualFormat == -1 ? typeFormat : individualFormat;
609 if (format <= 0)
610 return data.value;
611 if (data.type.contains(QLatin1String("unsigned"))) {
612 return reformatInteger(data.value.toULongLong(), format);
613 } else {
614 return reformatInteger(data.value.toLongLong(), format);
615 }
604616 }
605
606617 return data.value;
607618}
608619
780780 break;
781781
782782 case TypeFormatRole:
783 return m_handler->m_typeFormats[data.type];
784
785 case IndividualFormatRole: {
786 int format = m_handler->m_individualFormats[data.iname];
787 if (format == -1)
788 return m_handler->m_typeFormats[data.type];
789 return format;
790 }
791
783 return m_handler->m_typeFormats.value(data.type, -1);
784 case IndividualFormatRole:
785 return m_handler->m_individualFormats.value(data.iname, -1);
792786 case AddressRole: {
793787 if (!data.addr.isEmpty())
794788 return data.addr;
812812 }
813813 } else if (role == TypeFormatRole) {
814814 m_handler->setFormat(data.type, value.toInt());
815 } else if (role == IndividualFormatRole) {
816 m_handler->m_individualFormats[data.iname] = value.toInt();
815 } else if (role == IndividualFormatRole) {
816 const int format = value.toInt();
817 if (format == -1) {
818 m_handler->m_individualFormats.remove(data.iname);
819 } else {
820 m_handler->m_individualFormats[data.iname] = format;
821 }
817822 }
818823 emit dataChanged(index, index);
819824 return true;
13831383 QHashIterator<QString, int> it(m_typeFormats);
13841384 while (it.hasNext()) {
13851385 it.next();
1386 QString key = it.key().trimmed();
1387 if (!key.isEmpty())
1388 typeFormats.insert(key, it.value());
1386 const int format = it.value();
1387 if (format != DecimalFormat) {
1388 const QString key = it.key().trimmed();
1389 if (!key.isEmpty())
1390 typeFormats.insert(key, format);
1391 }
13891392 }
13901393 m_manager->setSessionValue("DefaultFormats", QVariant(typeFormats));
13911394}
  
542542 << QLatin1String("long") << QLatin1String("bool")
543543 << QLatin1String("signed char") << QLatin1String("unsigned")
544544 << QLatin1String("unsigned char") << QLatin1String("unsigned long")
545 << QLatin1String("long long") << QLatin1String("unsigned long long");
546 return type.endsWith(QLatin1String(" int")) || types.contains(type);
545 << QLatin1String("long long") << QLatin1String("unsigned long long")
546 << QLatin1String("qint16") << QLatin1String("quint16")
547 << QLatin1String("qint32") << QLatin1String("quint32")
548 << QLatin1String("qint64") << QLatin1String("quint64");
549 return type.endsWith(QLatin1String(" int"))
550 || type.endsWith(QLatin1String(" int64"))
551 || types.contains(type);
547552}
548553
549554bool isSymbianIntType(const QString &type)
  
210210
211211 QStringList alternativeFormats =
212212 model()->data(mi0, TypeFormatListRole).toStringList();
213 int typeFormat =
214 model()->data(mi0, TypeFormatRole).toInt();
215 int individualFormat =
216 model()->data(mi0, IndividualFormatRole).toInt();
213 const int typeFormat = qMax(int(DecimalFormat), model()->data(mi0, TypeFormatRole).toInt());
214 const int individualFormat = model()->data(mi0, IndividualFormatRole).toInt();
215 const int effectiveIndividualFormat = individualFormat == -1 ? typeFormat : individualFormat;
217216
218217 QMenu typeFormatMenu;
219218 QMenu individualFormatMenu;
220219 QList<QAction *> typeFormatActions;
221220 QList<QAction *> individualFormatActions;
221 QAction *clearIndividualFormatAction = 0;
222222 if (idx.isValid()) {
223223 typeFormatMenu.setTitle(tr("Change format for type '%1'").arg(type));
224224 individualFormatMenu.setTitle(tr("Change format for expression '%1'").arg(exp));
225 for (int i = 0; i != alternativeFormats.size(); ++i) {
226 const QString format = alternativeFormats.at(i);
227 QAction *act = new QAction(format, &typeFormatMenu);
228 act->setCheckable(true);
229 if (i == typeFormat)
230 act->setChecked(true);
231 typeFormatMenu.addAction(act);
232 typeFormatActions.append(act);
233 act = new QAction(format, &individualFormatMenu);
234 act->setCheckable(true);
235 if (i == individualFormat)
236 act->setChecked(true);
237 individualFormatMenu.addAction(act);
238 individualFormatActions.append(act);
239 }
240225 if (alternativeFormats.isEmpty()) {
241226 typeFormatMenu.setEnabled(false);
242227 individualFormatMenu.setEnabled(false);
228 } else {
229 clearIndividualFormatAction = individualFormatMenu.addAction(tr("Clear"));
230 clearIndividualFormatAction->setEnabled(individualFormat != -1);
231 individualFormatMenu.addSeparator();
232 for (int i = 0; i != alternativeFormats.size(); ++i) {
233 const QString format = alternativeFormats.at(i);
234 QAction *act = new QAction(format, &typeFormatMenu);
235 act->setCheckable(true);
236 if (i == typeFormat)
237 act->setChecked(true);
238 typeFormatMenu.addAction(act);
239 typeFormatActions.append(act);
240 act = new QAction(format, &individualFormatMenu);
241 act->setCheckable(true);
242 if (i == effectiveIndividualFormat)
243 act->setChecked(true);
244 individualFormatMenu.addAction(act);
245 individualFormatActions.append(act);
246 }
243247 }
244248 } else {
245249 typeFormatMenu.setTitle(tr("Change format for type"));
320320 m_grabbing = true;
321321 } else if (act == actClearCodeModelSnapshot) {
322322 m_manager->clearCppCodeModelSnapshot();
323 } else if (clearIndividualFormatAction && act == clearIndividualFormatAction) {
324 model()->setData(mi1, -1, IndividualFormatRole);
323325 } else {
324326 for (int i = 0; i != alternativeFormats.size(); ++i) {
325327 if (act == typeFormatActions.at(i))