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:
hjk
2021-03-05 08:01:17 +01:00
parent ee13340bdc
commit 7ccd9d6943
4 changed files with 20 additions and 39 deletions

View File

@@ -72,8 +72,6 @@ public:
GlobalDebuggerOptions *options = Internal::globalDebuggerOptions(); GlobalDebuggerOptions *options = Internal::globalDebuggerOptions();
SourcePathMap allPathMap = options->sourcePathMap; SourcePathMap allPathMap = options->sourcePathMap;
for (const auto &regExpMap : qAsConst(options->sourcePathRegExpMap))
allPathMap.insert(regExpMap.first.pattern(), regExpMap.second);
m_sourceMappingWidget->setSourcePathMap(allPathMap); m_sourceMappingWidget->setSourcePathMap(allPathMap);
DebuggerSettings &s = *debuggerSettings(); DebuggerSettings &s = *debuggerSettings();
@@ -121,17 +119,7 @@ void CommonOptionsPageWidget::apply()
m_group.writeSettings(ICore::settings()); m_group.writeSettings(ICore::settings());
GlobalDebuggerOptions *options = Internal::globalDebuggerOptions(); GlobalDebuggerOptions *options = Internal::globalDebuggerOptions();
options->sourcePathMap.clear(); options->sourcePathMap = m_sourceMappingWidget->sourcePathMap();
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->toSettings(); options->toSettings();
} }

View File

@@ -58,7 +58,7 @@ void GlobalDebuggerOptions::toSettings() const
{ {
QSettings *s = Core::ICore::settings(); QSettings *s = Core::ICore::settings();
s->beginWriteArray(sourcePathMappingArrayNameC); s->beginWriteArray(sourcePathMappingArrayNameC);
if (!sourcePathMap.isEmpty() || !sourcePathRegExpMap.isEmpty()) { if (!sourcePathMap.isEmpty()) {
const QString sourcePathMappingSourceKey(sourcePathMappingSourceKeyC); const QString sourcePathMappingSourceKey(sourcePathMappingSourceKeyC);
const QString sourcePathMappingTargetKey(sourcePathMappingTargetKeyC); const QString sourcePathMappingTargetKey(sourcePathMappingTargetKeyC);
int i = 0; int i = 0;
@@ -69,13 +69,6 @@ void GlobalDebuggerOptions::toSettings() const
s->setValue(sourcePathMappingSourceKey, it.key()); s->setValue(sourcePathMappingSourceKey, it.key());
s->setValue(sourcePathMappingTargetKey, it.value()); 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(); s->endArray();
} }
@@ -91,10 +84,7 @@ void GlobalDebuggerOptions::fromSettings()
s->setArrayIndex(i); s->setArrayIndex(i);
const QString key = s->value(sourcePathMappingSourceKey).toString(); const QString key = s->value(sourcePathMappingSourceKey).toString();
const QString value = s->value(sourcePathMappingTargetKey).toString(); const QString value = s->value(sourcePathMappingTargetKey).toString();
if (key.startsWith('(')) sourcePathMap.insert(key, value);
sourcePathRegExpMap.append(qMakePair(QRegularExpression(key), value));
else
sourcePathMap.insert(key, value);
} }
} }
s->endArray(); s->endArray();

View File

@@ -28,7 +28,6 @@
#include <QCoreApplication> #include <QCoreApplication>
#include <QHash> #include <QHash>
#include <QMap> #include <QMap>
#include <QRegularExpression>
#include <QVector> #include <QVector>
#include <utils/aspects.h> #include <utils/aspects.h>
@@ -37,7 +36,6 @@ namespace Debugger {
namespace Internal { namespace Internal {
using SourcePathMap = QMap<QString, QString>; using SourcePathMap = QMap<QString, QString>;
using SourcePathRegExpMap = QVector<QPair<QRegularExpression, QString>>;
// Global debugger options that are not stored as saved action. // Global debugger options that are not stored as saved action.
class GlobalDebuggerOptions class GlobalDebuggerOptions
@@ -46,8 +44,13 @@ public:
void toSettings() const; void toSettings() const;
void fromSettings(); 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; SourcePathMap sourcePathMap;
SourcePathRegExpMap sourcePathRegExpMap;
}; };
class GeneralSettings class GeneralSettings

View File

@@ -2813,12 +2813,14 @@ void CppDebuggerEngine::validateRunParameters(DebuggerRunParameters &rp)
bool hasLink = elfData.indexOf(".gnu_debuglink") >= 0; bool hasLink = elfData.indexOf(".gnu_debuglink") >= 0;
if (hasEmbeddedInfo) { if (hasEmbeddedInfo) {
const GlobalDebuggerOptions *options = Internal::globalDebuggerOptions(); const GlobalDebuggerOptions *options = Internal::globalDebuggerOptions();
SourcePathRegExpMap globalRegExpSourceMap; QList<QPair<QRegularExpression, QString>> globalRegExpSourceMap;
globalRegExpSourceMap.reserve(options->sourcePathRegExpMap.size()); globalRegExpSourceMap.reserve(options->sourcePathMap.size());
for (const auto &entry : qAsConst(options->sourcePathRegExpMap)) { for (auto it = options->sourcePathMap.begin(), end = options->sourcePathMap.end(); it != end; ++it) {
const QString expanded = Utils::globalMacroExpander()->expand(entry.second); if (it.key().startsWith('(')) {
if (!expanded.isEmpty()) const QString expanded = Utils::globalMacroExpander()->expand(it.value());
globalRegExpSourceMap.push_back(qMakePair(entry.first, expanded)); if (!expanded.isEmpty())
globalRegExpSourceMap.push_back(qMakePair(it.key(), expanded));
}
} }
if (globalRegExpSourceMap.isEmpty()) if (globalRegExpSourceMap.isEmpty())
return; return;
@@ -2828,13 +2830,11 @@ void CppDebuggerEngine::validateRunParameters(DebuggerRunParameters &rp)
bool found = false; bool found = false;
while (str < limit) { while (str < limit) {
const QString string = QString::fromUtf8(str); const QString string = QString::fromUtf8(str);
for (auto itExp = globalRegExpSourceMap.begin(), itEnd = globalRegExpSourceMap.end(); for (auto pair : qAsConst(globalRegExpSourceMap)) {
itExp != itEnd; const QRegularExpressionMatch match = pair.first.match(string);
++itExp) {
const QRegularExpressionMatch match = itExp->first.match(string);
if (match.hasMatch()) { if (match.hasMatch()) {
rp.sourcePathMap.insert(string.left(match.capturedStart()) + match.captured(1), rp.sourcePathMap.insert(string.left(match.capturedStart()) + match.captured(1),
itExp->second); pair.second);
found = true; found = true;
break; break;
} }