diff --git a/src/libs/utils/filesearch.cpp b/src/libs/utils/filesearch.cpp index d7d4113c006..877c859be27 100644 --- a/src/libs/utils/filesearch.cpp +++ b/src/libs/utils/filesearch.cpp @@ -108,9 +108,10 @@ void runFileSearch(QFutureInterface &future, const char *beforeRegion = regionPtr - 1; bool equal = true; if (wholeWord && - ( ((*beforeRegion >= '0' && *beforeRegion <= '9') || *beforeRegion >= 'A') - || ((*afterRegion >= '0' && *afterRegion <= '9') || *afterRegion >= 'A'))) - { + ( isalnum(*beforeRegion) + || (*beforeRegion == '_') + || isalnum(*afterRegion) + || (*afterRegion == '_'))) { equal = false; } diff --git a/src/plugins/cpptools/cppmodelmanager.cpp b/src/plugins/cpptools/cppmodelmanager.cpp index 3aa8136dff0..a08d66bebef 100644 --- a/src/plugins/cpptools/cppmodelmanager.cpp +++ b/src/plugins/cpptools/cppmodelmanager.cpp @@ -116,7 +116,7 @@ protected: { --depth; } }; -#endif QTCREATOR_WITH_DUMP_AST +#endif // QTCREATOR_WITH_DUMP_AST static const char pp_configuration_file[] = ""; diff --git a/src/plugins/debugger/debuggerdialogs.cpp b/src/plugins/debugger/debuggerdialogs.cpp index b5ccc2dc0db..38abffe91d8 100644 --- a/src/plugins/debugger/debuggerdialogs.cpp +++ b/src/plugins/debugger/debuggerdialogs.cpp @@ -41,6 +41,7 @@ #include #include #include +#include #include #include #include @@ -115,7 +116,7 @@ static QStandardItemModel *createProcessModel(QObject *parent) return rc; } -static bool isProcessName(const QString &procname) +static bool isUnixProcessId(const QString &procname) { for (int i = 0; i != procname.size(); ++i) if (!procname.at(i).isDigit()) @@ -134,31 +135,45 @@ QT_END_NAMESPACE static QList unixProcessList() { QList rc; - const QStringList procnames = QDir(QLatin1String("/proc/")).entryList(); - if (procnames.isEmpty()) + const QStringList procIds = QDir(QLatin1String("/proc/")).entryList(); + if (procIds.isEmpty()) return rc; - foreach (const QString &procname, procnames) { - if (!isProcessName(procname)) + foreach (const QString &procId, procIds) { + if (!isUnixProcessId(procId)) continue; QString filename = QLatin1String("/proc/"); - filename += procname; + filename += procId; filename += QLatin1String("/stat"); QFile file(filename); file.open(QIODevice::ReadOnly); const QStringList data = QString::fromLocal8Bit(file.readAll()).split(' '); ProcData proc; + proc.ppid = procId; proc.name = data.at(1); - if (proc.name.startsWith(QLatin1Char('(')) && proc.name.endsWith(QLatin1Char(')'))) - proc.name = proc.name.mid(1, proc.name.size() - 2); + if (proc.name.startsWith(QLatin1Char('(')) && proc.name.endsWith(QLatin1Char(')'))) { + proc.name.truncate(proc.name.size() - 1); + proc.name.remove(0, 1); + } proc.state = data.at(2); - proc.ppid = data.at(3); + // PPID is element 3 rc.push_back(proc); } return rc; } -static void populateProcessModel(QStandardItemModel *model) +static inline QStandardItem *createStandardItem(const QString &text, + bool enabled) +{ + QStandardItem *rc = new QStandardItem(text); + rc->setEnabled(enabled); + return rc; +} + +// Populate a standard item model with a list +// of processes and gray out the excludePid. +static void populateProcessModel(QStandardItemModel *model, + const QString &excludePid = QString()) { #ifdef Q_OS_WIN QList processes = winProcessList(); @@ -169,15 +184,16 @@ static void populateProcessModel(QStandardItemModel *model) if (const int rowCount = model->rowCount()) model->removeRows(0, rowCount); - + QStandardItem *root = model->invisibleRootItem(); foreach(const ProcData &proc, processes) { + const bool enabled = proc.ppid != excludePid; QList row; - row.append(new QStandardItem(proc.ppid)); - row.append(new QStandardItem(proc.name)); + row.append(createStandardItem(proc.ppid, enabled)); + row.append(createStandardItem(proc.name, enabled)); if (!proc.image.isEmpty()) row.back()->setToolTip(proc.image); - row.append(new QStandardItem(proc.state)); + row.append(createStandardItem(proc.state, enabled)); root->appendRow(row); } } @@ -190,12 +206,14 @@ static void populateProcessModel(QStandardItemModel *model) AttachExternalDialog::AttachExternalDialog(QWidget *parent) : QDialog(parent), + m_selfPid(QString::number(QCoreApplication::applicationPid())), m_ui(new Ui::AttachExternalDialog), m_proxyModel(new QSortFilterProxyModel(this)), m_model(createProcessModel(this)) { m_ui->setupUi(this); - m_ui->buttonBox->button(QDialogButtonBox::Ok)->setDefault(true); + okButton()->setDefault(true); + okButton()->setEnabled(false); m_proxyModel->setSourceModel(m_model); m_proxyModel->setFilterCaseSensitivity(Qt::CaseInsensitive); @@ -211,6 +229,9 @@ AttachExternalDialog::AttachExternalDialog(QWidget *parent) : connect(m_ui->procView, SIGNAL(activated(QModelIndex)), this, SLOT(procSelected(QModelIndex))); + connect(m_ui->pidLineEdit, SIGNAL(textChanged(QString)), + this, SLOT(pidChanged(QString))); + connect(m_ui->filterClearToolButton, SIGNAL(clicked()), m_ui->filterLineEdit, SLOT(clear())); connect(m_ui->filterLineEdit, SIGNAL(textChanged(QString)), @@ -224,13 +245,17 @@ AttachExternalDialog::~AttachExternalDialog() delete m_ui; } +QPushButton *AttachExternalDialog::okButton() const +{ + return m_ui->buttonBox->button(QDialogButtonBox::Ok); +} + void AttachExternalDialog::rebuildProcessList() { - populateProcessModel(m_model); + populateProcessModel(m_model, m_selfPid); m_ui->procView->expandAll(); m_ui->procView->resizeColumnToContents(0); m_ui->procView->resizeColumnToContents(1); - m_ui->procView->sortByColumn(1, Qt::AscendingOrder); } void AttachExternalDialog::procSelected(const QModelIndex &proxyIndex) @@ -239,7 +264,8 @@ void AttachExternalDialog::procSelected(const QModelIndex &proxyIndex) QModelIndex index = index0.sibling(index0.row(), 0); if (const QStandardItem *item = m_model->itemFromIndex(index)) { m_ui->pidLineEdit->setText(item->text()); - m_ui->buttonBox->button(QDialogButtonBox::Ok)->animateClick(); + if (okButton()->isEnabled()) + okButton()->animateClick(); } } @@ -248,6 +274,11 @@ int AttachExternalDialog::attachPID() const return m_ui->pidLineEdit->text().toInt(); } +void AttachExternalDialog::pidChanged(const QString &pid) +{ + okButton()->setEnabled(!pid.isEmpty() && pid != m_selfPid); +} + /////////////////////////////////////////////////////////////////////// // // AttachRemoteDialog diff --git a/src/plugins/debugger/debuggerdialogs.h b/src/plugins/debugger/debuggerdialogs.h index 621b978df91..1e11c356f7d 100644 --- a/src/plugins/debugger/debuggerdialogs.h +++ b/src/plugins/debugger/debuggerdialogs.h @@ -37,6 +37,7 @@ QT_BEGIN_NAMESPACE class QModelIndex; class QStandardItemModel; class QSortFilterProxyModel; +class QPushButton; namespace Ui { class AttachCoreDialog; @@ -90,11 +91,15 @@ public: private slots: void rebuildProcessList(); void procSelected(const QModelIndex &); + void pidChanged(const QString &); private: + inline QPushButton *okButton() const; + const QString m_selfPid; + Ui::AttachExternalDialog *m_ui; - QSortFilterProxyModel *m_proxyModel; QStandardItemModel *m_model; + QSortFilterProxyModel *m_proxyModel; }; diff --git a/src/plugins/debugger/debuggermanager.cpp b/src/plugins/debugger/debuggermanager.cpp index 817851a5748..349bc15ebc7 100644 --- a/src/plugins/debugger/debuggermanager.cpp +++ b/src/plugins/debugger/debuggermanager.cpp @@ -798,8 +798,9 @@ static bool determineDebuggerType(const QString &executable, *dt = DebuggerManager::ScriptDebugger; return true; } -#ifndef Q_WS_WIN +#ifndef Q_OS_WIN *dt = DebuggerManager::GdbDebugger; + Q_UNUSED(errorMessage) return true; #else // If a file has PDB files, it has been compiled by VS. diff --git a/src/plugins/debugger/win/dbgwinutils.cpp b/src/plugins/debugger/win/dbgwinutils.cpp index 67028e44c7b..2145f001ad2 100644 --- a/src/plugins/debugger/win/dbgwinutils.cpp +++ b/src/plugins/debugger/win/dbgwinutils.cpp @@ -65,7 +65,7 @@ QList winProcessList() for (bool hasNext = Process32First(snapshot, &pe); hasNext; hasNext = Process32Next(snapshot, &pe)) { ProcData procData; procData.ppid = QString::number(pe.th32ProcessID); - procData.name = QString::fromUtf16(pe.szExeFile); + procData.name = QString::fromUtf16(reinterpret_cast(pe.szExeFile)); #ifdef USE_PSAPI procData.image = imageName(pe.th32ProcessID); #endif