forked from qt-creator/qt-creator
QmlJsDebugger: Handle breakpoints in qrc:// resources more gracefully
Reviewed-by: Christiaan Janssen
This commit is contained in:
@@ -46,7 +46,6 @@
|
||||
#include <QtCore/qdebug.h>
|
||||
#include <QtCore/qcoreapplication.h>
|
||||
#include <QtCore/qset.h>
|
||||
#include <QtCore/qfileinfo.h>
|
||||
#include <QtCore/qurl.h>
|
||||
#include <QtScript/qscriptcontextinfo.h>
|
||||
#include <QtScript/qscriptengine.h>
|
||||
@@ -82,19 +81,19 @@ QDataStream &operator<<(QDataStream &s, const JSAgentWatchData &data)
|
||||
struct JSAgentStackData
|
||||
{
|
||||
QByteArray functionName;
|
||||
QByteArray fileName;
|
||||
QByteArray fileUrl;
|
||||
qint32 lineNumber;
|
||||
};
|
||||
|
||||
QDataStream &operator<<(QDataStream &s, const JSAgentStackData &data)
|
||||
{
|
||||
return s << data.functionName << data.fileName << data.lineNumber;
|
||||
return s << data.functionName << data.fileUrl << data.lineNumber;
|
||||
}
|
||||
|
||||
struct JSAgentBreakpointData
|
||||
{
|
||||
QByteArray functionName;
|
||||
QByteArray fileName;
|
||||
QByteArray fileUrl;
|
||||
qint32 lineNumber;
|
||||
};
|
||||
|
||||
@@ -102,22 +101,22 @@ typedef QSet<JSAgentBreakpointData> JSAgentBreakpoints;
|
||||
|
||||
QDataStream &operator<<(QDataStream &s, const JSAgentBreakpointData &data)
|
||||
{
|
||||
return s << data.functionName << data.fileName << data.lineNumber;
|
||||
return s << data.functionName << data.fileUrl << data.lineNumber;
|
||||
}
|
||||
|
||||
QDataStream &operator>>(QDataStream &s, JSAgentBreakpointData &data)
|
||||
{
|
||||
return s >> data.functionName >> data.fileName >> data.lineNumber;
|
||||
return s >> data.functionName >> data.fileUrl >> data.lineNumber;
|
||||
}
|
||||
|
||||
bool operator==(const JSAgentBreakpointData &b1, const JSAgentBreakpointData &b2)
|
||||
{
|
||||
return b1.lineNumber == b2.lineNumber && b1.fileName == b2.fileName;
|
||||
return b1.lineNumber == b2.lineNumber && b1.fileUrl == b2.fileUrl;
|
||||
}
|
||||
|
||||
uint qHash(const JSAgentBreakpointData &b)
|
||||
{
|
||||
return b.lineNumber ^ qHash(b.fileName);
|
||||
return b.lineNumber ^ qHash(b.fileUrl);
|
||||
}
|
||||
|
||||
class JSDebuggerAgentPrivate
|
||||
@@ -316,7 +315,7 @@ void JSDebuggerAgent::scriptLoad(qint64 id, const QString &program,
|
||||
const QString &fileName, int)
|
||||
{
|
||||
Q_UNUSED(program);
|
||||
d->filenames.insert(id, QUrl(fileName).toLocalFile());
|
||||
d->filenames.insert(id, fileName);
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -368,6 +367,12 @@ void JSDebuggerAgent::positionChange(qint64 scriptId, int lineNumber, int column
|
||||
d->positionChange(scriptId, lineNumber, columnNumber);
|
||||
}
|
||||
|
||||
QString fileName(const QString &fileUrl)
|
||||
{
|
||||
int lastDelimiterPos = fileUrl.lastIndexOf(QLatin1Char('/'));
|
||||
return fileUrl.mid(lastDelimiterPos, fileUrl.size() - lastDelimiterPos);
|
||||
}
|
||||
|
||||
void JSDebuggerAgentPrivate::positionChange(qint64 scriptId, int lineNumber, int columnNumber)
|
||||
{
|
||||
Q_UNUSED(columnNumber);
|
||||
@@ -382,7 +387,7 @@ void JSDebuggerAgentPrivate::positionChange(qint64 scriptId, int lineNumber, int
|
||||
QScriptContextInfo info(ctx);
|
||||
if (it == filenames.constEnd()) {
|
||||
// It is possible that the scripts are loaded before the agent is attached
|
||||
QString filename = QUrl(info.fileName()).toLocalFile();
|
||||
QString filename = info.fileName();
|
||||
|
||||
JSAgentStackData frame;
|
||||
frame.functionName = info.functionName().toUtf8();
|
||||
@@ -392,7 +397,7 @@ void JSDebuggerAgentPrivate::positionChange(qint64 scriptId, int lineNumber, int
|
||||
}
|
||||
|
||||
const QString filePath = it->toUtf8();
|
||||
JSAgentBreakpoints bps = fileNameToBreakpoints.values(QFileInfo(filePath).fileName()).toSet();
|
||||
JSAgentBreakpoints bps = fileNameToBreakpoints.values(fileName(filePath)).toSet();
|
||||
|
||||
foreach (const JSAgentBreakpointData &bp, bps) {
|
||||
if (bp.lineNumber == lineNumber) {
|
||||
@@ -477,7 +482,7 @@ void JSDebuggerAgentPrivate::messageReceived(const QByteArray &message)
|
||||
|
||||
fileNameToBreakpoints.clear();
|
||||
foreach (const JSAgentBreakpointData &bp, breakpoints) {
|
||||
fileNameToBreakpoints.insert(QFileInfo(bp.fileName).fileName(), bp);
|
||||
fileNameToBreakpoints.insert(fileName(bp.fileUrl), bp);
|
||||
}
|
||||
|
||||
//qDebug() << "BREAKPOINTS";
|
||||
@@ -621,7 +626,8 @@ void JSDebuggerAgentPrivate::stopped()
|
||||
// if the line number is unknown, fallback to the function line number
|
||||
if (frame.lineNumber == -1)
|
||||
frame.lineNumber = info.functionStartLineNumber();
|
||||
frame.fileName = QUrl(info.fileName()).toLocalFile().toUtf8();
|
||||
|
||||
frame.fileUrl = info.fileName().toUtf8();
|
||||
backtrace.append(frame);
|
||||
}
|
||||
QList<JSAgentWatchData> watches;
|
||||
|
Reference in New Issue
Block a user