Debugger: Use more FilePath in source file handling

Needed for the double-remote case.

With this we have proper breakpoint markers in the text editor for a remotely
running gdb on a remotely loaded project.

Change-Id: If80e4a4108a4a0bcdd7612a59e2bd695213f5ea5
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
hjk
2023-03-14 18:18:39 +01:00
parent 47ed25e95d
commit 0dc61f55c3
14 changed files with 87 additions and 83 deletions

View File

@@ -1126,9 +1126,9 @@ void BreakpointItem::addToCommand(DebuggerCommand *cmd) const
cmd->arg("expression", requested.expression); cmd->arg("expression", requested.expression);
} }
void BreakpointItem::updateFromGdbOutput(const GdbMi &bkpt) void BreakpointItem::updateFromGdbOutput(const GdbMi &bkpt, const FilePath &fileRoot)
{ {
m_parameters.updateFromGdbOutput(bkpt); m_parameters.updateFromGdbOutput(bkpt, fileRoot);
adjustMarker(); adjustMarker();
} }

View File

@@ -107,7 +107,7 @@ public:
const BreakpointParameters &requestedParameters() const; const BreakpointParameters &requestedParameters() const;
void addToCommand(DebuggerCommand *cmd) const; void addToCommand(DebuggerCommand *cmd) const;
void updateFromGdbOutput(const GdbMi &bkpt); void updateFromGdbOutput(const GdbMi &bkpt, const Utils::FilePath &fileRoot);
int modelId() const; int modelId() const;
QString responseId() const { return m_responseId; } QString responseId() const { return m_responseId; }

View File

@@ -265,7 +265,8 @@ static QString cleanupFullName(const QString &fileName)
return cleanFilePath; return cleanFilePath;
} }
void BreakpointParameters::updateFromGdbOutput(const GdbMi &bkpt)
void BreakpointParameters::updateFromGdbOutput(const GdbMi &bkpt, const Utils::FilePath &fileRoot)
{ {
QTC_ASSERT(bkpt.isValid(), return); QTC_ASSERT(bkpt.isValid(), return);
@@ -358,7 +359,7 @@ void BreakpointParameters::updateFromGdbOutput(const GdbMi &bkpt)
QString name; QString name;
if (!fullName.isEmpty()) { if (!fullName.isEmpty()) {
name = cleanupFullName(fullName); name = cleanupFullName(fullName);
fileName = Utils::FilePath::fromString(name); fileName = fileRoot.withNewPath(name);
//if (data->markerFileName().isEmpty()) //if (data->markerFileName().isEmpty())
// data->setMarkerFileName(name); // data->setMarkerFileName(name);
} else { } else {
@@ -367,7 +368,7 @@ void BreakpointParameters::updateFromGdbOutput(const GdbMi &bkpt)
// gdb's own. No point in assigning markerFileName for now. // gdb's own. No point in assigning markerFileName for now.
} }
if (!name.isEmpty()) if (!name.isEmpty())
fileName = Utils::FilePath::fromString(name); fileName = fileRoot.withNewPath(name);
if (fileName.isEmpty()) if (fileName.isEmpty())
updateLocation(originalLocation); updateLocation(originalLocation);

View File

@@ -128,7 +128,7 @@ public:
bool isQmlFileAndLineBreakpoint() const; bool isQmlFileAndLineBreakpoint() const;
QString toString() const; QString toString() const;
void updateLocation(const QString &location); // file.cpp:42 void updateLocation(const QString &location); // file.cpp:42
void updateFromGdbOutput(const GdbMi &bkpt); void updateFromGdbOutput(const GdbMi &bkpt, const Utils::FilePath &fileRoot);
bool operator==(const BreakpointParameters &p) const { return equals(p); } bool operator==(const BreakpointParameters &p) const { return equals(p); }
bool operator!=(const BreakpointParameters &p) const { return !equals(p); } bool operator!=(const BreakpointParameters &p) const { return !equals(p); }

View File

@@ -901,6 +901,9 @@ DebuggerRunTool::DebuggerRunTool(RunControl *runControl, AllowTerminal allowTerm
if (Project *project = runControl->project()) { if (Project *project = runControl->project()) {
m_runParameters.projectSourceDirectory = project->projectDirectory(); m_runParameters.projectSourceDirectory = project->projectDirectory();
m_runParameters.projectSourceFiles = project->files(Project::SourceFiles); m_runParameters.projectSourceFiles = project->files(Project::SourceFiles);
} else {
m_runParameters.projectSourceDirectory = m_runParameters.debugger.command.executable().parentDir();
m_runParameters.projectSourceFiles.clear();
} }
m_runParameters.toolChainAbi = ToolChainKitAspect::targetAbi(kit); m_runParameters.toolChainAbi = ToolChainKitAspect::targetAbi(kit);

View File

@@ -539,6 +539,7 @@ void GdbEngine::handleAsyncOutput(const QStringView asyncClass, const GdbMi &res
ba.remove(pos1, pos3 - pos1 + 1); ba.remove(pos1, pos3 - pos1 + 1);
GdbMi res; GdbMi res;
res.fromString(ba); res.fromString(ba);
const FilePath &fileRoot = runParameters().projectSourceDirectory;
BreakHandler *handler = breakHandler(); BreakHandler *handler = breakHandler();
Breakpoint bp; Breakpoint bp;
for (const GdbMi &bkpt : res) { for (const GdbMi &bkpt : res) {
@@ -547,13 +548,13 @@ void GdbEngine::handleAsyncOutput(const QStringView asyncClass, const GdbMi &res
// A sub-breakpoint. // A sub-breakpoint.
QTC_ASSERT(bp, continue); QTC_ASSERT(bp, continue);
SubBreakpoint loc = bp->findOrCreateSubBreakpoint(nr); SubBreakpoint loc = bp->findOrCreateSubBreakpoint(nr);
loc->params.updateFromGdbOutput(bkpt); loc->params.updateFromGdbOutput(bkpt, fileRoot);
loc->params.type = bp->type(); loc->params.type = bp->type();
} else { } else {
// A primary breakpoint. // A primary breakpoint.
bp = handler->findBreakpointByResponseId(nr); bp = handler->findBreakpointByResponseId(nr);
if (bp) if (bp)
bp->updateFromGdbOutput(bkpt); bp->updateFromGdbOutput(bkpt, fileRoot);
} }
} }
if (bp) if (bp)
@@ -569,7 +570,7 @@ void GdbEngine::handleAsyncOutput(const QStringView asyncClass, const GdbMi &res
const QString nr = bkpt["number"].data(); const QString nr = bkpt["number"].data();
BreakpointParameters br; BreakpointParameters br;
br.type = BreakpointByFileAndLine; br.type = BreakpointByFileAndLine;
br.updateFromGdbOutput(bkpt); br.updateFromGdbOutput(bkpt, runParameters().projectSourceDirectory);
handler->handleAlienBreakpoint(nr, br); handler->handleAlienBreakpoint(nr, br);
} }
} else if (asyncClass == u"breakpoint-deleted") { } else if (asyncClass == u"breakpoint-deleted") {
@@ -1028,7 +1029,7 @@ void GdbEngine::handleQuerySources(const DebuggerResponse &response)
{ {
m_sourcesListUpdating = false; m_sourcesListUpdating = false;
if (response.resultClass == ResultDone) { if (response.resultClass == ResultDone) {
QMap<QString, QString> oldShortToFull = m_shortToFullName; QMap<QString, FilePath> oldShortToFull = m_shortToFullName;
m_shortToFullName.clear(); m_shortToFullName.clear();
m_fullToShortName.clear(); m_fullToShortName.clear();
// "^done,files=[{file="../../../../bin/dumper/dumper.cpp", // "^done,files=[{file="../../../../bin/dumper/dumper.cpp",
@@ -1039,7 +1040,7 @@ void GdbEngine::handleQuerySources(const DebuggerResponse &response)
continue; continue;
GdbMi fullName = item["fullname"]; GdbMi fullName = item["fullname"];
QString file = fileName.data(); QString file = fileName.data();
QString full; FilePath full;
if (fullName.isValid()) { if (fullName.isValid()) {
full = cleanupFullName(fullName.data()); full = cleanupFullName(fullName.data());
m_fullToShortName[full] = file; m_fullToShortName[full] = file;
@@ -1183,7 +1184,7 @@ void GdbEngine::handleStopResponse(const GdbMi &data)
const QString nr = data["bkptno"].data(); const QString nr = data["bkptno"].data();
int lineNumber = 0; int lineNumber = 0;
QString fullName; FilePath fullName;
QString function; QString function;
QString language; QString language;
if (frame.isValid()) { if (frame.isValid()) {
@@ -1196,15 +1197,13 @@ void GdbEngine::handleStopResponse(const GdbMi &data)
lineNumber = lineNumberG.toInt(); lineNumber = lineNumberG.toInt();
fullName = cleanupFullName(frame["fullname"].data()); fullName = cleanupFullName(frame["fullname"].data());
if (fullName.isEmpty()) if (fullName.isEmpty())
fullName = frame["file"].data(); fullName = runParameters().projectSourceDirectory.withNewPath(frame["file"].data());
} // found line number } // found line number
} else { } else {
showMessage("INVALID STOPPED REASON", LogWarning); showMessage("INVALID STOPPED REASON", LogWarning);
} }
const FilePath onDevicePath = FilePath::fromString(fullName).onDevice( const FilePath fileName = fullName.localSource().value_or(fullName);
runParameters().debugger.command.executable());
const FilePath fileName = onDevicePath.localSource().value_or(onDevicePath);
if (!nr.isEmpty() && frame.isValid()) { if (!nr.isEmpty() && frame.isValid()) {
// Use opportunity to update the breakpoint marker position. // Use opportunity to update the breakpoint marker position.
@@ -1560,50 +1559,47 @@ void GdbEngine::handleExecuteContinue(const DebuggerResponse &response)
} }
} }
QString GdbEngine::fullName(const QString &fileName) FilePath GdbEngine::fullName(const QString &fileName)
{ {
if (fileName.isEmpty()) if (fileName.isEmpty())
return QString(); return {};
QTC_ASSERT(!m_sourcesListUpdating, /* */); QTC_CHECK(!m_sourcesListUpdating);
return m_shortToFullName.value(fileName, QString()); return m_shortToFullName.value(fileName, {});
} }
QString GdbEngine::cleanupFullName(const QString &fileName) FilePath GdbEngine::cleanupFullName(const QString &fileName)
{ {
QString cleanFilePath = fileName; FilePath cleanFilePath =
runParameters().projectSourceDirectory.withNewPath(fileName).cleanPath();
// Gdb running on windows often delivers "fullnames" which // Gdb running on windows often delivers "fullnames" which
// (a) have no drive letter and (b) are not normalized. // (a) have no drive letter and (b) are not normalized.
if (Abi::hostAbi().os() == Abi::WindowsOS) { if (Abi::hostAbi().os() == Abi::WindowsOS) {
if (fileName.isEmpty()) if (fileName.isEmpty())
return QString(); return {};
QFileInfo fi(fileName);
if (fi.isReadable())
cleanFilePath = QDir::cleanPath(fi.absoluteFilePath());
} }
if (!debuggerSettings()->autoEnrichParameters.value()) if (!debuggerSettings()->autoEnrichParameters.value())
return cleanFilePath; return cleanFilePath;
const QString sysroot = runParameters().sysRoot.toString(); if (cleanFilePath.isReadableFile())
if (QFileInfo(cleanFilePath).isReadable())
return cleanFilePath; return cleanFilePath;
const FilePath sysroot = runParameters().sysRoot;
if (!sysroot.isEmpty() && fileName.startsWith('/')) { if (!sysroot.isEmpty() && fileName.startsWith('/')) {
cleanFilePath = sysroot + fileName; cleanFilePath = sysroot.pathAppended(fileName.mid(1));
if (QFileInfo(cleanFilePath).isReadable()) if (cleanFilePath.isReadableFile())
return cleanFilePath; return cleanFilePath;
} }
if (m_baseNameToFullName.isEmpty()) { if (m_baseNameToFullName.isEmpty()) {
FilePath filePath = FilePath::fromString(sysroot + "/usr/src/debug"); FilePath filePath = sysroot.pathAppended("/usr/src/debug");
if (filePath.isDir()) { if (filePath.isDir()) {
filePath.iterateDirectory( filePath.iterateDirectory(
[this](const FilePath &filePath) { [this](const FilePath &filePath) {
QString name = filePath.fileName(); QString name = filePath.fileName();
if (!name.startsWith('.')) { if (!name.startsWith('.'))
QString path = filePath.path(); m_baseNameToFullName.insert(name, filePath);
m_baseNameToFullName.insert(name, path);
}
return IterationPolicy::Continue; return IterationPolicy::Continue;
}, },
{{"*"}, QDir::NoFilter, QDirIterator::Subdirectories}); {{"*"}, QDir::NoFilter, QDirIterator::Subdirectories});
@@ -1613,7 +1609,7 @@ QString GdbEngine::cleanupFullName(const QString &fileName)
cleanFilePath.clear(); cleanFilePath.clear();
const QString base = FilePath::fromUserInput(fileName).fileName(); const QString base = FilePath::fromUserInput(fileName).fileName();
QMultiMap<QString, QString>::const_iterator jt = m_baseNameToFullName.constFind(base); auto jt = m_baseNameToFullName.constFind(base);
while (jt != m_baseNameToFullName.constEnd() && jt.key() == base) { while (jt != m_baseNameToFullName.constEnd() && jt.key() == base) {
// FIXME: Use some heuristics to find the "best" match. // FIXME: Use some heuristics to find the "best" match.
return jt.value(); return jt.value();
@@ -1950,7 +1946,7 @@ void GdbEngine::executeRunToLine(const ContextData &data)
if (data.address) if (data.address)
loc = addressSpec(data.address); loc = addressSpec(data.address);
else else
loc = '"' + breakLocation(data.fileName.toString()) + '"' + ':' + QString::number(data.lineNumber); loc = '"' + breakLocation(data.fileName) + '"' + ':' + QString::number(data.lineNumber);
runCommand({"tbreak " + loc}); runCommand({"tbreak " + loc});
runCommand({"continue", NativeCommand|RunRequest, CB(handleExecuteRunToLine)}); runCommand({"continue", NativeCommand|RunRequest, CB(handleExecuteRunToLine)});
@@ -1978,7 +1974,7 @@ void GdbEngine::executeJumpToLine(const ContextData &data)
if (data.address) if (data.address)
loc = addressSpec(data.address); loc = addressSpec(data.address);
else else
loc = '"' + breakLocation(data.fileName.toString()) + '"' + ':' + QString::number(data.lineNumber); loc = '"' + breakLocation(data.fileName) + '"' + ':' + QString::number(data.lineNumber);
runCommand({"tbreak " + loc}); runCommand({"tbreak " + loc});
notifyInferiorRunRequested(); notifyInferiorRunRequested();
@@ -2052,11 +2048,11 @@ void GdbEngine::setTokenBarrier()
// //
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
QString GdbEngine::breakLocation(const QString &file) const QString GdbEngine::breakLocation(const FilePath &file) const
{ {
QString where = m_fullToShortName.value(file); QString where = m_fullToShortName.value(file);
if (where.isEmpty()) if (where.isEmpty())
return FilePath::fromString(file).fileName(); return file.fileName();
return where; return where;
} }
@@ -2080,7 +2076,7 @@ QString GdbEngine::breakpointLocation(const BreakpointParameters &data)
usage = BreakpointUseShortPath; usage = BreakpointUseShortPath;
const QString fileName = usage == BreakpointUseFullPath const QString fileName = usage == BreakpointUseFullPath
? data.fileName.toString() : breakLocation(data.fileName.toString()); ? data.fileName.path() : breakLocation(data.fileName);
// The argument is simply a C-quoted version of the argument to the // The argument is simply a C-quoted version of the argument to the
// non-MI "break" command, including the "original" quoting it wants. // non-MI "break" command, including the "original" quoting it wants.
return "\"\\\"" + GdbMi::escapeCString(fileName) + "\\\":" return "\"\\\"" + GdbMi::escapeCString(fileName) + "\\\":"
@@ -2094,7 +2090,7 @@ QString GdbEngine::breakpointLocation2(const BreakpointParameters &data)
usage = BreakpointUseShortPath; usage = BreakpointUseShortPath;
const QString fileName = usage == BreakpointUseFullPath const QString fileName = usage == BreakpointUseFullPath
? data.fileName.toString() : breakLocation(data.fileName.toString()); ? data.fileName.path() : breakLocation(data.fileName);
return GdbMi::escapeCString(fileName) + ':' + QString::number(data.lineNumber); return GdbMi::escapeCString(fileName) + ':' + QString::number(data.lineNumber);
} }
@@ -2107,7 +2103,7 @@ void GdbEngine::handleInsertInterpreterBreakpoint(const DebuggerResponse &respon
notifyBreakpointInsertOk(bp); notifyBreakpointInsertOk(bp);
} else { } else {
bp->setResponseId(response.data["number"].data()); bp->setResponseId(response.data["number"].data());
bp->updateFromGdbOutput(response.data); bp->updateFromGdbOutput(response.data, runParameters().projectSourceDirectory);
notifyBreakpointInsertOk(bp); notifyBreakpointInsertOk(bp);
} }
} }
@@ -2117,7 +2113,7 @@ void GdbEngine::handleInterpreterBreakpointModified(const GdbMi &data)
int modelId = data["modelid"].toInt(); int modelId = data["modelid"].toInt();
Breakpoint bp = breakHandler()->findBreakpointByModelId(modelId); Breakpoint bp = breakHandler()->findBreakpointByModelId(modelId);
QTC_ASSERT(bp, return); QTC_ASSERT(bp, return);
bp->updateFromGdbOutput(data); bp->updateFromGdbOutput(data, runParameters().projectSourceDirectory);
} }
void GdbEngine::handleWatchInsert(const DebuggerResponse &response, const Breakpoint &bp) void GdbEngine::handleWatchInsert(const DebuggerResponse &response, const Breakpoint &bp)
@@ -2167,7 +2163,7 @@ void GdbEngine::handleBkpt(const GdbMi &bkpt, const Breakpoint &bp)
// A sub-breakpoint. // A sub-breakpoint.
SubBreakpoint sub = bp->findOrCreateSubBreakpoint(nr); SubBreakpoint sub = bp->findOrCreateSubBreakpoint(nr);
QTC_ASSERT(sub, return); QTC_ASSERT(sub, return);
sub->params.updateFromGdbOutput(bkpt); sub->params.updateFromGdbOutput(bkpt, runParameters().projectSourceDirectory);
sub->params.type = bp->type(); sub->params.type = bp->type();
if (usePseudoTracepoints && bp->isTracepoint()) { if (usePseudoTracepoints && bp->isTracepoint()) {
sub->params.tracepoint = true; sub->params.tracepoint = true;
@@ -2185,7 +2181,7 @@ void GdbEngine::handleBkpt(const GdbMi &bkpt, const Breakpoint &bp)
const QString subnr = location["number"].data(); const QString subnr = location["number"].data();
SubBreakpoint sub = bp->findOrCreateSubBreakpoint(subnr); SubBreakpoint sub = bp->findOrCreateSubBreakpoint(subnr);
QTC_ASSERT(sub, return); QTC_ASSERT(sub, return);
sub->params.updateFromGdbOutput(location); sub->params.updateFromGdbOutput(location, runParameters().projectSourceDirectory);
sub->params.type = bp->type(); sub->params.type = bp->type();
if (usePseudoTracepoints && bp->isTracepoint()) { if (usePseudoTracepoints && bp->isTracepoint()) {
sub->params.tracepoint = true; sub->params.tracepoint = true;
@@ -2196,7 +2192,7 @@ void GdbEngine::handleBkpt(const GdbMi &bkpt, const Breakpoint &bp)
// A (the?) primary breakpoint. // A (the?) primary breakpoint.
bp->setResponseId(nr); bp->setResponseId(nr);
bp->updateFromGdbOutput(bkpt); bp->updateFromGdbOutput(bkpt, runParameters().projectSourceDirectory);
if (usePseudoTracepoints && bp->isTracepoint()) if (usePseudoTracepoints && bp->isTracepoint())
bp->setMessage(bp->requestedParameters().message); bp->setMessage(bp->requestedParameters().message);
} }
@@ -2503,7 +2499,7 @@ void GdbEngine::handleTracepointModified(const GdbMi &data)
// A sub-breakpoint. // A sub-breakpoint.
QTC_ASSERT(bp, continue); QTC_ASSERT(bp, continue);
SubBreakpoint loc = bp->findOrCreateSubBreakpoint(nr); SubBreakpoint loc = bp->findOrCreateSubBreakpoint(nr);
loc->params.updateFromGdbOutput(bkpt); loc->params.updateFromGdbOutput(bkpt, runParameters().projectSourceDirectory);
loc->params.type = bp->type(); loc->params.type = bp->type();
if (bp->isTracepoint()) { if (bp->isTracepoint()) {
loc->params.tracepoint = true; loc->params.tracepoint = true;
@@ -2513,7 +2509,7 @@ void GdbEngine::handleTracepointModified(const GdbMi &data)
// A primary breakpoint. // A primary breakpoint.
bp = handler->findBreakpointByResponseId(nr); bp = handler->findBreakpointByResponseId(nr);
if (bp) if (bp)
bp->updateFromGdbOutput(bkpt); bp->updateFromGdbOutput(bkpt, runParameters().projectSourceDirectory);
} }
} }
QTC_ASSERT(bp, return); QTC_ASSERT(bp, return);
@@ -3036,7 +3032,7 @@ void GdbEngine::reloadSourceFiles()
cmd.callback = [this](const DebuggerResponse &response) { cmd.callback = [this](const DebuggerResponse &response) {
m_sourcesListUpdating = false; m_sourcesListUpdating = false;
if (response.resultClass == ResultDone) { if (response.resultClass == ResultDone) {
QMap<QString, QString> oldShortToFull = m_shortToFullName; QMap<QString, FilePath> oldShortToFull = m_shortToFullName;
m_shortToFullName.clear(); m_shortToFullName.clear();
m_fullToShortName.clear(); m_fullToShortName.clear();
// "^done,files=[{file="../../../../bin/dumper/dumper.cpp", // "^done,files=[{file="../../../../bin/dumper/dumper.cpp",
@@ -3047,7 +3043,7 @@ void GdbEngine::reloadSourceFiles()
continue; continue;
GdbMi fullName = item["fullname"]; GdbMi fullName = item["fullname"];
QString file = fileName.data(); QString file = fileName.data();
QString full; FilePath full;
if (fullName.isValid()) { if (fullName.isValid()) {
full = cleanupFullName(fullName.data()); full = cleanupFullName(fullName.data());
m_fullToShortName[full] = file; m_fullToShortName[full] = file;

View File

@@ -210,7 +210,7 @@ private: ////////// General Interface //////////
void handleBkpt(const GdbMi &bkpt, const Breakpoint &bp); void handleBkpt(const GdbMi &bkpt, const Breakpoint &bp);
QString breakpointLocation(const BreakpointParameters &data); // For gdb/MI. QString breakpointLocation(const BreakpointParameters &data); // For gdb/MI.
QString breakpointLocation2(const BreakpointParameters &data); // For gdb/CLI fallback. QString breakpointLocation2(const BreakpointParameters &data); // For gdb/CLI fallback.
QString breakLocation(const QString &file) const; QString breakLocation(const Utils::FilePath &file) const;
void updateTracepointCaptures(const Breakpoint &bp); void updateTracepointCaptures(const Breakpoint &bp);
// //
@@ -265,13 +265,13 @@ private: ////////// General Interface //////////
void reloadSourceFilesInternal(); void reloadSourceFilesInternal();
void handleQuerySources(const DebuggerResponse &response); void handleQuerySources(const DebuggerResponse &response);
QString fullName(const QString &fileName); Utils::FilePath fullName(const QString &fileName);
QString cleanupFullName(const QString &fileName); Utils::FilePath cleanupFullName(const QString &fileName);
// awful hack to keep track of used files // awful hack to keep track of used files
QMap<QString, QString> m_shortToFullName; QMap<QString, Utils::FilePath> m_shortToFullName;
QMap<QString, QString> m_fullToShortName; QMap<Utils::FilePath, QString> m_fullToShortName;
QMultiMap<QString, QString> m_baseNameToFullName; QMultiMap<QString, Utils::FilePath> m_baseNameToFullName;
bool m_sourcesListUpdating = false; bool m_sourcesListUpdating = false;

View File

@@ -1802,10 +1802,10 @@ void QmlEnginePrivate::messageReceived(const QByteArray &data)
updateScriptSource(name, lineOffset, columnOffset, source); updateScriptSource(name, lineOffset, columnOffset, source);
} }
QMap<QString,QString> files; QMap<QString, FilePath> files;
for (const QString &file : std::as_const(sourceFiles)) { for (const QString &file : std::as_const(sourceFiles)) {
QString shortName = file; QString shortName = file;
QString fullName = engine->toFileInProject(file); FilePath fullName = engine->toFileInProject(file);
files.insert(shortName, fullName); files.insert(shortName, fullName);
} }
@@ -1915,7 +1915,7 @@ void QmlEnginePrivate::messageReceived(const QByteArray &data)
const QVariantMap script = body.value("script").toMap(); const QVariantMap script = body.value("script").toMap();
QUrl fileUrl(script.value(NAME).toString()); QUrl fileUrl(script.value(NAME).toString());
QString filePath = engine->toFileInProject(fileUrl); FilePath filePath = engine->toFileInProject(fileUrl);
const QVariantMap exception = body.value("exception").toMap(); const QVariantMap exception = body.value("exception").toMap();
QString errorMessage = exception.value("text").toString(); QString errorMessage = exception.value("text").toString();
@@ -2045,8 +2045,7 @@ StackFrame QmlEnginePrivate::extractStackFrame(const QVariant &bodyVal)
stackFrame.function = extractString(body.value("func")); stackFrame.function = extractString(body.value("func"));
if (stackFrame.function.isEmpty()) if (stackFrame.function.isEmpty())
stackFrame.function = Tr::tr("Anonymous Function"); stackFrame.function = Tr::tr("Anonymous Function");
stackFrame.file = FilePath::fromString( stackFrame.file = engine->toFileInProject(extractString(body.value("script")));
engine->toFileInProject(extractString(body.value("script"))));
stackFrame.usable = stackFrame.file.isReadableFile(); stackFrame.usable = stackFrame.file.isReadableFile();
stackFrame.receiver = extractString(body.value("receiver")); stackFrame.receiver = extractString(body.value("receiver"));
stackFrame.line = body.value("line").toInt() + 1; stackFrame.line = body.value("line").toInt() + 1;
@@ -2444,7 +2443,7 @@ void QmlEnginePrivate::flushSendBuffer()
sendBuffer.clear(); sendBuffer.clear();
} }
QString QmlEngine::toFileInProject(const QUrl &fileUrl) FilePath QmlEngine::toFileInProject(const QUrl &fileUrl)
{ {
// make sure file finder is properly initialized // make sure file finder is properly initialized
const DebuggerRunParameters &rp = runParameters(); const DebuggerRunParameters &rp = runParameters();
@@ -2453,7 +2452,7 @@ QString QmlEngine::toFileInProject(const QUrl &fileUrl)
d->fileFinder.setAdditionalSearchDirectories(rp.additionalSearchDirectories); d->fileFinder.setAdditionalSearchDirectories(rp.additionalSearchDirectories);
d->fileFinder.setSysroot(rp.sysRoot); d->fileFinder.setSysroot(rp.sysRoot);
return d->fileFinder.findFile(fileUrl).constFirst().toString(); return d->fileFinder.findFile(fileUrl).constFirst();
} }
DebuggerEngine *createQmlEngine() DebuggerEngine *createQmlEngine()

View File

@@ -25,7 +25,7 @@ public:
void logServiceActivity(const QString &service, const QString &logMessage); void logServiceActivity(const QString &service, const QString &logMessage);
void expressionEvaluated(quint32 queryId, const QVariant &result); void expressionEvaluated(quint32 queryId, const QVariant &result);
QString toFileInProject(const QUrl &fileUrl); Utils::FilePath toFileInProject(const QUrl &fileUrl);
private: private:
void disconnected(); void disconnected();

View File

@@ -20,6 +20,7 @@ using namespace QmlDebug;
using namespace QmlJS; using namespace QmlJS;
using namespace QmlJS::AST; using namespace QmlJS::AST;
using namespace TextEditor; using namespace TextEditor;
using namespace Utils;
namespace Debugger::Internal { namespace Debugger::Internal {
@@ -218,11 +219,10 @@ void clearExceptionSelection()
} }
} }
QStringList highlightExceptionCode(int lineNumber, const QString &filePath, const QString &errorMessage) QStringList highlightExceptionCode(int lineNumber, const FilePath &filePath, const QString &errorMessage)
{ {
QStringList messages; QStringList messages;
const QList<IEditor *> editors = DocumentModel::editorsForFilePath( const QList<IEditor *> editors = DocumentModel::editorsForFilePath(filePath);
Utils::FilePath::fromString(filePath));
const TextEditor::FontSettings &fontSettings = TextEditor::TextEditorSettings::fontSettings(); const TextEditor::FontSettings &fontSettings = TextEditor::TextEditorSettings::fontSettings();
QTextCharFormat errorFormat = fontSettings.toTextCharFormat(TextEditor::C_ERROR); QTextCharFormat errorFormat = fontSettings.toTextCharFormat(TextEditor::C_ERROR);
@@ -251,7 +251,7 @@ QStringList highlightExceptionCode(int lineNumber, const QString &filePath, cons
selections.append(sel); selections.append(sel);
ed->setExtraSelections(TextEditorWidget::DebuggerExceptionSelection, selections); ed->setExtraSelections(TextEditorWidget::DebuggerExceptionSelection, selections);
messages.append(QString::fromLatin1("%1: %2: %3").arg(filePath).arg(lineNumber).arg(errorMessage)); messages.append(QString::fromLatin1("%1: %2: %3").arg(filePath.toUserOutput()).arg(lineNumber).arg(errorMessage));
} }
return messages; return messages;
} }

View File

@@ -6,11 +6,13 @@
#include <qmldebug/qdebugmessageclient.h> #include <qmldebug/qdebugmessageclient.h>
#include <qmldebug/qmloutputparser.h> #include <qmldebug/qmloutputparser.h>
namespace Utils { class FilePath; }
namespace Debugger::Internal { namespace Debugger::Internal {
void appendDebugOutput(QtMsgType type, const QString &message, const QmlDebug::QDebugContextInfo &info); void appendDebugOutput(QtMsgType type, const QString &message, const QmlDebug::QDebugContextInfo &info);
void clearExceptionSelection(); void clearExceptionSelection();
QStringList highlightExceptionCode(int lineNumber, const QString &filePath, const QString &errorMessage); QStringList highlightExceptionCode(int lineNumber, const Utils::FilePath &filePath, const QString &errorMessage);
} // Debugger::Internal } // Debugger::Internal

View File

@@ -32,6 +32,7 @@
using namespace QmlDebug; using namespace QmlDebug;
using namespace QmlDebug::Constants; using namespace QmlDebug::Constants;
using namespace Utils;
namespace Debugger::Internal { namespace Debugger::Internal {
@@ -541,8 +542,8 @@ void QmlInspectorAgent::buildDebugIdHashRecursive(const ObjectReference &ref)
lineNum += match.captured(3).toInt() - 1; lineNum += match.captured(3).toInt() - 1;
} }
const QString filePath = m_qmlEngine->toFileInProject(fileUrl); const FilePath filePath = m_qmlEngine->toFileInProject(fileUrl);
m_debugIdLocations.insert(ref.debugId(), FileReference(filePath, lineNum, colNum)); m_debugIdLocations.insert(ref.debugId(), FileReference(filePath.toFSPathString(), lineNum, colNum));
const auto children = ref.children(); const auto children = ref.children();
for (const ObjectReference &it : children) for (const ObjectReference &it : children)
@@ -735,7 +736,7 @@ void QmlInspectorAgent::onShowAppOnTopChanged(bool checked)
void QmlInspectorAgent::jumpToObjectDefinitionInEditor(const FileReference &objSource) void QmlInspectorAgent::jumpToObjectDefinitionInEditor(const FileReference &objSource)
{ {
const auto filePath = Utils::FilePath::fromString(m_qmlEngine->toFileInProject(objSource.url())); const FilePath filePath = m_qmlEngine->toFileInProject(objSource.url());
Core::EditorManager::openEditorAt({filePath, objSource.lineNumber()}); Core::EditorManager::openEditorAt({filePath, objSource.lineNumber()});
} }

View File

@@ -55,8 +55,8 @@ Qt::ItemFlags SourceFilesHandler::flags(const QModelIndex &index) const
{ {
if (index.row() >= m_fullNames.size()) if (index.row() >= m_fullNames.size())
return {}; return {};
QFileInfo fi(m_fullNames.at(index.row())); FilePath filePath = m_fullNames.at(index.row());
return fi.isReadable() ? QAbstractItemModel::flags(index) : Qt::ItemFlags({}); return filePath.isReadableFile() ? QAbstractItemModel::flags(index) : Qt::ItemFlags({});
} }
QVariant SourceFilesHandler::data(const QModelIndex &index, int role) const QVariant SourceFilesHandler::data(const QModelIndex &index, int role) const
@@ -75,7 +75,7 @@ QVariant SourceFilesHandler::data(const QModelIndex &index, int role) const
break; break;
case 1: case 1:
if (role == Qt::DisplayRole) if (role == Qt::DisplayRole)
return m_fullNames.at(row); return m_fullNames.at(row).toUserOutput();
//if (role == Qt::DecorationRole) //if (role == Qt::DecorationRole)
// return module.symbolsRead ? icon2 : icon; // return module.symbolsRead ? icon2 : icon;
break; break;
@@ -123,13 +123,13 @@ bool SourceFilesHandler::setData(const QModelIndex &idx, const QVariant &data, i
return false; return false;
} }
void SourceFilesHandler::setSourceFiles(const QMap<QString, QString> &sourceFiles) void SourceFilesHandler::setSourceFiles(const QMap<QString, FilePath> &sourceFiles)
{ {
beginResetModel(); beginResetModel();
m_shortNames.clear(); m_shortNames.clear();
m_fullNames.clear(); m_fullNames.clear();
QMap<QString, QString>::ConstIterator it = sourceFiles.begin(); auto it = sourceFiles.begin();
QMap<QString, QString>::ConstIterator et = sourceFiles.end(); const auto et = sourceFiles.end();
for (; it != et; ++it) { for (; it != et; ++it) {
m_shortNames.append(it.key()); m_shortNames.append(it.key());
m_fullNames.append(it.value()); m_fullNames.append(it.value());
@@ -139,7 +139,7 @@ void SourceFilesHandler::setSourceFiles(const QMap<QString, QString> &sourceFile
void SourceFilesHandler::removeAll() void SourceFilesHandler::removeAll()
{ {
setSourceFiles(QMap<QString, QString>()); setSourceFiles({});
//header()->setSectionResizeMode(0, QHeaderView::ResizeToContents); //header()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
} }

View File

@@ -3,6 +3,8 @@
#pragma once #pragma once
#include <utils/filepath.h>
#include <QAbstractItemModel> #include <QAbstractItemModel>
#include <QStringList> #include <QStringList>
@@ -29,7 +31,7 @@ public:
void clearModel(); void clearModel();
void setSourceFiles(const QMap<QString, QString> &sourceFiles); void setSourceFiles(const QMap<QString, Utils::FilePath> &sourceFiles);
void removeAll(); void removeAll();
QAbstractItemModel *model() { return m_proxyModel; } QAbstractItemModel *model() { return m_proxyModel; }
@@ -37,7 +39,7 @@ public:
private: private:
DebuggerEngine *m_engine; DebuggerEngine *m_engine;
QStringList m_shortNames; QStringList m_shortNames;
QStringList m_fullNames; Utils::FilePaths m_fullNames;
QAbstractItemModel *m_proxyModel; QAbstractItemModel *m_proxyModel;
}; };