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
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)) {
m_symbolAddressCache.insert(symbol, address);
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
// 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"))
continue;
if (line.startsWith("ChildEBP")) {

View File

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

View File

@@ -497,7 +497,8 @@ DisassemblerLines parseCdbDisassembler(const QString &a)
quint64 functionOffset = 0;
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.
if (parseCdbDisassemblerFunctionLine(line, &currentFunction, &functionOffset, &sourceFile)) {
functionAddress = 0;

View File

@@ -248,7 +248,7 @@ QWidget *CommonOptionsPage::widget()
}
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);
m_sourceMappingWidget->setSourcePathMap(allPathMap);
}

View File

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

View File

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

View File

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