FpDebug: Fix for handling libraries that do not provide a real file-handle.

This commit is contained in:
Joost van der Sluis 2021-12-30 20:36:04 +01:00
parent a57cf215d3
commit 7750772722
2 changed files with 16 additions and 2 deletions

View File

@ -445,8 +445,22 @@ end;
{ tDbgWinLibrary }
procedure tDbgWinLibrary.InitializeLoaders;
var
FileInformation: TByHandleFileInformation;
begin
TDbgImageLoaderLibrary.Create(FInfo.hFile, nil, TDBGPtr(FInfo.lpBaseOfDll)).AddToLoaderList(LoaderList);
if GetFileInformationByHandle(FInfo.hFile, FileInformation) then
TDbgImageLoaderLibrary.Create(FInfo.hFile, nil, TDBGPtr(FInfo.lpBaseOfDll)).AddToLoaderList(LoaderList)
else if Name <> '' then
begin
// There are situations in which the provided handle is not a file-handle. In
// those cases, use the filename as fallback.
// (Happened in a Windows-docker (Azure, AKS) on the kernel32.dll. No idea
// why, though)
if FileExists(Name) then
TDbgImageLoaderLibrary.Create(Name, nil, TDBGPtr(FInfo.lpBaseOfDll)).AddToLoaderList(LoaderList)
else
DebugLn(DBG_WARNINGS, 'File [%s] related to library does not exist', [Name]);
end;
end;
constructor tDbgWinLibrary.Create(const AProcess: TDbgProcess;

View File

@ -323,7 +323,7 @@ begin
FMapHandle := CreateFileMapping(FFileHandle, nil, PAGE_READONLY{ or SEC_IMAGE}, 0, 0, nil);
if FMapHandle = 0
then begin
raise Exception.Create('Could not create module mapping');
raise Exception.CreateFmt('Could not create module mapping, error %d', [GetLastError]);
Exit;
end;