forked from qt-creator/qt-creator
Fix MinGW valgrind build
QueryFullProcessImageName is only available on Windows >= Vista. iSetting _WIN32_WINNT fixes availability on MinGW and moving the functionality to winutils avoids code duplication. Change-Id: I0ff1a12a1c092b1ad9cde75b636b52c5b959ce7d Reviewed-by: Orgad Shaneh <orgads@gmail.com> Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -26,10 +26,10 @@
|
|||||||
#include "winutils.h"
|
#include "winutils.h"
|
||||||
#include "qtcassert.h"
|
#include "qtcassert.h"
|
||||||
|
|
||||||
// Enable WinAPI Windows XP and later
|
// Enable WinAPI Windows Vista and later
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
#undef _WIN32_WINNT
|
#undef _WIN32_WINNT
|
||||||
#define _WIN32_WINNT 0x0501
|
#define _WIN32_WINNT 0x0600 // Needed for QueryFullProcessImageName
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -168,6 +168,23 @@ QTCREATOR_UTILS_EXPORT bool is64BitWindowsBinary(const QString &binaryIn)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QTCREATOR_UTILS_EXPORT QString imageName(quint32 processId)
|
||||||
|
{
|
||||||
|
QString result;
|
||||||
|
#ifdef Q_OS_WIN
|
||||||
|
HANDLE handle = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, processId);
|
||||||
|
if (handle == NULL)
|
||||||
|
return result;
|
||||||
|
|
||||||
|
wchar_t path[MAX_PATH];
|
||||||
|
DWORD pathLen = MAX_PATH;
|
||||||
|
if (QueryFullProcessImageName(handle, 0, path, &pathLen))
|
||||||
|
result = QString::fromUtf16(reinterpret_cast<const ushort*>(path));
|
||||||
|
CloseHandle(handle);
|
||||||
|
#endif
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
WindowsCrashDialogBlocker::WindowsCrashDialogBlocker()
|
WindowsCrashDialogBlocker::WindowsCrashDialogBlocker()
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
: silenceErrorMode(SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX | SEM_FAILCRITICALERRORS),
|
: silenceErrorMode(SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX | SEM_FAILCRITICALERRORS),
|
||||||
|
@@ -44,6 +44,9 @@ QTCREATOR_UTILS_EXPORT bool is64BitWindowsSystem();
|
|||||||
// Check for a 64bit binary.
|
// Check for a 64bit binary.
|
||||||
QTCREATOR_UTILS_EXPORT bool is64BitWindowsBinary(const QString &binary);
|
QTCREATOR_UTILS_EXPORT bool is64BitWindowsBinary(const QString &binary);
|
||||||
|
|
||||||
|
// Get the path to the executable for a given PID.
|
||||||
|
QTCREATOR_UTILS_EXPORT QString imageName(quint32 processId);
|
||||||
|
|
||||||
//
|
//
|
||||||
// RAII class to temporarily prevent windows crash messages from popping up using the
|
// RAII class to temporarily prevent windows crash messages from popping up using the
|
||||||
// application-global (!) error mode.
|
// application-global (!) error mode.
|
||||||
|
@@ -54,40 +54,6 @@ namespace Internal {
|
|||||||
|
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
|
|
||||||
// Resolve QueryFullProcessImageNameW out of kernel32.dll due
|
|
||||||
// to incomplete MinGW import libs and it not being present
|
|
||||||
// on Windows XP.
|
|
||||||
static BOOL queryFullProcessImageName(HANDLE h, DWORD flags, LPWSTR buffer, DWORD *size)
|
|
||||||
{
|
|
||||||
// Resolve required symbols from the kernel32.dll
|
|
||||||
typedef BOOL (WINAPI *QueryFullProcessImageNameWProtoType)
|
|
||||||
(HANDLE, DWORD, LPWSTR, PDWORD);
|
|
||||||
static QueryFullProcessImageNameWProtoType queryFullProcessImageNameW = 0;
|
|
||||||
if (!queryFullProcessImageNameW) {
|
|
||||||
QLibrary kernel32Lib(QLatin1String("kernel32.dll"), 0);
|
|
||||||
if (kernel32Lib.isLoaded() || kernel32Lib.load())
|
|
||||||
queryFullProcessImageNameW = (QueryFullProcessImageNameWProtoType)kernel32Lib.resolve("QueryFullProcessImageNameW");
|
|
||||||
}
|
|
||||||
if (!queryFullProcessImageNameW)
|
|
||||||
return FALSE;
|
|
||||||
// Read out process
|
|
||||||
return (*queryFullProcessImageNameW)(h, flags, buffer, size);
|
|
||||||
}
|
|
||||||
|
|
||||||
static QString imageName(DWORD processId)
|
|
||||||
{
|
|
||||||
QString rc;
|
|
||||||
HANDLE handle = OpenProcess(PROCESS_QUERY_INFORMATION , FALSE, processId);
|
|
||||||
if (handle == INVALID_HANDLE_VALUE)
|
|
||||||
return rc;
|
|
||||||
WCHAR buffer[MAX_PATH];
|
|
||||||
DWORD bufSize = MAX_PATH;
|
|
||||||
if (queryFullProcessImageName(handle, 0, buffer, &bufSize))
|
|
||||||
rc = QString::fromUtf16(reinterpret_cast<const ushort*>(buffer));
|
|
||||||
CloseHandle(handle);
|
|
||||||
return rc;
|
|
||||||
}
|
|
||||||
|
|
||||||
LocalProcessList::LocalProcessList(const IDevice::ConstPtr &device, QObject *parent)
|
LocalProcessList::LocalProcessList(const IDevice::ConstPtr &device, QObject *parent)
|
||||||
: DeviceProcessList(device, parent)
|
: DeviceProcessList(device, parent)
|
||||||
, m_myPid(GetCurrentProcessId())
|
, m_myPid(GetCurrentProcessId())
|
||||||
@@ -108,7 +74,7 @@ QList<DeviceProcessItem> LocalProcessList::getLocalProcesses()
|
|||||||
DeviceProcessItem p;
|
DeviceProcessItem p;
|
||||||
p.pid = pe.th32ProcessID;
|
p.pid = pe.th32ProcessID;
|
||||||
// Image has the absolute path, but can fail.
|
// Image has the absolute path, but can fail.
|
||||||
const QString image = imageName(pe.th32ProcessID);
|
const QString image = Utils::imageName(pe.th32ProcessID);
|
||||||
p.exe = p.cmdLine = image.isEmpty() ?
|
p.exe = p.cmdLine = image.isEmpty() ?
|
||||||
QString::fromWCharArray(pe.szExeFile) :
|
QString::fromWCharArray(pe.szExeFile) :
|
||||||
image;
|
image;
|
||||||
|
@@ -98,6 +98,8 @@
|
|||||||
#include <QStandardPaths>
|
#include <QStandardPaths>
|
||||||
#include <QWinEventNotifier>
|
#include <QWinEventNotifier>
|
||||||
|
|
||||||
|
#include <utils/winutils.h>
|
||||||
|
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -1503,15 +1505,7 @@ void HeobData::processFinished()
|
|||||||
debugger->setStartMode(AttachExternal);
|
debugger->setStartMode(AttachExternal);
|
||||||
debugger->setCloseMode(DetachAtClose);
|
debugger->setCloseMode(DetachAtClose);
|
||||||
debugger->setContinueAfterAttach(true);
|
debugger->setContinueAfterAttach(true);
|
||||||
|
debugger->setInferiorExecutable(Utils::imageName(m_data[1]));
|
||||||
HANDLE p = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, m_data[1]);
|
|
||||||
if (p != NULL) {
|
|
||||||
wchar_t path[MAX_PATH];
|
|
||||||
DWORD pathLen = MAX_PATH;
|
|
||||||
if (QueryFullProcessImageName(p, 0, path, &pathLen))
|
|
||||||
debugger->setInferiorExecutable(QString::fromWCharArray(path));
|
|
||||||
CloseHandle(p);
|
|
||||||
}
|
|
||||||
|
|
||||||
connect(m_runControl, &RunControl::started, this, &HeobData::debugStarted);
|
connect(m_runControl, &RunControl::started, this, &HeobData::debugStarted);
|
||||||
connect(m_runControl, &RunControl::stopped, this, &HeobData::debugStopped);
|
connect(m_runControl, &RunControl::stopped, this, &HeobData::debugStopped);
|
||||||
|
Reference in New Issue
Block a user