forked from qt-creator/qt-creator
Debugger: Simplify gdb output parsing structure
The base problem is that gdb output is weird outside the 7 bit ASCII range. Could be true UTF-8, or \x encoded UTF-8 byte sequences, i.e. three layers of encoding. Change-Id: Id9ee4bd4a8979624f9682f28064c3ac599afe4b9 Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -109,8 +109,6 @@ static bool parseOctalEscapedHelper(DebuggerOutputParser &parser, QByteArray &bu
|
|||||||
{
|
{
|
||||||
if (parser.remainingChars() < 4)
|
if (parser.remainingChars() < 4)
|
||||||
return false;
|
return false;
|
||||||
if (!parser.isCurrent('\\'))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
const char c1 = parser.lookAhead(1).unicode();
|
const char c1 = parser.lookAhead(1).unicode();
|
||||||
const char c2 = parser.lookAhead(2).unicode();
|
const char c2 = parser.lookAhead(2).unicode();
|
||||||
@@ -127,8 +125,6 @@ static bool parseHexEscapedHelper(DebuggerOutputParser &parser, QByteArray &buff
|
|||||||
{
|
{
|
||||||
if (parser.remainingChars() < 4)
|
if (parser.remainingChars() < 4)
|
||||||
return false;
|
return false;
|
||||||
if (!parser.isCurrent('\\'))
|
|
||||||
return false;
|
|
||||||
if (parser.lookAhead(1) != 'x')
|
if (parser.lookAhead(1) != 'x')
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@@ -142,7 +138,7 @@ static bool parseHexEscapedHelper(DebuggerOutputParser &parser, QByteArray &buff
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void parseSimpleEscape(DebuggerOutputParser &parser, QString &result)
|
static void parseSimpleEscape(DebuggerOutputParser &parser, QByteArray &result)
|
||||||
{
|
{
|
||||||
if (parser.isAtEnd()) {
|
if (parser.isAtEnd()) {
|
||||||
qDebug() << "MI Parse Error, unterminated backslash escape";
|
qDebug() << "MI Parse Error, unterminated backslash escape";
|
||||||
@@ -167,23 +163,18 @@ static void parseSimpleEscape(DebuggerOutputParser &parser, QString &result)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reads subsequent \123 or \x12 entities and converts to Utf8,
|
// Reads one \123 or \x12 entity, *or* one escaped char, *or* one unescaped char.
|
||||||
// *or* one escaped char, *or* one unescaped char.
|
static void parseCharOrEscape(DebuggerOutputParser &parser, QByteArray &result)
|
||||||
static void parseCharOrEscape(DebuggerOutputParser &parser, QString &result)
|
|
||||||
{
|
{
|
||||||
QByteArray buffer;
|
if (parser.isCurrent('\\')) {
|
||||||
while (parseOctalEscapedHelper(parser, buffer))
|
if (parseOctalEscapedHelper(parser, result))
|
||||||
;
|
return;
|
||||||
while (parseHexEscapedHelper(parser, buffer))
|
if (parseHexEscapedHelper(parser, result))
|
||||||
;
|
return;
|
||||||
|
|
||||||
if (!buffer.isEmpty()) {
|
|
||||||
result.append(QString::fromUtf8(buffer));
|
|
||||||
} else if (parser.isCurrent('\\')) {
|
|
||||||
parser.advance();
|
parser.advance();
|
||||||
parseSimpleEscape(parser, result);
|
parseSimpleEscape(parser, result);
|
||||||
} else {
|
} else {
|
||||||
result += parser.readChar();
|
result += char(parser.readChar().unicode());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -199,12 +190,12 @@ QString DebuggerOutputParser::readCString()
|
|||||||
}
|
}
|
||||||
|
|
||||||
++from; // Skip initial quote.
|
++from; // Skip initial quote.
|
||||||
QString result;
|
QByteArray result;
|
||||||
result.reserve(30);
|
result.reserve(30);
|
||||||
while (from < to) {
|
while (from < to) {
|
||||||
if (*from == '"') {
|
if (*from == '"') {
|
||||||
++from;
|
++from;
|
||||||
return result;
|
return QString::fromUtf8(result);
|
||||||
}
|
}
|
||||||
parseCharOrEscape(*this, result);
|
parseCharOrEscape(*this, result);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user