From e9f1ffb855995c7fca8dd87051d8272da409bb96 Mon Sep 17 00:00:00 2001 From: Joost van der Sluis Date: Wed, 8 Dec 2021 22:17:45 +0100 Subject: [PATCH] FpDebug: Load libraries on Linux, and skip incompatible binaries. Also on Windows, for consistency and stability --- components/fpdebug/fpdbglinuxclasses.pas | 25 +++++++++++++++++++++++- components/fpdebug/fpdbgwinclasses.pas | 8 +++++++- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/components/fpdebug/fpdbglinuxclasses.pas b/components/fpdebug/fpdbglinuxclasses.pas index 9bca24417b..ce60a23ad5 100644 --- a/components/fpdebug/fpdbglinuxclasses.pas +++ b/components/fpdebug/fpdbglinuxclasses.pas @@ -371,6 +371,8 @@ type { tDbgLinuxLibrary } tDbgLinuxLibrary = class(TDbgLibrary) + protected + procedure InitializeLoaders; override; public constructor Create(const AProcess: TDbgProcess; const AFileName: string; const AModuleHandle: THandle; const ABaseAddr: TDbgPtr); end; @@ -390,6 +392,21 @@ end; { tDbgLinuxLibrary } +procedure tDbgLinuxLibrary.InitializeLoaders; +var + Loader: TDbgImageLoader; +begin + Loader := TDbgImageLoader.Create(Name, nil, BaseAddr); + // The dynamic-loader (dl) on Linux also loads other stuff then ELF- + // formatted libraries. + // So it is reasonable likely that the loaded 'library' can not be handled + // by the detault readers from the loader. + if Loader.IsValid then + Loader.AddToLoaderList(LoaderList) + else + Loader.Free; +end; + constructor tDbgLinuxLibrary.Create(const AProcess: TDbgProcess; const AFileName: string; const AModuleHandle: THandle; const ABaseAddr: TDbgPtr); begin Inherited Create(AProcess, AFileName, AModuleHandle, ABaseAddr); @@ -867,8 +884,14 @@ begin end; procedure TDbgLinuxProcess.InitializeLoaders; +var + Loader: TDbgImageLoader; begin - TDbgImageLoader.Create(Name).AddToLoaderList(LoaderList); + Loader := TDbgImageLoader.Create(Name); + if Loader.IsValid then + Loader.AddToLoaderList(LoaderList) + else + Loader.Free; end; function TDbgLinuxProcess.CreateThread(AthreadIdentifier: THandle; out IsMainThread: boolean): TDbgThread; diff --git a/components/fpdebug/fpdbgwinclasses.pas b/components/fpdebug/fpdbgwinclasses.pas index 5ff442740a..0d61766cee 100644 --- a/components/fpdebug/fpdbgwinclasses.pas +++ b/components/fpdebug/fpdbgwinclasses.pas @@ -478,8 +478,14 @@ begin end; procedure TDbgWinProcess.InitializeLoaders; +var + Loader: TDbgImageLoader; begin - TDbgImageLoader.Create(FInfo.hFile).AddToLoaderList(LoaderList); + Loader := TDbgImageLoader.Create(FInfo.hFile); + if Loader.IsValid then + AddToLoaderList(LoaderList) + else + Loader.Free; end; function TDbgWinProcess.CreateWatchPointData: TFpWatchPointData;