forked from qt-creator/qt-creator
Debugger: Remove debuggerstringutils.h
With QT_RESTRICTED_CAST_FROM_ASCII making GdbMi etc operate on QString is feasible again. Take this as opportunity to move debugger encoding handling closer to a 'conversion on input and output if needed, storage in QString only' scheme. Change-Id: I2f10c9fa8a6c62c44f4e6682efe3769e9fba30f7 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -35,21 +35,21 @@
|
||||
namespace Debugger {
|
||||
namespace Internal {
|
||||
|
||||
bool isPointerType(const QByteArray &type)
|
||||
bool isPointerType(const QString &type)
|
||||
{
|
||||
return type.endsWith('*') || type.endsWith("* const");
|
||||
}
|
||||
|
||||
bool isCharPointerType(const QByteArray &type)
|
||||
bool isCharPointerType(const QString &type)
|
||||
{
|
||||
return type == "char *" || type == "const char *" || type == "char const *";
|
||||
}
|
||||
|
||||
bool isIntType(const QByteArray &type)
|
||||
bool isIntType(const QString &type)
|
||||
{
|
||||
if (type.isEmpty())
|
||||
return false;
|
||||
switch (type.at(0)) {
|
||||
switch (type.at(0).unicode()) {
|
||||
case 'b':
|
||||
return type == "bool";
|
||||
case 'c':
|
||||
@@ -97,12 +97,12 @@ bool isIntType(const QByteArray &type)
|
||||
}
|
||||
}
|
||||
|
||||
bool isFloatType(const QByteArray &type)
|
||||
bool isFloatType(const QString &type)
|
||||
{
|
||||
return type == "float" || type == "double" || type == "qreal";
|
||||
}
|
||||
|
||||
bool isIntOrFloatType(const QByteArray &type)
|
||||
bool isIntOrFloatType(const QString &type)
|
||||
{
|
||||
return isIntType(type) || isFloatType(type);
|
||||
}
|
||||
@@ -176,7 +176,7 @@ void WatchItem::setValue(const QString &value0)
|
||||
|
||||
// pointer type information is available in the 'type'
|
||||
// column. No need to duplicate it here.
|
||||
if (value.startsWith(QLatin1Char('(') + QLatin1String(type) + QLatin1String(") 0x")))
|
||||
if (value.startsWith('(' + type + ") 0x"))
|
||||
value = value.section(QLatin1Char(' '), -1, -1);
|
||||
|
||||
setValueUnneeded();
|
||||
@@ -184,7 +184,7 @@ void WatchItem::setValue(const QString &value0)
|
||||
|
||||
enum GuessChildrenResult { HasChildren, HasNoChildren, HasPossiblyChildren };
|
||||
|
||||
static GuessChildrenResult guessChildren(const QByteArray &type)
|
||||
static GuessChildrenResult guessChildren(const QString &type)
|
||||
{
|
||||
if (isIntOrFloatType(type))
|
||||
return HasNoChildren;
|
||||
@@ -197,7 +197,7 @@ static GuessChildrenResult guessChildren(const QByteArray &type)
|
||||
return HasPossiblyChildren;
|
||||
}
|
||||
|
||||
void WatchItem::setType(const QByteArray &str, bool guessChildrenFromType)
|
||||
void WatchItem::setType(const QString &str, bool guessChildrenFromType)
|
||||
{
|
||||
type = str.trimmed();
|
||||
bool changed = true;
|
||||
@@ -242,7 +242,7 @@ QString WatchItem::toString() const
|
||||
str << QLatin1Char('{');
|
||||
if (!iname.isEmpty())
|
||||
str << "iname=\"" << iname << doubleQuoteComma;
|
||||
if (!name.isEmpty() && name != QLatin1String(iname))
|
||||
if (!name.isEmpty() && name != iname)
|
||||
str << "name=\"" << name << doubleQuoteComma;
|
||||
if (address) {
|
||||
str.setIntegerBase(16);
|
||||
@@ -306,11 +306,11 @@ QString WatchItem::shadowedName(const QString &name, int seen)
|
||||
return shadowedNameFormat().arg(name).arg(seen);
|
||||
}
|
||||
|
||||
QByteArray WatchItem::hexAddress() const
|
||||
QString WatchItem::hexAddress() const
|
||||
{
|
||||
if (address)
|
||||
return QByteArray("0x") + QByteArray::number(address, 16);
|
||||
return QByteArray();
|
||||
return "0x" + QString::number(address, 16);
|
||||
return QString();
|
||||
}
|
||||
|
||||
template <class T>
|
||||
@@ -325,9 +325,9 @@ QString decodeItemHelper(const double &t)
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void decodeArrayHelper(WatchItem *item, const QByteArray &rawData, int size, const QByteArray &childType)
|
||||
void decodeArrayHelper(WatchItem *item, const QString &rawData, int size, const QString &childType)
|
||||
{
|
||||
const QByteArray ba = QByteArray::fromHex(rawData);
|
||||
const QByteArray ba = QByteArray::fromHex(rawData.toUtf8());
|
||||
const T *p = (const T *) ba.data();
|
||||
for (int i = 0, n = ba.size() / sizeof(T); i < n; ++i) {
|
||||
WatchItem *child = new WatchItem;
|
||||
@@ -340,8 +340,8 @@ void decodeArrayHelper(WatchItem *item, const QByteArray &rawData, int size, con
|
||||
}
|
||||
}
|
||||
|
||||
static void decodeArrayData(WatchItem *item, const QByteArray &rawData,
|
||||
const DebuggerEncoding &encoding, const QByteArray &childType)
|
||||
static void decodeArrayData(WatchItem *item, const QString &rawData,
|
||||
const DebuggerEncoding &encoding, const QString &childType)
|
||||
{
|
||||
switch (encoding.type) {
|
||||
case DebuggerEncoding::HexEncodedSignedInteger:
|
||||
@@ -426,14 +426,14 @@ void WatchItem::parseHelper(const GdbMi &input, bool maySort)
|
||||
if (iname.startsWith("local.") && iname.count('.') == 1)
|
||||
// Solve one common case of adding 'class' in
|
||||
// *(class X*)0xdeadbeef for gdb.
|
||||
exp = name.toLatin1();
|
||||
exp = name;
|
||||
else
|
||||
exp = "*(" + gdbQuoteTypes(type) + "*)" + hexAddress();
|
||||
}
|
||||
}
|
||||
|
||||
mi = input["value"];
|
||||
QByteArray enc = input["valueencoded"].data();
|
||||
QString enc = input["valueencoded"].data();
|
||||
if (mi.isValid() || !enc.isEmpty()) {
|
||||
setValue(decodeData(mi.data(), enc));
|
||||
} else {
|
||||
@@ -474,7 +474,7 @@ void WatchItem::parseHelper(const GdbMi &input, bool maySort)
|
||||
mi = input["arraydata"];
|
||||
if (mi.isValid()) {
|
||||
DebuggerEncoding encoding(input["arrayencoding"].data());
|
||||
QByteArray childType = input["childtype"].data();
|
||||
QString childType = input["childtype"].data();
|
||||
decodeArrayData(this, mi.data(), encoding, childType);
|
||||
} else {
|
||||
const GdbMi children = input["children"];
|
||||
@@ -495,13 +495,13 @@ void WatchItem::parseHelper(const GdbMi &input, bool maySort)
|
||||
if (childNumChild.isValid())
|
||||
child->setHasChildren(childNumChild.toInt() > 0);
|
||||
GdbMi name = subinput["name"];
|
||||
QByteArray nn;
|
||||
QString nn;
|
||||
if (name.isValid()) {
|
||||
nn = name.data();
|
||||
child->name = QString::fromLatin1(nn);
|
||||
child->name = nn;
|
||||
} else {
|
||||
nn.setNum(i);
|
||||
child->name = QString::fromLatin1("[%1]").arg(i);
|
||||
child->name = QString("[%1]").arg(i);
|
||||
}
|
||||
GdbMi iname = subinput["iname"];
|
||||
if (iname.isValid())
|
||||
@@ -512,7 +512,7 @@ void WatchItem::parseHelper(const GdbMi &input, bool maySort)
|
||||
child->address = addressBase + i * addressStep;
|
||||
child->exp = "*(" + gdbQuoteTypes(child->type) + "*)" + child->hexAddress();
|
||||
}
|
||||
QByteArray key = subinput["key"].data();
|
||||
QString key = subinput["key"].data();
|
||||
if (!key.isEmpty())
|
||||
child->name = decodeData(key, subinput["keyencoded"].data());
|
||||
child->parseHelper(subinput, maySort);
|
||||
@@ -531,14 +531,14 @@ void WatchItem::parse(const GdbMi &data, bool maySort)
|
||||
|
||||
GdbMi wname = data["wname"];
|
||||
if (wname.isValid()) // Happens (only) for watched expressions.
|
||||
name = QString::fromUtf8(QByteArray::fromHex(wname.data()));
|
||||
name = fromHex(wname.data());
|
||||
else
|
||||
name = QString::fromLatin1(data["name"].data());
|
||||
name = data["name"].data();
|
||||
|
||||
parseHelper(data, maySort);
|
||||
|
||||
if (wname.isValid())
|
||||
exp = name.toUtf8();
|
||||
exp = name;
|
||||
}
|
||||
|
||||
WatchItem *WatchItem::parentItem() const
|
||||
@@ -564,14 +564,14 @@ QString WatchItem::toToolTip() const
|
||||
str << "<html><body><table>";
|
||||
formatToolTipRow(str, tr("Name"), name);
|
||||
formatToolTipRow(str, tr("Expression"), expression());
|
||||
formatToolTipRow(str, tr("Internal Type"), QLatin1String(type));
|
||||
formatToolTipRow(str, tr("Internal Type"), type);
|
||||
bool ok;
|
||||
const quint64 intValue = value.toULongLong(&ok);
|
||||
if (ok && intValue) {
|
||||
formatToolTipRow(str, tr("Value"), QLatin1String("(dec) ") + value);
|
||||
formatToolTipRow(str, QString(), QLatin1String("(hex) ") + QString::number(intValue, 16));
|
||||
formatToolTipRow(str, QString(), QLatin1String("(oct) ") + QString::number(intValue, 8));
|
||||
formatToolTipRow(str, QString(), QLatin1String("(bin) ") + QString::number(intValue, 2));
|
||||
formatToolTipRow(str, tr("Value"), "(dec) " + value);
|
||||
formatToolTipRow(str, QString(), "(hex) " + QString::number(intValue, 16));
|
||||
formatToolTipRow(str, QString(), "(oct) " + QString::number(intValue, 8));
|
||||
formatToolTipRow(str, QString(), "(bin) " + QString::number(intValue, 2));
|
||||
} else {
|
||||
QString val = value;
|
||||
if (val.size() > 1000) {
|
||||
@@ -589,7 +589,7 @@ QString WatchItem::toToolTip() const
|
||||
formatToolTipRow(str, tr("Array Index"), QString::number(arrayIndex));
|
||||
if (size)
|
||||
formatToolTipRow(str, tr("Static Object Size"), tr("%n bytes", 0, size));
|
||||
formatToolTipRow(str, tr("Internal ID"), QLatin1String(internalName()));
|
||||
formatToolTipRow(str, tr("Internal ID"), internalName());
|
||||
str << "</table></body></html>";
|
||||
return res;
|
||||
}
|
||||
@@ -627,7 +627,7 @@ quint64 WatchItem::realAddress() const
|
||||
return address;
|
||||
}
|
||||
|
||||
QByteArray WatchItem::internalName() const
|
||||
QString WatchItem::internalName() const
|
||||
{
|
||||
if (arrayIndex >= 0) {
|
||||
if (const WatchItem *p = parentItem())
|
||||
@@ -646,14 +646,14 @@ QString WatchItem::realName() const
|
||||
QString WatchItem::expression() const
|
||||
{
|
||||
if (!exp.isEmpty())
|
||||
return QString::fromLatin1(exp);
|
||||
return exp;
|
||||
if (quint64 addr = realAddress()) {
|
||||
if (!type.isEmpty())
|
||||
return QString::fromLatin1("*(%1*)0x%2").arg(QLatin1String(type)).arg(addr, 0, 16);
|
||||
return QString("*(%1*)0x%2").arg(type).arg(addr, 0, 16);
|
||||
}
|
||||
const WatchItem *p = parentItem();
|
||||
if (p && !p->exp.isEmpty())
|
||||
return QString::fromLatin1("(%1).%2").arg(QString::fromLatin1(p->exp), name);
|
||||
return QString("(%1).%2").arg(p->exp, name);
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user