Debugger: Code cosmetics

Remove uses of foreach, ...

Change-Id: I3997d4dffc63d58c386c70b08063ecb894ef1abb
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
hjk
2019-07-25 17:27:58 +02:00
parent 76b6a36bb1
commit 7705fbb701
8 changed files with 32 additions and 26 deletions

View File

@@ -1319,7 +1319,8 @@ void CdbEngine::handleResolveSymbol(const DebuggerResponse &response, const QStr
{ {
// Insert all matches of (potentially) ambiguous symbols // Insert all matches of (potentially) ambiguous symbols
if (!response.data.data().isEmpty()) { if (!response.data.data().isEmpty()) {
foreach (const QString &line, response.data.data().split('\n')) { const QStringList lines = response.data.data().split('\n');
for (const QString &line : lines) {
if (const quint64 address = resolvedAddress(line)) { if (const quint64 address = resolvedAddress(line)) {
m_symbolAddressCache.insert(symbol, address); m_symbolAddressCache.insert(symbol, address);
showMessage(QString("Obtained 0x%1 for %2"). showMessage(QString("Obtained 0x%1 for %2").
@@ -1939,7 +1940,8 @@ void CdbEngine::ensureUsing32BitStackInWow64(const DebuggerResponse &response, c
{ {
// Parsing the header of the stack output to check which bitness // Parsing the header of the stack output to check which bitness
// the cdb is currently using. // the cdb is currently using.
foreach (const QStringRef &line, response.data.data().splitRef('\n')) { const QVector<QStringRef> lines = response.data.data().splitRef('\n');
for (const QStringRef &line : lines) {
if (!line.startsWith("Child")) if (!line.startsWith("Child"))
continue; continue;
if (line.startsWith("ChildEBP")) { if (line.startsWith("ChildEBP")) {

View File

@@ -107,11 +107,11 @@ CdbBreakEventWidget::CdbBreakEventWidget(QWidget *parent) : QWidget(parent)
void CdbBreakEventWidget::clear() void CdbBreakEventWidget::clear()
{ {
foreach (QLineEdit *l, m_lineEdits) { for (QLineEdit *l : qAsConst(m_lineEdits)) {
if (l) if (l)
l->clear(); l->clear();
} }
foreach (QCheckBox *c, m_checkBoxes) for (QCheckBox *c : qAsConst(m_checkBoxes))
c->setChecked(false); c->setChecked(false);
} }

View File

@@ -497,7 +497,8 @@ DisassemblerLines parseCdbDisassembler(const QString &a)
quint64 functionOffset = 0; quint64 functionOffset = 0;
QString sourceFile; QString sourceFile;
foreach (const QString &line, a.split('\n')) { const QStringList lines = a.split('\n');
for (const QString &line : lines) {
// New function. Append as comment line. // New function. Append as comment line.
if (parseCdbDisassemblerFunctionLine(line, &currentFunction, &functionOffset, &sourceFile)) { if (parseCdbDisassemblerFunctionLine(line, &currentFunction, &functionOffset, &sourceFile)) {
functionAddress = 0; functionAddress = 0;

View File

@@ -248,7 +248,7 @@ QWidget *CommonOptionsPage::widget()
} }
SourcePathMap allPathMap = m_options->sourcePathMap; SourcePathMap allPathMap = m_options->sourcePathMap;
foreach (auto regExpMap, m_options->sourcePathRegExpMap) for (auto regExpMap : qAsConst(m_options->sourcePathRegExpMap))
allPathMap.insert(regExpMap.first.pattern(), regExpMap.second); allPathMap.insert(regExpMap.first.pattern(), regExpMap.second);
m_sourceMappingWidget->setSourcePathMap(allPathMap); m_sourceMappingWidget->setSourcePathMap(allPathMap);
} }

View File

@@ -668,27 +668,27 @@ void DebuggerSettings::insertItem(int code, SavedAction *item)
void DebuggerSettings::readSettings() void DebuggerSettings::readSettings()
{ {
QSettings *settings = Core::ICore::settings(); QSettings *settings = Core::ICore::settings();
foreach (SavedAction *item, m_items) for (SavedAction *item : qAsConst(m_items))
item->readSettings(settings); item->readSettings(settings);
} }
void DebuggerSettings::writeSettings() const void DebuggerSettings::writeSettings() const
{ {
QSettings *settings = Core::ICore::settings(); QSettings *settings = Core::ICore::settings();
foreach (SavedAction *item, m_items) for (SavedAction *item : qAsConst(m_items))
item->writeSettings(settings); item->writeSettings(settings);
} }
SavedAction *DebuggerSettings::item(int code) const SavedAction *DebuggerSettings::item(int code) const
{ {
QTC_ASSERT(m_items.value(code, 0), qDebug() << "CODE: " << code; return nullptr); QTC_ASSERT(m_items.value(code, nullptr), qDebug() << "CODE: " << code; return nullptr);
return m_items.value(code, 0); return m_items.value(code, nullptr);
} }
QString DebuggerSettings::dump() QString DebuggerSettings::dump()
{ {
QStringList settings; QStringList settings;
foreach (SavedAction *item, theDebuggerSettings->m_items) { for (SavedAction *item : qAsConst(theDebuggerSettings->m_items)) {
QString key = item->settingsKey(); QString key = item->settingsKey();
if (!key.isEmpty()) { if (!key.isEmpty()) {
const QString current = item->value().toString(); const QString current = item->value().toString();

View File

@@ -225,7 +225,7 @@ public:
{ {
auto agent = new MemoryAgent(data, engine); auto agent = new MemoryAgent(data, engine);
if (agent->isUsable()) { if (agent->isUsable()) {
m_agents.append(agent); m_agents.push_back(agent);
} else { } else {
delete agent; delete agent;
AsynchronousMessageBox::warning( AsynchronousMessageBox::warning(
@@ -238,7 +238,7 @@ public:
// On stack frame completed and on request. // On stack frame completed and on request.
void updateContents() void updateContents()
{ {
foreach (MemoryAgent *agent, m_agents) { for (MemoryAgent *agent : m_agents) {
if (agent) if (agent)
agent->updateContents(); agent->updateContents();
} }
@@ -246,14 +246,14 @@ public:
void handleDebuggerFinished() void handleDebuggerFinished()
{ {
foreach (MemoryAgent *agent, m_agents) { for (MemoryAgent *agent : m_agents) {
if (agent) if (agent)
agent->setFinished(); // Prevent triggering updates, etc. agent->setFinished(); // Prevent triggering updates, etc.
} }
} }
private: private:
QList<MemoryAgent *> m_agents; std::vector<MemoryAgent *> m_agents;
}; };
@@ -2698,7 +2698,7 @@ void CppDebuggerEngine::validateRunParameters(DebuggerRunParameters &rp)
QSharedPointer<GlobalDebuggerOptions> options = Internal::globalDebuggerOptions(); QSharedPointer<GlobalDebuggerOptions> options = Internal::globalDebuggerOptions();
SourcePathRegExpMap globalRegExpSourceMap; SourcePathRegExpMap globalRegExpSourceMap;
globalRegExpSourceMap.reserve(options->sourcePathRegExpMap.size()); globalRegExpSourceMap.reserve(options->sourcePathRegExpMap.size());
foreach (auto entry, options->sourcePathRegExpMap) { for (auto entry : qAsConst(options->sourcePathRegExpMap)) {
const QString expanded = Utils::globalMacroExpander()->expand(entry.second); const QString expanded = Utils::globalMacroExpander()->expand(entry.second);
if (!expanded.isEmpty()) if (!expanded.isEmpty())
globalRegExpSourceMap.push_back(qMakePair(entry.first, expanded)); globalRegExpSourceMap.push_back(qMakePair(entry.first, expanded));
@@ -2735,7 +2735,7 @@ void CppDebuggerEngine::validateRunParameters(DebuggerRunParameters &rp)
if (hasEmbeddedInfo || hasLink) if (hasEmbeddedInfo || hasLink)
return; return;
foreach (const QByteArray &name, interesting) { for (const QByteArray &name : qAsConst(interesting)) {
const QString found = seen.contains(name) ? DebuggerEngine::tr("Found.") const QString found = seen.contains(name) ? DebuggerEngine::tr("Found.")
: DebuggerEngine::tr("Not found."); : DebuggerEngine::tr("Not found.");
detailedWarning.append('\n' + DebuggerEngine::tr("Section %1: %2").arg(QString::fromUtf8(name)).arg(found)); detailedWarning.append('\n' + DebuggerEngine::tr("Section %1: %2").arg(QString::fromUtf8(name)).arg(found));

View File

@@ -115,7 +115,8 @@ DebuggerItem::DebuggerItem(const QVariantMap &data)
static_cast<int>(NoEngineType)).toInt()); static_cast<int>(NoEngineType)).toInt());
m_lastModified = data.value(DEBUGGER_INFORMATION_LASTMODIFIED).toDateTime(); m_lastModified = data.value(DEBUGGER_INFORMATION_LASTMODIFIED).toDateTime();
foreach (const QString &a, data.value(DEBUGGER_INFORMATION_ABIS).toStringList()) { const QStringList abis = data.value(DEBUGGER_INFORMATION_ABIS).toStringList();
for (const QString &a : abis) {
Abi abi = Abi::fromString(a); Abi abi = Abi::fromString(a);
if (!abi.isNull()) if (!abi.isNull())
m_abis.append(abi); m_abis.append(abi);

View File

@@ -350,8 +350,9 @@ DebuggerItem DebuggerItemConfigWidget::item() const
item.setCommand(m_binaryChooser->fileName()); item.setCommand(m_binaryChooser->fileName());
item.setWorkingDirectory(m_workingDirectoryChooser->fileName()); item.setWorkingDirectory(m_workingDirectoryChooser->fileName());
item.setAutoDetected(m_autodetected); item.setAutoDetected(m_autodetected);
ProjectExplorer::Abis abiList; Abis abiList;
foreach (const QString &a, m_abis->text().split(QRegExp("[^A-Za-z0-9-_]+"))) { const QStringList abis = m_abis->text().split(QRegExp("[^A-Za-z0-9-_]+"));
for (const QString &a : abis) {
if (a.isNull()) if (a.isNull())
continue; continue;
abiList << Abi::fromString(a); abiList << Abi::fromString(a);
@@ -770,19 +771,20 @@ void DebuggerItemManagerPrivate::autoDetectGdbOrLldbDebuggers()
} }
} }
Utils::FilePathList path = Environment::systemEnvironment().path(); FilePathList path = Utils::filteredUnique(
path << searchGdbPathsFromRegistry(); Environment::systemEnvironment().path() + searchGdbPathsFromRegistry());
path = Utils::filteredUnique(path);
QDir dir; QDir dir;
dir.setNameFilters(filters); dir.setNameFilters(filters);
dir.setFilter(QDir::Files | QDir::Executable); dir.setFilter(QDir::Files | QDir::Executable);
foreach (const Utils::FilePath &base, path) { for (const FilePath &base : path) {
dir.setPath(base.toFileInfo().absoluteFilePath()); dir.setPath(base.toFileInfo().absoluteFilePath());
foreach (const QString &entry, dir.entryList()) const QStringList entries = dir.entryList();
for (const QString &entry : entries)
suspects.append(FilePath::fromString(dir.absoluteFilePath(entry))); suspects.append(FilePath::fromString(dir.absoluteFilePath(entry)));
} }
foreach (const FilePath &command, suspects) { for (const FilePath &command : qAsConst(suspects)) {
const auto commandMatches = [command](const DebuggerTreeItem *titem) { const auto commandMatches = [command](const DebuggerTreeItem *titem) {
return titem->m_item.command() == command; return titem->m_item.command() == command;
}; };