forked from qt-creator/qt-creator
Debugger[CDB]: Do path mapping in both directions.
For breakpoints and reported stacktraces. Make mapping more precise, check for slashes.
This commit is contained in:
@@ -1147,7 +1147,7 @@ void CdbEngine::executeRunToLine(const ContextData &data)
|
||||
bp.fileName = data.fileName;
|
||||
bp.lineNumber = data.lineNumber;
|
||||
}
|
||||
postCommand(cdbAddBreakpointCommand(bp, BreakpointId(-1), true), 0);
|
||||
postCommand(cdbAddBreakpointCommand(bp, m_sourcePathMappings, BreakpointId(-1), true), 0);
|
||||
continueInferior();
|
||||
}
|
||||
|
||||
@@ -1157,7 +1157,7 @@ void CdbEngine::executeRunToFunction(const QString &functionName)
|
||||
BreakpointParameters bp(BreakpointByFunction);
|
||||
bp.functionName = functionName;
|
||||
|
||||
postCommand(cdbAddBreakpointCommand(bp, BreakpointId(-1), true), 0);
|
||||
postCommand(cdbAddBreakpointCommand(bp, m_sourcePathMappings, BreakpointId(-1), true), 0);
|
||||
continueInferior();
|
||||
}
|
||||
|
||||
@@ -2329,7 +2329,7 @@ void CdbEngine::attemptBreakpointSynchronization()
|
||||
}
|
||||
switch (handler->state(id)) {
|
||||
case BreakpointInsertRequested:
|
||||
postCommand(cdbAddBreakpointCommand(parameters, id, false), 0);
|
||||
postCommand(cdbAddBreakpointCommand(parameters, m_sourcePathMappings, id, false), 0);
|
||||
if (!parameters.enabled)
|
||||
postCommand("bd " + QByteArray::number(id), 0);
|
||||
handler->notifyBreakpointInsertProceeding(id);
|
||||
@@ -2351,7 +2351,7 @@ void CdbEngine::attemptBreakpointSynchronization()
|
||||
// Delete and re-add, triggering update
|
||||
addedChanged = true;
|
||||
postCommand("bc " + QByteArray::number(id), 0);
|
||||
postCommand(cdbAddBreakpointCommand(parameters, id, false), 0);
|
||||
postCommand(cdbAddBreakpointCommand(parameters, m_sourcePathMappings, id, false), 0);
|
||||
m_pendingBreakpointMap.insert(id, response);
|
||||
}
|
||||
handler->notifyBreakpointChangeOk(id);
|
||||
@@ -2384,15 +2384,8 @@ CdbEngine::NormalizedSourceFileName CdbEngine::sourceMapNormalizeFileNameFromDeb
|
||||
if (debugSourceMapping)
|
||||
qDebug(">sourceMapNormalizeFileNameFromDebugger %s", qPrintable(f));
|
||||
// Do we have source path mappings? ->Apply.
|
||||
QString fileName = QDir::toNativeSeparators(f);
|
||||
if (!m_sourcePathMappings.isEmpty()) {
|
||||
foreach (const SourcePathMapping &m, m_sourcePathMappings) {
|
||||
if (fileName.startsWith(m.first, Qt::CaseInsensitive)) {
|
||||
fileName.replace(0, m.first.size(), m.second);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
const QString fileName = cdbSourcePathMapping(QDir::toNativeSeparators(f), m_sourcePathMappings,
|
||||
DebuggerToSource);
|
||||
// Up/lower case normalization according to Windows.
|
||||
#ifdef Q_OS_WIN
|
||||
QString normalized = winNormalizeFileName(fileName);
|
||||
|
@@ -53,8 +53,50 @@
|
||||
namespace Debugger {
|
||||
namespace Internal {
|
||||
|
||||
// Convert breakpoint in CDB syntax.
|
||||
// Perform mapping on parts of the source tree as reported by/passed to debugger
|
||||
// in case the user has specified such mappings in the global settings.
|
||||
// That is, when debugging an executable built from 'X:\buildsrv\foo.cpp' and using a local
|
||||
// source tree under 'c:\src', the user would specify a mapping 'X:\buildsrv'->'c:\src'
|
||||
// and file names passed to breakpoints and reported stack traces can be converted.
|
||||
QString cdbSourcePathMapping(QString fileName,
|
||||
const QList<QPair<QString, QString> > &sourcePathMapping,
|
||||
SourcePathMode mode)
|
||||
{
|
||||
typedef QPair<QString, QString> SourcePathMapping;
|
||||
|
||||
if (fileName.isEmpty() || sourcePathMapping.isEmpty())
|
||||
return fileName;
|
||||
foreach (const SourcePathMapping &m, sourcePathMapping) {
|
||||
const QString &source = mode == DebuggerToSource ? m.first : m.second;
|
||||
const int sourceSize = source.size();
|
||||
// Map parts of the path and ensure a slash follows.
|
||||
if (fileName.size() > sourceSize && fileName.startsWith(source, Qt::CaseInsensitive)) {
|
||||
const QChar next = fileName.at(sourceSize);
|
||||
if (next == QLatin1Char('\\') || next == QLatin1Char('/')) {
|
||||
const QString &target = mode == DebuggerToSource ? m.second: m.first;
|
||||
fileName.replace(0, sourceSize, target);
|
||||
return fileName;
|
||||
}
|
||||
}
|
||||
}
|
||||
return fileName;
|
||||
}
|
||||
|
||||
// Determine file name to be used for breakpoints. Convert to native and, unless short path
|
||||
// is set, perform reverse lookup in the source path mappings.
|
||||
static inline QString cdbBreakPointFileName(const BreakpointParameters &bp,
|
||||
const QList<QPair<QString, QString> > &sourcePathMapping)
|
||||
{
|
||||
if (bp.fileName.isEmpty())
|
||||
return bp.fileName;
|
||||
if (bp.pathUsage == BreakpointUseShortPath)
|
||||
return QFileInfo(bp.fileName).fileName();
|
||||
return cdbSourcePathMapping(QDir::toNativeSeparators(bp.fileName), sourcePathMapping, SourceToDebugger);
|
||||
}
|
||||
|
||||
// Convert breakpoint in CDB syntax. (applying source path mappings using native paths).
|
||||
QByteArray cdbAddBreakpointCommand(const BreakpointParameters &bpIn,
|
||||
const QList<QPair<QString, QString> > &sourcePathMapping,
|
||||
BreakpointId id /* = BreakpointId(-1) */,
|
||||
bool oneshot)
|
||||
{
|
||||
@@ -97,12 +139,7 @@ QByteArray cdbAddBreakpointCommand(const BreakpointParameters &bpIn,
|
||||
str << '`';
|
||||
if (!bp.module.isEmpty())
|
||||
str << bp.module << '!';
|
||||
if (bp.pathUsage == BreakpointUseShortPath) {
|
||||
str << QFileInfo(bp.fileName).fileName();
|
||||
} else {
|
||||
str << QDir::toNativeSeparators(bp.fileName);
|
||||
}
|
||||
str << ':' << bp.lineNumber << '`';
|
||||
str << cdbBreakPointFileName(bp, sourcePathMapping) << ':' << bp.lineNumber << '`';
|
||||
break;
|
||||
case Watchpoint:
|
||||
str << "rw 1 " << hex << hexPrefixOn << bp.address << hexPrefixOff << dec;
|
||||
|
@@ -39,6 +39,7 @@
|
||||
#include <QtCore/QtGlobal>
|
||||
#include <QtCore/QList>
|
||||
#include <QtCore/QVector>
|
||||
#include <QtCore/QPair>
|
||||
#include <QtCore/QByteArray>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
@@ -54,8 +55,17 @@ struct ThreadData;
|
||||
class Register;
|
||||
class GdbMi;
|
||||
|
||||
// Convert breakpoint in CDB syntax.
|
||||
QByteArray cdbAddBreakpointCommand(const BreakpointParameters &d, BreakpointId id = BreakpointId(-1), bool oneshot = false);
|
||||
// Perform mapping on parts of the source tree as reported by/passed to debugger
|
||||
// in case the user has specified such mappings in the global settings.
|
||||
enum SourcePathMode { DebuggerToSource, SourceToDebugger };
|
||||
QString cdbSourcePathMapping(QString fileName,
|
||||
const QList<QPair<QString, QString> > &sourcePathMapping,
|
||||
SourcePathMode mode);
|
||||
|
||||
// Convert breakpoint in CDB syntax (applying source path mappings using native paths).
|
||||
QByteArray cdbAddBreakpointCommand(const BreakpointParameters &d,
|
||||
const QList<QPair<QString, QString> > &sourcePathMapping,
|
||||
BreakpointId id = BreakpointId(-1), bool oneshot = false);
|
||||
// Parse extension command listing breakpoints.
|
||||
// Note that not all fields are returned, since file, line, function are encoded
|
||||
// in the expression (that is in addition deleted on resolving for a bp-type breakpoint).
|
||||
|
Reference in New Issue
Block a user