summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOliver Wolff <[email protected]>2023-01-16 13:25:38 +0100
committerOliver Wolff <[email protected]>2023-03-31 05:16:31 +0100
commit3cf1a10e4fbb8f0409b6b4f432461810407b3123 (patch)
tree3b6577a72dd974e9fc1700765cda9ab7431f8f56
parent1ba89e35bd2f10524441c1449d476ba1952c3ace (diff)
windeployqt: Make determineDebugAndDependentLibs more readable
Change-Id: Ib06fb5f2bce9afe1bd799c3ff96abff5ddb063a9 Reviewed-by: Yuhang Zhao <[email protected]> Reviewed-by: Oliver Wolff <[email protected]>
-rw-r--r--src/tools/windeployqt/utils.cpp55
1 files changed, 35 insertions, 20 deletions
diff --git a/src/tools/windeployqt/utils.cpp b/src/tools/windeployqt/utils.cpp
index d54d0758942..ec68d6c3712 100644
--- a/src/tools/windeployqt/utils.cpp
+++ b/src/tools/windeployqt/utils.cpp
@@ -720,32 +720,47 @@ static inline MsvcDebugRuntimeResult checkMsvcDebugRuntime(const QStringList &de
}
template <class ImageNtHeader>
-inline void determineDebugAndDependentLibs(const ImageNtHeader *nth, const void *fileMemory,
+inline QStringList determineDependentLibs(const ImageNtHeader *nth, const void *fileMemory,
+ QString *errorMessage)
+{
+ return readImportSections(nth, fileMemory, errorMessage);
+}
+
+template <class ImageNtHeader>
+inline bool determineDebug(const ImageNtHeader *nth, const void *fileMemory,
bool isMinGW,
QStringList *dependentLibrariesIn,
- bool *isDebugIn, QString *errorMessage)
+ QString *errorMessage)
{
+ // Use logic that's used e.g. in objdump / pfd library
+ if (isMinGW)
+ return !(nth->FileHeader.Characteristics & IMAGE_FILE_DEBUG_STRIPPED);
+
+ const QStringList dependentLibraries = dependentLibrariesIn != nullptr ?
+ *dependentLibrariesIn :
+ determineDependentLibs(nth, fileMemory, errorMessage);
+
const bool hasDebugEntry = nth->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_DEBUG].Size;
- QStringList dependentLibraries;
- if (dependentLibrariesIn || (isDebugIn != nullptr && hasDebugEntry && !isMinGW))
- dependentLibraries = readImportSections(nth, fileMemory, errorMessage);
+ // When an MSVC debug entry is present, check whether the debug runtime
+ // is actually used to detect -release / -force-debug-info builds.
+ const MsvcDebugRuntimeResult msvcrt = checkMsvcDebugRuntime(dependentLibraries);
+ if (msvcrt == NoMsvcRuntime)
+ return hasDebugEntry;
+ else
+ return hasDebugEntry && msvcrt == MsvcDebugRuntime;
+}
+template <class ImageNtHeader>
+inline void determineDebugAndDependentLibs(const ImageNtHeader *nth, const void *fileMemory,
+ bool isMinGW,
+ QStringList *dependentLibrariesIn,
+ bool *isDebugIn, QString *errorMessage)
+{
if (dependentLibrariesIn)
- *dependentLibrariesIn = dependentLibraries;
- if (isDebugIn != nullptr) {
- if (isMinGW) {
- // Use logic that's used e.g. in objdump / pfd library
- *isDebugIn = !(nth->FileHeader.Characteristics & IMAGE_FILE_DEBUG_STRIPPED);
- } else {
- // When an MSVC debug entry is present, check whether the debug runtime
- // is actually used to detect -release / -force-debug-info builds.
- const MsvcDebugRuntimeResult msvcrt = checkMsvcDebugRuntime(dependentLibraries);
- if (msvcrt == NoMsvcRuntime)
- *isDebugIn = hasDebugEntry;
- else
- *isDebugIn = hasDebugEntry && msvcrt == MsvcDebugRuntime;
- }
- }
+ *dependentLibrariesIn = determineDependentLibs(nth, fileMemory, errorMessage);
+
+ if (isDebugIn)
+ *isDebugIn = determineDebug(nth, fileMemory, isMinGW, dependentLibrariesIn, errorMessage);
}
// Read a PE executable and determine dependent libraries, word size