forked from qt-creator/qt-creator
Code polishing, continuing cb23999fbf
Add more error messages to processes run for toolchain detection. Move Windows-specific code to dbgwinutils, remove inclusion of <windows.h>. Fix MinGW gcc 4.5 warnings.
This commit is contained in:
@@ -50,7 +50,7 @@
|
||||
#include <QtNetwork/QTcpSocket>
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
# include <windows.h>
|
||||
# include "dbgwinutils.h"
|
||||
#else
|
||||
# include <sys/types.h>
|
||||
# include <unistd.h>
|
||||
@@ -127,7 +127,7 @@ TcfTrkGdbAdapter::TcfTrkGdbAdapter(GdbEngine *engine) :
|
||||
m_gdbConnection = 0;
|
||||
m_snapshot.reset();
|
||||
#ifdef Q_OS_WIN
|
||||
const DWORD portOffset = GetCurrentProcessId() % 100;
|
||||
const unsigned long portOffset = winGetCurrentProcessId() % 100;
|
||||
#else
|
||||
const uid_t portOffset = getuid();
|
||||
#endif
|
||||
|
||||
@@ -39,12 +39,9 @@
|
||||
#include <QtGui/QMessageBox>
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
# ifdef __GNUC__ // Required for OpenThread under MinGW
|
||||
# define _WIN32_WINNT 0x0502
|
||||
# endif // __GNUC__
|
||||
# include <windows.h>
|
||||
# include <utils/winutils.h>
|
||||
#endif // Q_OS_WIN
|
||||
# include "dbgwinutils.h"
|
||||
# include "dbgwinutils.h"
|
||||
#endif
|
||||
|
||||
namespace Debugger {
|
||||
namespace Internal {
|
||||
@@ -138,42 +135,23 @@ void TermGdbAdapter::setupInferior()
|
||||
CB(handleStubAttached));
|
||||
}
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
static bool resumeThread(DWORD dwThreadId)
|
||||
{
|
||||
bool ok = false;
|
||||
HANDLE handle = NULL;
|
||||
do {
|
||||
if (!dwThreadId)
|
||||
break;
|
||||
|
||||
handle = OpenThread(SYNCHRONIZE |THREAD_QUERY_INFORMATION |THREAD_SUSPEND_RESUME,
|
||||
FALSE, dwThreadId);
|
||||
if (handle==NULL)
|
||||
break;
|
||||
|
||||
ok = ResumeThread(handle) != DWORD(-1);
|
||||
} while (false);
|
||||
if (handle != NULL)
|
||||
CloseHandle(handle);
|
||||
return ok;
|
||||
}
|
||||
#endif // Q_OS_WIN
|
||||
|
||||
void TermGdbAdapter::handleStubAttached(const GdbResponse &response)
|
||||
{
|
||||
QTC_ASSERT(state() == InferiorSetupRequested, qDebug() << state());
|
||||
#ifdef Q_OS_WIN
|
||||
QString errorMessage;
|
||||
#endif // Q_OS_WIN
|
||||
switch (response.resultClass) {
|
||||
case GdbResultDone:
|
||||
case GdbResultRunning:
|
||||
#ifdef Q_OS_WIN
|
||||
// Resume thread that was suspended by console stub process (see stub code).
|
||||
if (resumeThread(m_stubProc.applicationMainThreadID())) {
|
||||
if (winResumeThread(m_stubProc.applicationMainThreadID(), &errorMessage)) {
|
||||
showMessage(QString::fromLatin1("Inferior attached, thread %1 resumed").
|
||||
arg(m_stubProc.applicationMainThreadID()), LogMisc);
|
||||
} else {
|
||||
showMessage(QString::fromLatin1("Inferior attached, unable to resume thread %1: %2").
|
||||
arg(m_stubProc.applicationMainThreadID()).arg(Utils::winErrorMessage(GetLastError())),
|
||||
arg(m_stubProc.applicationMainThreadID()).arg(errorMessage),
|
||||
LogWarning);
|
||||
}
|
||||
#else
|
||||
|
||||
@@ -52,7 +52,7 @@
|
||||
#include <QtNetwork/QTcpSocket>
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
# include <windows.h>
|
||||
# include "dbgwinutils.h"
|
||||
#else
|
||||
# include <sys/types.h>
|
||||
# include <unistd.h>
|
||||
@@ -100,7 +100,7 @@ TrkGdbAdapter::TrkGdbAdapter(GdbEngine *engine) :
|
||||
m_gdbConnection = 0;
|
||||
m_snapshot.reset();
|
||||
#ifdef Q_OS_WIN
|
||||
const DWORD portOffset = GetCurrentProcessId() % 100;
|
||||
const unsigned long portOffset = winGetCurrentProcessId() % 100;
|
||||
#else
|
||||
const uid_t portOffset = getuid();
|
||||
#endif
|
||||
|
||||
@@ -31,8 +31,19 @@
|
||||
#include "debuggerdialogs.h"
|
||||
|
||||
#include <QtCore/QDebug>
|
||||
#include <QtCore/QString>
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
# ifdef __GNUC__ // Required for OpenThread under MinGW
|
||||
# define _WIN32_WINNT 0x0502
|
||||
# endif // __GNUC__
|
||||
# include <windows.h>
|
||||
# include <utils/winutils.h>
|
||||
# if !defined(PROCESS_SUSPEND_RESUME) // Check flag for MinGW
|
||||
# define PROCESS_SUSPEND_RESUME (0x0800)
|
||||
# endif // PROCESS_SUSPEND_RESUME
|
||||
#endif // Q_OS_WIN
|
||||
|
||||
#include <windows.h>
|
||||
#include <tlhelp32.h>
|
||||
#include <psapi.h>
|
||||
#include <QtCore/QLibrary>
|
||||
@@ -98,5 +109,63 @@ QList<ProcData> winProcessList()
|
||||
return rc;
|
||||
}
|
||||
|
||||
bool winResumeThread(unsigned long dwThreadId, QString *errorMessage)
|
||||
{
|
||||
bool ok = false;
|
||||
HANDLE handle = NULL;
|
||||
do {
|
||||
if (!dwThreadId)
|
||||
break;
|
||||
|
||||
handle = OpenThread(SYNCHRONIZE |THREAD_QUERY_INFORMATION |THREAD_SUSPEND_RESUME,
|
||||
FALSE, dwThreadId);
|
||||
if (handle==NULL) {
|
||||
*errorMessage = QString::fromLatin1("Unable to open thread %1: %2").
|
||||
arg(dwThreadId).arg(Utils::winErrorMessage(GetLastError()));
|
||||
break;
|
||||
}
|
||||
if (ResumeThread(handle) == DWORD(-1)) {
|
||||
*errorMessage = QString::fromLatin1("Unable to resume thread %1: %2").
|
||||
arg(dwThreadId).arg(Utils::winErrorMessage(GetLastError()));
|
||||
break;
|
||||
}
|
||||
ok = true;
|
||||
} while (false);
|
||||
if (handle != NULL)
|
||||
CloseHandle(handle);
|
||||
return ok;
|
||||
}
|
||||
|
||||
// Open the process and break into it
|
||||
bool winDebugBreakProcess(unsigned long pid, QString *errorMessage)
|
||||
{
|
||||
bool ok = false;
|
||||
HANDLE inferior = NULL;
|
||||
do {
|
||||
const DWORD rights = PROCESS_QUERY_INFORMATION|PROCESS_SET_INFORMATION
|
||||
|PROCESS_VM_OPERATION|PROCESS_VM_WRITE|PROCESS_VM_READ
|
||||
|PROCESS_DUP_HANDLE|PROCESS_TERMINATE|PROCESS_CREATE_THREAD|PROCESS_SUSPEND_RESUME ;
|
||||
inferior = OpenProcess(rights, FALSE, pid);
|
||||
if (inferior == NULL) {
|
||||
*errorMessage = QString::fromLatin1("Cannot open process %1: %2").
|
||||
arg(pid).arg(Utils::winErrorMessage(GetLastError()));
|
||||
break;
|
||||
}
|
||||
if (!DebugBreakProcess(inferior)) {
|
||||
*errorMessage = QString::fromLatin1("DebugBreakProcess failed: %1").arg(Utils::winErrorMessage(GetLastError()));
|
||||
break;
|
||||
}
|
||||
ok = true;
|
||||
} while (false);
|
||||
if (inferior != NULL)
|
||||
CloseHandle(inferior);
|
||||
return ok;
|
||||
}
|
||||
|
||||
unsigned long winGetCurrentProcessId()
|
||||
{
|
||||
return GetCurrentProcessId();
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace Debugger
|
||||
|
||||
@@ -32,6 +32,8 @@
|
||||
|
||||
#include <QtCore/QList>
|
||||
|
||||
QT_FORWARD_DECLARE_CLASS(QString)
|
||||
|
||||
namespace Debugger {
|
||||
namespace Internal {
|
||||
|
||||
@@ -39,6 +41,14 @@ struct ProcData; // debuggerdialogs, used by the process listing dialogs
|
||||
|
||||
QList<ProcData> winProcessList();
|
||||
|
||||
// Resume a suspended thread by id.
|
||||
bool winResumeThread(unsigned long dwThreadId, QString *errorMessage);
|
||||
|
||||
// Open a process by PID and break into it.
|
||||
bool winDebugBreakProcess(unsigned long pid, QString *errorMessage);
|
||||
|
||||
unsigned long winGetCurrentProcessId();
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace Debugger
|
||||
|
||||
|
||||
Reference in New Issue
Block a user