forked from qt-creator/qt-creator
Debugger: Move interpretation on nature of source path mapping to user code
Change f0e2708
introduced the ability to specify source path mapping
containing regular expressions and used this in the elf reader.
To simplify the code, this change here moves the decision which paths
are considered regular expressions to the user. The other users which
are not aware of the special handling of paths starting with '(' in
the elf reader will interpret them as plain string, which appears to
be the right thing.
Change-Id: I31f10ed866fe7582d44307a923b6db10206acc9a
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
@@ -72,8 +72,6 @@ public:
|
||||
|
||||
GlobalDebuggerOptions *options = Internal::globalDebuggerOptions();
|
||||
SourcePathMap allPathMap = options->sourcePathMap;
|
||||
for (const auto ®ExpMap : qAsConst(options->sourcePathRegExpMap))
|
||||
allPathMap.insert(regExpMap.first.pattern(), regExpMap.second);
|
||||
m_sourceMappingWidget->setSourcePathMap(allPathMap);
|
||||
|
||||
DebuggerSettings &s = *debuggerSettings();
|
||||
@@ -121,17 +119,7 @@ void CommonOptionsPageWidget::apply()
|
||||
m_group.writeSettings(ICore::settings());
|
||||
|
||||
GlobalDebuggerOptions *options = Internal::globalDebuggerOptions();
|
||||
options->sourcePathMap.clear();
|
||||
options->sourcePathRegExpMap.clear();
|
||||
|
||||
SourcePathMap allPathMap = m_sourceMappingWidget->sourcePathMap();
|
||||
for (auto it = allPathMap.begin(), end = allPathMap.end(); it != end; ++it) {
|
||||
const QString key = it.key();
|
||||
if (key.startsWith('('))
|
||||
options->sourcePathRegExpMap.append(qMakePair(QRegularExpression(key), it.value()));
|
||||
else
|
||||
options->sourcePathMap.insert(key, it.value());
|
||||
}
|
||||
options->sourcePathMap = m_sourceMappingWidget->sourcePathMap();
|
||||
options->toSettings();
|
||||
}
|
||||
|
||||
|
@@ -58,7 +58,7 @@ void GlobalDebuggerOptions::toSettings() const
|
||||
{
|
||||
QSettings *s = Core::ICore::settings();
|
||||
s->beginWriteArray(sourcePathMappingArrayNameC);
|
||||
if (!sourcePathMap.isEmpty() || !sourcePathRegExpMap.isEmpty()) {
|
||||
if (!sourcePathMap.isEmpty()) {
|
||||
const QString sourcePathMappingSourceKey(sourcePathMappingSourceKeyC);
|
||||
const QString sourcePathMappingTargetKey(sourcePathMappingTargetKeyC);
|
||||
int i = 0;
|
||||
@@ -69,13 +69,6 @@ void GlobalDebuggerOptions::toSettings() const
|
||||
s->setValue(sourcePathMappingSourceKey, it.key());
|
||||
s->setValue(sourcePathMappingTargetKey, it.value());
|
||||
}
|
||||
for (auto it = sourcePathRegExpMap.constBegin(), cend = sourcePathRegExpMap.constEnd();
|
||||
it != cend;
|
||||
++it, ++i) {
|
||||
s->setArrayIndex(i);
|
||||
s->setValue(sourcePathMappingSourceKey, it->first.pattern());
|
||||
s->setValue(sourcePathMappingTargetKey, it->second);
|
||||
}
|
||||
}
|
||||
s->endArray();
|
||||
}
|
||||
@@ -91,10 +84,7 @@ void GlobalDebuggerOptions::fromSettings()
|
||||
s->setArrayIndex(i);
|
||||
const QString key = s->value(sourcePathMappingSourceKey).toString();
|
||||
const QString value = s->value(sourcePathMappingTargetKey).toString();
|
||||
if (key.startsWith('('))
|
||||
sourcePathRegExpMap.append(qMakePair(QRegularExpression(key), value));
|
||||
else
|
||||
sourcePathMap.insert(key, value);
|
||||
sourcePathMap.insert(key, value);
|
||||
}
|
||||
}
|
||||
s->endArray();
|
||||
|
@@ -28,7 +28,6 @@
|
||||
#include <QCoreApplication>
|
||||
#include <QHash>
|
||||
#include <QMap>
|
||||
#include <QRegularExpression>
|
||||
#include <QVector>
|
||||
|
||||
#include <utils/aspects.h>
|
||||
@@ -37,7 +36,6 @@ namespace Debugger {
|
||||
namespace Internal {
|
||||
|
||||
using SourcePathMap = QMap<QString, QString>;
|
||||
using SourcePathRegExpMap = QVector<QPair<QRegularExpression, QString>>;
|
||||
|
||||
// Global debugger options that are not stored as saved action.
|
||||
class GlobalDebuggerOptions
|
||||
@@ -46,8 +44,13 @@ public:
|
||||
void toSettings() const;
|
||||
void fromSettings();
|
||||
|
||||
// Entries starting with '(' are considered regular expressions in the ElfReader.
|
||||
// This is useful when there are multiple build machines with different
|
||||
// path, and the user would like to match anything up to some known
|
||||
// directory to his local project.
|
||||
// Syntax: (/home/.*)/KnownSubdir -> /home/my/project
|
||||
|
||||
SourcePathMap sourcePathMap;
|
||||
SourcePathRegExpMap sourcePathRegExpMap;
|
||||
};
|
||||
|
||||
class GeneralSettings
|
||||
|
@@ -2813,12 +2813,14 @@ void CppDebuggerEngine::validateRunParameters(DebuggerRunParameters &rp)
|
||||
bool hasLink = elfData.indexOf(".gnu_debuglink") >= 0;
|
||||
if (hasEmbeddedInfo) {
|
||||
const GlobalDebuggerOptions *options = Internal::globalDebuggerOptions();
|
||||
SourcePathRegExpMap globalRegExpSourceMap;
|
||||
globalRegExpSourceMap.reserve(options->sourcePathRegExpMap.size());
|
||||
for (const auto &entry : qAsConst(options->sourcePathRegExpMap)) {
|
||||
const QString expanded = Utils::globalMacroExpander()->expand(entry.second);
|
||||
if (!expanded.isEmpty())
|
||||
globalRegExpSourceMap.push_back(qMakePair(entry.first, expanded));
|
||||
QList<QPair<QRegularExpression, QString>> globalRegExpSourceMap;
|
||||
globalRegExpSourceMap.reserve(options->sourcePathMap.size());
|
||||
for (auto it = options->sourcePathMap.begin(), end = options->sourcePathMap.end(); it != end; ++it) {
|
||||
if (it.key().startsWith('(')) {
|
||||
const QString expanded = Utils::globalMacroExpander()->expand(it.value());
|
||||
if (!expanded.isEmpty())
|
||||
globalRegExpSourceMap.push_back(qMakePair(it.key(), expanded));
|
||||
}
|
||||
}
|
||||
if (globalRegExpSourceMap.isEmpty())
|
||||
return;
|
||||
@@ -2828,13 +2830,11 @@ void CppDebuggerEngine::validateRunParameters(DebuggerRunParameters &rp)
|
||||
bool found = false;
|
||||
while (str < limit) {
|
||||
const QString string = QString::fromUtf8(str);
|
||||
for (auto itExp = globalRegExpSourceMap.begin(), itEnd = globalRegExpSourceMap.end();
|
||||
itExp != itEnd;
|
||||
++itExp) {
|
||||
const QRegularExpressionMatch match = itExp->first.match(string);
|
||||
for (auto pair : qAsConst(globalRegExpSourceMap)) {
|
||||
const QRegularExpressionMatch match = pair.first.match(string);
|
||||
if (match.hasMatch()) {
|
||||
rp.sourcePathMap.insert(string.left(match.capturedStart()) + match.captured(1),
|
||||
itExp->second);
|
||||
pair.second);
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
|
Reference in New Issue
Block a user