From f09614b9a832878eccab1de1a13ece88a167b923 Mon Sep 17 00:00:00 2001 From: martin Date: Wed, 5 Dec 2018 01:49:29 +0000 Subject: [PATCH] FpDebug: (Linux/Mac) Do not keep files open longer than needed. Systems may limit max files open. (Mac opens many files) git-svn-id: trunk@59729 - --- components/fpdebug/fpdbgdwarfdataclasses.pas | 1 + components/fpdebug/fpdbgloader.pp | 6 ++++++ components/fpdebug/fpimgreaderbase.pas | 16 ++++++++++++++++ 3 files changed, 23 insertions(+) diff --git a/components/fpdebug/fpdbgdwarfdataclasses.pas b/components/fpdebug/fpdbgdwarfdataclasses.pas index 7dd4c6d7dd..a0626d87f2 100644 --- a/components/fpdebug/fpdbgdwarfdataclasses.pas +++ b/components/fpdebug/fpdbgdwarfdataclasses.pas @@ -2948,6 +2948,7 @@ begin FFiles[i].Sections[Section].Size := p^.Size; FFiles[i].Sections[Section].VirtualAddress := p^.VirtualAddress; end; + ALoaderList[i].CloseFileLoader; end; end; diff --git a/components/fpdebug/fpdbgloader.pp b/components/fpdebug/fpdbgloader.pp index f4b919cb07..823edb11f3 100644 --- a/components/fpdebug/fpdbgloader.pp +++ b/components/fpdebug/fpdbgloader.pp @@ -77,6 +77,7 @@ type constructor Create(AFileHandle: THandle; ADebugMap: TObject = nil); {$endif} destructor Destroy; override; + procedure CloseFileLoader; procedure AddToLoaderList(ALoaderList: TDbgImageLoaderList); function IsValid: Boolean; property FileName: String read FFileName; // Empty if using USE_WIN_FILE_MAPPING @@ -220,6 +221,11 @@ begin inherited Destroy; end; +procedure TDbgImageLoader.CloseFileLoader; +begin + FFileLoader.Close; +end; + procedure TDbgImageLoader.AddToLoaderList(ALoaderList: TDbgImageLoaderList); begin ALoaderList.Add(Self); diff --git a/components/fpdebug/fpimgreaderbase.pas b/components/fpdebug/fpimgreaderbase.pas index 705c61d237..b63650f609 100644 --- a/components/fpdebug/fpimgreaderbase.pas +++ b/components/fpdebug/fpimgreaderbase.pas @@ -52,6 +52,7 @@ type FMapHandle: THandle; FModulePtr: Pointer; {$else} + FFileName: String; FStream: TStream; FList: TList; {$endif} @@ -61,6 +62,7 @@ type constructor Create(AFileHandle: THandle); {$endif} destructor Destroy; override; + procedure Close; function Read(AOffset, ASize: QWord; AMem: Pointer): QWord; function LoadMemory(AOffset, ASize: QWord; out AMem: Pointer): QWord; procedure UnloadMemory({%H-}AMem: Pointer); @@ -122,6 +124,7 @@ begin try if cls.isValid(ASource) then begin Result := cls.Create(ASource, ADebugMap, OwnSource); + ASource.Close; Exit; end else @@ -132,6 +135,7 @@ begin end; end; end; + ASource.Close; Result := nil; end; @@ -162,6 +166,7 @@ begin if (FileExists(s)) then AFileName := s end; {$ENDIF} + FFileName := AFileName; FStream := TFileStreamUTF8.Create(AFileName, fmOpenRead or fmShareDenyNone); inherited Create; {$endif} @@ -212,6 +217,13 @@ begin {$endif} end; +procedure TDbgFileLoader.Close; +begin + {$ifNdef USE_WIN_FILE_MAPPING} + FreeAndNil(FStream); + {$endif} +end; + function TDbgFileLoader.Read(AOffset, ASize: QWord; AMem: Pointer): QWord; begin {$ifdef USE_WIN_FILE_MAPPING} @@ -221,6 +233,8 @@ begin Result := 0; if AMem = nil then exit; + if FStream = nil then + FStream := TFileStreamUTF8.Create(FFileName, fmOpenRead or fmShareDenyNone); FStream.Position := AOffset; Result := FStream.Read(AMem^, ASize); {$endif} @@ -236,6 +250,8 @@ begin AMem := AllocMem(ASize); if AMem = nil then exit; + if FStream = nil then + FStream := TFileStreamUTF8.Create(FFileName, fmOpenRead or fmShareDenyNone); FList.Add(AMem); FStream.Position := AOffset; Result := FStream.Read(AMem^, ASize);