Debugger[CDB]: Fix disassembler for lines with no offset.

Also add function lines as comment.
Fix offset display.
This commit is contained in:
Friedemann Kleint
2011-04-13 14:31:39 +02:00
parent 292119bb6a
commit 0565acf300
2 changed files with 23 additions and 18 deletions

View File

@@ -469,8 +469,8 @@ QtCored4!QTextStreamPrivate::putString+0x34:
When the source line changes, the source instruction is inserted. When the source line changes, the source instruction is inserted.
*/ */
// Parse a function header line: Match: 'nsp::foo::+0x<offset> [<file> @ <line>]:' // Parse a function header line: Match: 'nsp::foo+0x<offset> [<file> @ <line>]:'
// or 'nsp::foo::+0x<offset>:' // or 'nsp::foo+0x<offset>:', 'nsp::foo [<file> @ <line>]:'
// Do not use regexp here as it is hard for functions like operator+, operator[]. // Do not use regexp here as it is hard for functions like operator+, operator[].
bool parseCdbDisassemblerFunctionLine(const QString &l, bool parseCdbDisassemblerFunctionLine(const QString &l,
QString *currentFunction, quint64 *functionOffset, QString *currentFunction, quint64 *functionOffset,
@@ -478,23 +478,25 @@ bool parseCdbDisassemblerFunctionLine(const QString &l,
{ {
if (l.isEmpty() || !l.endsWith(QLatin1Char(':')) || l.at(0).isDigit() || l.at(0).isSpace()) if (l.isEmpty() || !l.endsWith(QLatin1Char(':')) || l.at(0).isDigit() || l.at(0).isSpace())
return false; return false;
int functionEnd = l.indexOf(QLatin1Char(' '));
if (functionEnd < 0)
functionEnd = l.size() - 1; // Nothing at all, just ':'
const int offsetPos = l.indexOf(QLatin1String("+0x")); const int offsetPos = l.indexOf(QLatin1String("+0x"));
if (offsetPos == -1) if (offsetPos > 0) {
return false;
sourceFile->clear();
*currentFunction = l.left(offsetPos); *currentFunction = l.left(offsetPos);
if (!l.endsWith(QLatin1String("]:"))) { // No source file. *functionOffset = l.mid(offsetPos + 3, functionEnd - offsetPos - 3).trimmed().toULongLong(0, 16);
*functionOffset = l.mid(offsetPos + 3, l.size() - offsetPos - 4).trimmed().toULongLong(0, 16); } else { // No offset, directly at beginning.
if (debugDisAsm) *currentFunction = l.left(functionEnd);
qDebug() << "Function:" << l << currentFunction << functionOffset; *functionOffset = 0;
return true;
} }
sourceFile->clear();
// Parse file and line. // Parse file and line.
const int filePos = l.indexOf(QLatin1Char('['), offsetPos + 1); const int filePos = l.indexOf(QLatin1Char('['), functionEnd);
const int linePos = filePos != -1 ? l.indexOf(QLatin1String(" @ "), filePos + 1) : -1; if (filePos == -1)
return true; // No file
const int linePos = l.indexOf(QLatin1String(" @ "), filePos + 1);
if (linePos == -1) if (linePos == -1)
return false; return false;
*functionOffset = l.mid(offsetPos + 3, filePos - offsetPos - 4).trimmed().toULongLong(0, 16);
*sourceFile = l.mid(filePos + 1, linePos - filePos - 1).trimmed(); *sourceFile = l.mid(filePos + 1, linePos - filePos - 1).trimmed();
if (debugDisAsm) if (debugDisAsm)
qDebug() << "Function with source: " << l << currentFunction qDebug() << "Function with source: " << l << currentFunction
@@ -555,9 +557,12 @@ DisassemblerLines parseCdbDisassembler(const QList<QByteArray> &a)
foreach (const QByteArray &lineBA, a) { foreach (const QByteArray &lineBA, a) {
const QString line = QString::fromLatin1(lineBA); const QString line = QString::fromLatin1(lineBA);
// New function? // New function. Append as comment line.
if (parseCdbDisassemblerFunctionLine(line, &currentFunction, &functionOffset, &sourceFile)) { if (parseCdbDisassemblerFunctionLine(line, &currentFunction, &functionOffset, &sourceFile)) {
functionAddress = 0; functionAddress = 0;
DisassemblerLine commentLine;
commentLine.data = line;
result.appendLine(commentLine);
} else { } else {
DisassemblerLine disassemblyLine; DisassemblerLine disassemblyLine;
uint sourceLine; uint sourceLine;
@@ -573,7 +578,7 @@ DisassemblerLines parseCdbDisassembler(const QList<QByteArray> &a)
} }
// Determine address of function from the first assembler line after a // Determine address of function from the first assembler line after a
// function header line. // function header line.
if (!functionAddress && disassemblyLine.address && functionOffset) { if (!functionAddress && disassemblyLine.address) {
functionAddress = disassemblyLine.address - functionOffset; functionAddress = disassemblyLine.address - functionOffset;
} }
if (functionAddress && disassemblyLine.address) if (functionAddress && disassemblyLine.address)

View File

@@ -187,7 +187,7 @@ QString DisassemblerLine::toString() const
if (address) if (address)
str += _("0x%1 ").arg(address, 0, 16); str += _("0x%1 ").arg(address, 0, 16);
if (offset) if (offset)
str += _("<+0x%1> ").arg(offset, 4, 10, QLatin1Char('0')); str += _("<+0x%1> ").arg(offset, 4, 16, QLatin1Char('0'));
str += _(" "); str += _(" ");
str += data; str += data;
} else if (isCode()) { } else if (isCode()) {