aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOliver Wolff <oliver.wolff@qt.io>2018-02-05 12:15:57 +0100
committerOliver Wolff <oliver.wolff@qt.io>2018-02-06 07:30:18 +0000
commit74d718c001a81dcd32a11aebc8806618aa235267 (patch)
tree2408d5cab7b216513836696e7a32715eebbf982d
parent88a889d45a05dcd78e5aa1bec9f2e4aca20252bf (diff)
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>
-rw-r--r--src/libs/utils/winutils.cpp21
-rw-r--r--src/libs/utils/winutils.h3
-rw-r--r--src/plugins/projectexplorer/devicesupport/localprocesslist.cpp36
-rw-r--r--src/plugins/valgrind/memchecktool.cpp12
4 files changed, 26 insertions, 46 deletions
diff --git a/src/libs/utils/winutils.cpp b/src/libs/utils/winutils.cpp
index d41cb693cd..140d94977d 100644
--- a/src/libs/utils/winutils.cpp
+++ b/src/libs/utils/winutils.cpp
@@ -26,10 +26,10 @@
#include "winutils.h"
#include "qtcassert.h"
-// Enable WinAPI Windows XP and later
+// Enable WinAPI Windows Vista and later
#ifdef Q_OS_WIN
#undef _WIN32_WINNT
-#define _WIN32_WINNT 0x0501
+#define _WIN32_WINNT 0x0600 // Needed for QueryFullProcessImageName
#include <windows.h>
#endif
@@ -168,6 +168,23 @@ QTCREATOR_UTILS_EXPORT bool is64BitWindowsBinary(const QString &binaryIn)
#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()
#ifdef Q_OS_WIN
: silenceErrorMode(SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX | SEM_FAILCRITICALERRORS),
diff --git a/src/libs/utils/winutils.h b/src/libs/utils/winutils.h
index 6bb75f97d6..314cce673d 100644
--- a/src/libs/utils/winutils.h
+++ b/src/libs/utils/winutils.h
@@ -44,6 +44,9 @@ QTCREATOR_UTILS_EXPORT bool is64BitWindowsSystem();
// Check for a 64bit 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
// application-global (!) error mode.
diff --git a/src/plugins/projectexplorer/devicesupport/localprocesslist.cpp b/src/plugins/projectexplorer/devicesupport/localprocesslist.cpp
index 035a045729..b0d95c6474 100644
--- a/src/plugins/projectexplorer/devicesupport/localprocesslist.cpp
+++ b/src/plugins/projectexplorer/devicesupport/localprocesslist.cpp
@@ -54,40 +54,6 @@ namespace Internal {
#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)
: DeviceProcessList(device, parent)
, m_myPid(GetCurrentProcessId())
@@ -108,7 +74,7 @@ QList<DeviceProcessItem> LocalProcessList::getLocalProcesses()
DeviceProcessItem p;
p.pid = pe.th32ProcessID;
// 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() ?
QString::fromWCharArray(pe.szExeFile) :
image;
diff --git a/src/plugins/valgrind/memchecktool.cpp b/src/plugins/valgrind/memchecktool.cpp
index d007f3580f..db06b93f91 100644
--- a/src/plugins/valgrind/memchecktool.cpp
+++ b/src/plugins/valgrind/memchecktool.cpp
@@ -98,6 +98,8 @@
#include <QStandardPaths>
#include <QWinEventNotifier>
+#include <utils/winutils.h>
+
#include <windows.h>
#endif
@@ -1503,15 +1505,7 @@ void HeobData::processFinished()
debugger->setStartMode(AttachExternal);
debugger->setCloseMode(DetachAtClose);
debugger->setContinueAfterAttach(true);
-
- 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);
- }
+ debugger->setInferiorExecutable(Utils::imageName(m_data[1]));
connect(m_runControl, &RunControl::started, this, &HeobData::debugStarted);
connect(m_runControl, &RunControl::stopped, this, &HeobData::debugStopped);