forked from qt-creator/qt-creator
Debugger/Windows: Do not attach to process being debugged.
Reviewed-by: Robert Loehning <robert.loehning@nokia.com> Task-number: QTCREATORBUG-2086
This commit is contained in:
@@ -55,6 +55,7 @@
|
||||
#include <QtGui/QPushButton>
|
||||
#include <QtGui/QProxyModel>
|
||||
#include <QtGui/QSortFilterProxyModel>
|
||||
#include <QtGui/QMessageBox>
|
||||
|
||||
using namespace Utils;
|
||||
|
||||
@@ -424,6 +425,20 @@ void AttachExternalDialog::pidChanged(const QString &pid)
|
||||
okButton()->setEnabled(enabled);
|
||||
}
|
||||
|
||||
void AttachExternalDialog::accept()
|
||||
{
|
||||
#ifdef Q_OS_WIN
|
||||
const qint64 pid = attachPID();
|
||||
if (pid && isWinProcessBeingDebugged(pid)) {
|
||||
QMessageBox::warning(this, tr("Process Already Under Debugger Control"),
|
||||
tr("The process %1 is already under the control of a debugger.\n"
|
||||
"Qt Creator cannot attach to it.").arg(pid));
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
QDialog::accept();
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
|
||||
@@ -92,6 +92,8 @@ public:
|
||||
qint64 attachPID() const;
|
||||
QString executable() const;
|
||||
|
||||
virtual void accept();
|
||||
|
||||
private slots:
|
||||
void rebuildProcessList();
|
||||
void procSelected(const QModelIndex &index);
|
||||
|
||||
@@ -242,5 +242,16 @@ QString winNormalizeFileName(const QString &f)
|
||||
return rc.isEmpty() ? f : rc;
|
||||
}
|
||||
|
||||
bool isWinProcessBeingDebugged(unsigned long pid)
|
||||
{
|
||||
HANDLE processHandle = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, pid);
|
||||
if (processHandle == NULL)
|
||||
return false;
|
||||
BOOL debugged = FALSE;
|
||||
CheckRemoteDebuggerPresent(processHandle, &debugged);
|
||||
CloseHandle(processHandle);
|
||||
return debugged != FALSE;
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace Debugger
|
||||
|
||||
@@ -57,6 +57,8 @@ unsigned long winGetCurrentProcessId();
|
||||
|
||||
QString winNormalizeFileName(const QString &f);
|
||||
|
||||
bool isWinProcessBeingDebugged(unsigned long pid);
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace Debugger
|
||||
|
||||
|
||||
Reference in New Issue
Block a user