Debugger[New CDB]: Fix disassembly.

Introduce GDBMI-based 'stack' extension command instead of the
builtin 'k' as this does not print the correct instruction pointer.
This commit is contained in:
Friedemann Kleint
2010-11-22 13:50:40 +01:00
parent 3e002e6d79
commit 7fbff9c3af
9 changed files with 171 additions and 103 deletions

View File

@@ -154,75 +154,6 @@ QVariant cdbIntegerValue(const QByteArray &t)
return converted;
}
/* Parse: 64bit:
\code
Child-SP RetAddr Call Site
00000000`0012a290 00000000`70deb844 QtCored4!QString::QString+0x18 [c:\qt\src\corelib\tools\qstring.h @ 729]
\endcode 32bit:
\code
ChildEBP RetAddr
0012cc68 6714d114 QtCored4!QString::QString+0xf [d:\dev\qt4.7-vs8\qt\src\corelib\tools\qstring.h @ 729]
\endcode */
static inline bool isHexDigit(char c)
{
return std::isdigit(c) || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F');
}
static inline bool parseStackFrame(QByteArray line, Debugger::Internal::StackFrame *frame)
{
frame->clear();
if (line.isEmpty() || line.startsWith("Child") || !isHexDigit(line.at(0)))
return false;
if (line.endsWith(']')) {
const int sourceFilePos = line.lastIndexOf('[');
const int sepPos = line.lastIndexOf(" @ ");
if (sourceFilePos != -1 && sepPos != -1) {
const QString fileName = QString::fromLocal8Bit(line.mid(sourceFilePos + 1, sepPos - sourceFilePos - 1));
frame->file = QDir::cleanPath(fileName);
frame->line = line.mid(sepPos + 3, line.size() - sepPos - 4).toInt();
line.truncate(sourceFilePos - 1);
}
}
// Split address tokens
const int retAddrPos = line.indexOf(' ');
const int symbolPos = retAddrPos != -1 ? line.indexOf(' ', retAddrPos + 1) : -1;
if (symbolPos == -1)
return false;
// Remove offset off symbol
const int offsetPos = line.lastIndexOf("+0x");
if (offsetPos != -1)
line.truncate(offsetPos);
frame->address = cdbIntegerValue(line.mid(0, retAddrPos)).toULongLong();
// Module!foo
frame->function = QString::fromAscii(line.mid(symbolPos));
const int moduleSep = frame->function.indexOf(QLatin1Char('!'));
if (moduleSep != -1) {
frame->from = frame->function.left(moduleSep);
frame->function.remove(0, moduleSep + 1);
}
return true;
}
int parseCdbStackTrace(const QList<QByteArray> &in, QList<Debugger::Internal::StackFrame> *frames)
{
frames->clear();
Debugger::Internal::StackFrame frame;
frames->reserve(in.size());
int level = 0;
int current = -1;
foreach(const QByteArray &line, in)
if (parseStackFrame(line, &frame)) {
frame.level = level++;
if (current == -1 && frame.isUsable())
current = frames->size();
frames->push_back(frame);
}
return current;
}
/* \code
0:002> ~ [Debugger-Id] Id: <hex pid> <hex tid> Suspends count thread environment block add state name
0 Id: 133c.1374 Suspend: 1 Teb: 000007ff`fffdd000 Unfrozen