diff --git a/src/plugins/debugger/debuggerprotocol.h b/src/plugins/debugger/debuggerprotocol.h index 7f3bcd9653f..1e743633f0b 100644 --- a/src/plugins/debugger/debuggerprotocol.h +++ b/src/plugins/debugger/debuggerprotocol.h @@ -316,7 +316,9 @@ enum DisplayFormat CharCodeIntegerFormat = 28, // Frontend internal only CompactFloatFormat = 26, // Frontend internal only - ScientificFloatFormat = 27 // Frontend internal only + ScientificFloatFormat = 27, // Frontend internal only + HexFloatFormat = 29, // Frontend internal only + NormalizedTwoFloatFormat = 30, // Frontend internal only }; diff --git a/src/plugins/debugger/watchdata.cpp b/src/plugins/debugger/watchdata.cpp index cf49aa250d4..b5036f34ed2 100644 --- a/src/plugins/debugger/watchdata.cpp +++ b/src/plugins/debugger/watchdata.cpp @@ -628,6 +628,19 @@ QString WatchItem::sourceExpression() const return QString("%1.%2").arg(p->sourceExpression(), name); } +int WatchItem::guessSize() const +{ + if (size != 0) + return size; + if (type == "double") + return 8; + if (type == "float") + return 4; + if (type == "qfloat16") + return 2; + return 0; +} + } // namespace Internal } // namespace Debugger diff --git a/src/plugins/debugger/watchdata.h b/src/plugins/debugger/watchdata.h index 5cfddead45c..aa668009303 100644 --- a/src/plugins/debugger/watchdata.h +++ b/src/plugins/debugger/watchdata.h @@ -65,6 +65,7 @@ public: bool isValid() const { return !iname.isEmpty(); } bool isVTablePointer() const; + int guessSize() const; void setError(const QString &); void setValue(const QString &); diff --git a/src/plugins/debugger/watchhandler.cpp b/src/plugins/debugger/watchhandler.cpp index 6c9d7db78bf..bc1e57206c1 100644 --- a/src/plugins/debugger/watchhandler.cpp +++ b/src/plugins/debugger/watchhandler.cpp @@ -63,6 +63,7 @@ #include #include #include +#include #include #include #include @@ -80,7 +81,10 @@ #include #include +#include #include +#include + #include using namespace Core; @@ -770,6 +774,32 @@ static QString formattedValue(const WatchItem *item) return QString::number(dd, 'g'); } + if (format == HexFloatFormat) { + double dd = item->value.toDouble(); + std::ostringstream ss; + ss << std::hexfloat; + switch (item->guessSize()) { + case 2: ss << qfloat16(dd); break; + case 4: ss << float(dd); break; + default: ss << dd; break; + } + return QString::fromStdString(ss.str()); + } + + if (format == NormalizedTwoFloatFormat) { + double dd = item->value.toDouble(); + std::ostringstream ss; + int pow2_exp; + double norm = std::frexp(dd, &pow2_exp); + int numDecimalDigits = 12; + switch (item->guessSize()) { + case 2: numDecimalDigits = 4; break; + case 4: numDecimalDigits = 8; break; + default: break; + } + return QString::number(norm, 'f', numDecimalDigits) + " * 2^" + QString::number(pow2_exp); + } + if (item->type == "va_list") return item->value; @@ -992,6 +1022,8 @@ static DisplayFormats typeFormatList(const WatchItem *item) if (ok) { formats.append(CompactFloatFormat); formats.append(ScientificFloatFormat); + formats.append(HexFloatFormat); + formats.append(NormalizedTwoFloatFormat); } // Fixed artificial integral types. @@ -2084,6 +2116,8 @@ QString WatchModel::nameForFormat(int format) case CompactFloatFormat: return tr("Compact Float"); case ScientificFloatFormat: return tr("Scientific Float"); + case HexFloatFormat: return tr("Hexadecimal Float"); + case NormalizedTwoFloatFormat: return tr("Normalized, with Power-of-Two Exponent"); } QTC_CHECK(false);