windeployqt: Make determineDebugAndDependentLibs more readable

Change-Id: Ib06fb5f2bce9afe1bd799c3ff96abff5ddb063a9
Reviewed-by: Yuhang Zhao <yuhangzhao@deepin.org>
Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
This commit is contained in:
Oliver Wolff 2023-01-16 13:25:38 +01:00
parent 1ba89e35bd
commit 3cf1a10e4f

View File

@ -719,33 +719,48 @@ static inline MsvcDebugRuntimeResult checkMsvcDebugRuntime(const QStringList &de
return NoMsvcRuntime;
}
template <class ImageNtHeader>
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,
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;
// 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)
{
const bool hasDebugEntry = nth->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_DEBUG].Size;
QStringList dependentLibraries;
if (dependentLibrariesIn || (isDebugIn != nullptr && hasDebugEntry && !isMinGW))
dependentLibraries = readImportSections(nth, fileMemory, 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