Debugger [CDB]: Enable Assignment to string classes.

Assign to QString/QByteArray following gdbmacros.py
implementation (call resize if required, copy data into buffer).

Assign to std::[w]string only it has sufficient memory
(since std::string<>.resize cannot be called).
This commit is contained in:
Friedemann Kleint
2011-05-17 12:19:24 +02:00
parent ab3ab3264e
commit 581765055d
11 changed files with 429 additions and 33 deletions

View File

@@ -1261,6 +1261,15 @@ void CdbEngine::handleJumpToLineAddressResolution(const CdbBuiltinCommandPtr &cm
}
}
static inline bool isAsciiWord(const QString &s)
{
foreach (const QChar &c, s) {
if (!c.isLetterOrNumber() || c.toAscii() == 0)
return false;
}
return true;
}
void CdbEngine::assignValueInDebugger(const WatchData *w, const QString &expr, const QVariant &value)
{
if (debug)
@@ -1270,10 +1279,28 @@ void CdbEngine::assignValueInDebugger(const WatchData *w, const QString &expr, c
qWarning("Internal error: assignValueInDebugger: Invalid state or no stack frame.");
return;
}
QByteArray cmd;
ByteArrayInputStream str(cmd);
str << m_extensionCommandPrefixBA << "assign " << w->iname << '=' << value.toString();
switch (value.type()) {
case QVariant::String: {
// Convert qstring to Utf16 data not considering endianness for Windows.
const QString s = value.toString();
if (isAsciiWord(s)) {
str << m_extensionCommandPrefixBA << "assign \"" << w->iname << '='
<< s.toLatin1() << '"';
} else {
const QByteArray utf16(reinterpret_cast<const char *>(s.utf16()), 2 * s.size());
str << m_extensionCommandPrefixBA << "assign -u " << w->iname << '='
<< utf16.toHex();
}
}
break;
default:
str << m_extensionCommandPrefixBA << "assign " << w->iname << '='
<< value.toString();
break;
}
postCommand(cmd, 0);
// Update all locals in case we change a union or something pointed to
// that affects other variables, too.