diff --git a/components/fpdebug/fpdmemorytools.pas b/components/fpdebug/fpdmemorytools.pas index 4474ecc15e..64d323a2b7 100644 --- a/components/fpdebug/fpdmemorytools.pas +++ b/components/fpdebug/fpdmemorytools.pas @@ -206,8 +206,10 @@ type FCacheAddress: TDBGPtr; FCacheSize: Cardinal; FMem: Array of byte; + FFailed: Boolean; public constructor Create(ACacheAddress: TDBGPtr; ACacheSize: Cardinal); + function ContainsMemory(AnAddress: TDbgPtr; ASize: Cardinal): Boolean; function ReadMemory(AnAddress: TDbgPtr; ASize: Cardinal; ADest: Pointer): Boolean; property CacheAddress: TDBGPtr read FCacheAddress; property CacheSize: Cardinal read FCacheSize; @@ -640,15 +642,28 @@ begin FCacheSize := ACacheSize; end; +function TFpDbgMemCacheSimple.ContainsMemory(AnAddress: TDbgPtr; ASize: Cardinal + ): Boolean; +begin + Result := (AnAddress >= FCacheAddress) or (AnAddress + ASize <= FCacheAddress + FCacheSize); +end; + function TFpDbgMemCacheSimple.ReadMemory(AnAddress: TDbgPtr; ASize: Cardinal; ADest: Pointer): Boolean; begin - if (AnAddress < FCacheAddress) or (AnAddress + ASize > FCacheAddress + FCacheSize) then - exit(False); + Result := False; + if (AnAddress < FCacheAddress) or (AnAddress + ASize > FCacheAddress + FCacheSize) or + FFailed + then + exit; if FMem = nil then begin SetLength(FMem, FCacheSize); - MemReader.ReadMemory(FCacheAddress, FCacheSize, @FMem[0]); + if not MemReader.ReadMemory(FCacheAddress, FCacheSize, @FMem[0]) then begin + FMem := nil; + FFailed := True; + exit; + end; end; Result := true; @@ -723,9 +738,10 @@ begin if Node = nil then exit(inherited ReadMemory(AnAddress, ASize, ADest)); - Result := TFpDbgMemCacheSimple(Node.Data).ReadMemory(AnAddress, ASize, ADest); - if Result then + if TFpDbgMemCacheSimple(Node.Data).ContainsMemory(AnAddress, ASize) then begin + Result := TFpDbgMemCacheSimple(Node.Data).ReadMemory(AnAddress, ASize, ADest); exit; + end; Result := inherited ReadMemory(AnAddress, ASize, ADest); end; diff --git a/components/lazdebuggers/lazdebuggerfplldb/fplldbdebugger.pas b/components/lazdebuggers/lazdebuggerfplldb/fplldbdebugger.pas index b62133e5a3..2ae69a0d9d 100644 --- a/components/lazdebuggers/lazdebuggerfplldb/fplldbdebugger.pas +++ b/components/lazdebuggers/lazdebuggerfplldb/fplldbdebugger.pas @@ -689,10 +689,19 @@ end; function TFpLldbDbgMemCacheManagerSimple.ReadMemory(AnAddress: TDbgPtr; ASize: Cardinal; ADest: Pointer): Boolean; +var + i: Integer; begin + i := -1; if not HasMemory(AnAddress, ASize) then - FList.Add(AddCache(AnAddress, ASize)); + i := FList.Add(AddCache(AnAddress, ASize)); Result := inherited ReadMemory(AnAddress, ASize, ADest); + + // Only auto add caches, if success. May get a request for a subset later (pchar) + if (not Result) and (i >= 0) then begin + RemoveCache(TFpDbgMemCacheBase(FList[i])); + FList.Delete(i); + end; end; procedure TFpLldbDbgMemCacheManagerSimple.Clear;