Skip to content

Commit

Permalink
windeployqt: Make determineDebugAndDependentLibs more readable
Browse files Browse the repository at this point in the history
Change-Id: Ib06fb5f2bce9afe1bd799c3ff96abff5ddb063a9
Reviewed-by: Yuhang Zhao <[email protected]>
Reviewed-by: Oliver Wolff <[email protected]>
  • Loading branch information
owolff committed Mar 31, 2023
1 parent 1ba89e3 commit 3cf1a10
Showing 1 changed file with 35 additions and 20 deletions.
55 changes: 35 additions & 20 deletions src/tools/windeployqt/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3cf1a10

Please sign in to comment.