mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-12 14:29:36 +02:00
FpDebug: Linux fix finding "_dl_debug_state" (fol library debugging) when the main exe uses external debug info. Issue #41033
This commit is contained in:
parent
69e4861d80
commit
7c370e7757
@ -76,6 +76,7 @@ type
|
|||||||
constructor Create; virtual;
|
constructor Create; virtual;
|
||||||
constructor Create(AFileName: String; ADebugMap: TObject = nil;
|
constructor Create(AFileName: String; ADebugMap: TObject = nil;
|
||||||
ALoadedTargetImageAddr: TDBGPtr = 0);
|
ALoadedTargetImageAddr: TDBGPtr = 0);
|
||||||
|
constructor Create(AnImageReader: TDbgImageReader);
|
||||||
{$ifdef USE_WIN_FILE_MAPPING}
|
{$ifdef USE_WIN_FILE_MAPPING}
|
||||||
constructor Create(AFileHandle: THandle; ADebugMap: TObject = nil;
|
constructor Create(AFileHandle: THandle; ADebugMap: TObject = nil;
|
||||||
ALoadedTargetImageAddr: TDBGPtr = 0);
|
ALoadedTargetImageAddr: TDBGPtr = 0);
|
||||||
@ -283,6 +284,12 @@ begin
|
|||||||
FreeAndNil(FFileLoader);
|
FreeAndNil(FFileLoader);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
constructor TDbgImageLoader.Create(AnImageReader: TDbgImageReader);
|
||||||
|
begin
|
||||||
|
inherited Create;
|
||||||
|
FImgReader := AnImageReader;
|
||||||
|
end;
|
||||||
|
|
||||||
{$ifdef USE_WIN_FILE_MAPPING}
|
{$ifdef USE_WIN_FILE_MAPPING}
|
||||||
constructor TDbgImageLoader.Create(AFileHandle: THandle; ADebugMap: TObject;
|
constructor TDbgImageLoader.Create(AFileHandle: THandle; ADebugMap: TObject;
|
||||||
ALoadedTargetImageAddr: TDBGPtr);
|
ALoadedTargetImageAddr: TDBGPtr);
|
||||||
|
@ -36,7 +36,7 @@ uses
|
|||||||
LazUTF8, {$ifdef FORCE_LAZLOGGER_DUMMY} LazLoggerDummy {$else} LazLoggerBase {$endif},
|
LazUTF8, {$ifdef FORCE_LAZLOGGER_DUMMY} LazLoggerDummy {$else} LazLoggerBase {$endif},
|
||||||
DbgIntfBaseTypes,
|
DbgIntfBaseTypes,
|
||||||
// FpDebug
|
// FpDebug
|
||||||
FpImgReaderBase, fpDbgSymTable, FpImgReaderElfTypes, FpDbgCommon;
|
FpImgReaderBase, fpDbgSymTable, FpImgReaderElfTypes, FpDbgCommon, FpDbgLoader;
|
||||||
|
|
||||||
type
|
type
|
||||||
TElfSection = packed record
|
TElfSection = packed record
|
||||||
@ -74,17 +74,21 @@ type
|
|||||||
FFileLoader : TDbgFileLoader;
|
FFileLoader : TDbgFileLoader;
|
||||||
fOwnSource : Boolean;
|
fOwnSource : Boolean;
|
||||||
fElfFile : TElfFile;
|
fElfFile : TElfFile;
|
||||||
|
FImgLoaderDbgFile: TDbgImageLoader;
|
||||||
protected
|
protected
|
||||||
function GetSection(const AName: String): PDbgImageSection; override;
|
function GetSection(const AName: String): PDbgImageSection; override;
|
||||||
function GetSection(const ID: integer): PDbgImageSection; override;
|
function GetSection(const ID: integer): PDbgImageSection; override;
|
||||||
procedure LoadSections;
|
procedure LoadSections;
|
||||||
procedure ClearSections;
|
procedure ClearSections;
|
||||||
|
procedure ClearSectionsButInterP;
|
||||||
public
|
public
|
||||||
class function isValid(ASource: TDbgFileLoader): Boolean; override;
|
class function isValid(ASource: TDbgFileLoader): Boolean; override;
|
||||||
class function UserName: AnsiString; override;
|
class function UserName: AnsiString; override;
|
||||||
constructor Create(ASource: TDbgFileLoader; ADebugMap: TObject; ALoadedTargetImageAddr: TDbgPtr; OwnSource: Boolean); override;
|
constructor Create(ASource: TDbgFileLoader; ADebugMap: TObject; ALoadedTargetImageAddr: TDbgPtr; OwnSource: Boolean); override;
|
||||||
|
constructor CreateForDbgFile(ASource: TDbgFileLoader; ADebugMap: TObject; ALoadedTargetImageAddr: TDbgPtr; OwnSource: Boolean);
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
procedure ParseSymbolTable(AFpSymbolInfo: TfpSymbolList); override;
|
procedure ParseSymbolTable(AFpSymbolInfo: TfpSymbolList); override;
|
||||||
|
procedure AddSubFilesToLoaderList(ALoaderList: TObject; PrimaryLoader: TObject); override;
|
||||||
|
|
||||||
//function GetSectionInfo(const SectionName: AnsiString; var Size: int64): Boolean; override;
|
//function GetSectionInfo(const SectionName: AnsiString; var Size: int64): Boolean; override;
|
||||||
//function GetSectionData(const SectionName: AnsiString; Offset, Size: Int64; var Buf: array of byte): Int64; override;
|
//function GetSectionData(const SectionName: AnsiString; Offset, Size: Int64; var Buf: array of byte): Int64; override;
|
||||||
@ -381,6 +385,21 @@ begin
|
|||||||
FSections.Clear;
|
FSections.Clear;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TElfDbgSource.ClearSectionsButInterP;
|
||||||
|
var
|
||||||
|
i: Integer;
|
||||||
|
begin
|
||||||
|
i := 0;
|
||||||
|
while i < FSections.Count do begin
|
||||||
|
if FSections[i] <> '.interp' then begin
|
||||||
|
Freemem(FSections.Objects[i]);
|
||||||
|
FSections.Delete(i);
|
||||||
|
end
|
||||||
|
else
|
||||||
|
inc(i);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
class function TElfDbgSource.isValid(ASource: TDbgFileLoader): Boolean;
|
class function TElfDbgSource.isValid(ASource: TDbgFileLoader): Boolean;
|
||||||
var
|
var
|
||||||
buf : array [0..3+sizeof(Elf32_EHdr)] of byte;
|
buf : array [0..3+sizeof(Elf32_EHdr)] of byte;
|
||||||
@ -408,6 +427,7 @@ var
|
|||||||
DbgFileName, SourceFileName: String;
|
DbgFileName, SourceFileName: String;
|
||||||
crc: Cardinal;
|
crc: Cardinal;
|
||||||
NewFileLoader: TDbgFileLoader;
|
NewFileLoader: TDbgFileLoader;
|
||||||
|
ImgReadeDbgFile: TElfDbgSource;
|
||||||
begin
|
begin
|
||||||
inherited Create(ASource, ADebugMap, ALoadedTargetImageAddr, OwnSource);
|
inherited Create(ASource, ADebugMap, ALoadedTargetImageAddr, OwnSource);
|
||||||
|
|
||||||
@ -435,24 +455,41 @@ begin
|
|||||||
SourceFileName := ExtractFilePath(SourceFileName);
|
SourceFileName := ExtractFilePath(SourceFileName);
|
||||||
NewFileLoader := LoadGnuDebugLink(SourceFileName, DbgFileName, crc);
|
NewFileLoader := LoadGnuDebugLink(SourceFileName, DbgFileName, crc);
|
||||||
if NewFileLoader <> nil then begin
|
if NewFileLoader <> nil then begin
|
||||||
if fOwnSource then
|
ImgReadeDbgFile := TElfDbgSource.CreateForDbgFile(NewFileLoader, ADebugMap, ALoadedTargetImageAddr, True);
|
||||||
FFileLoader.Free;
|
FImgLoaderDbgFile := TDbgImageLoader.Create(ImgReadeDbgFile);
|
||||||
|
|
||||||
FFileLoader := NewFileLoader;
|
ClearSectionsButInterP;
|
||||||
fOwnSource := True;
|
|
||||||
|
|
||||||
fElfFile.Free;
|
|
||||||
fElfFile := TElfFile.Create;
|
|
||||||
fElfFile.LoadFromFile(FFileLoader);
|
|
||||||
|
|
||||||
ClearSections;
|
|
||||||
LoadSections;
|
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
FTargetInfo := fElfFile.FTargetInfo;
|
FTargetInfo := fElfFile.FTargetInfo;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
constructor TElfDbgSource.CreateForDbgFile(ASource: TDbgFileLoader; ADebugMap: TObject;
|
||||||
|
ALoadedTargetImageAddr: TDbgPtr; OwnSource: Boolean);
|
||||||
|
begin
|
||||||
|
inherited Create(ASource, ADebugMap, ALoadedTargetImageAddr, OwnSource);
|
||||||
|
|
||||||
|
FSections := TStringListUTF8Fast.Create;
|
||||||
|
FSections.Sorted := True;
|
||||||
|
//FSections.Duplicates := dupError;
|
||||||
|
FSections.CaseSensitive := False;
|
||||||
|
|
||||||
|
// Elf-binaries do not have an internal offset encoded into the binary (ImageBase)
|
||||||
|
// so their reloction-offset is just equal to the location at which the binary
|
||||||
|
// has been loaded into memory. (The LoadedTargetImageAddr)
|
||||||
|
SetRelocationOffset(ALoadedTargetImageAddr);
|
||||||
|
|
||||||
|
FFileLoader := ASource;
|
||||||
|
fOwnSource := OwnSource;
|
||||||
|
fElfFile := TElfFile.Create;
|
||||||
|
fElfFile.LoadFromFile(FFileLoader);
|
||||||
|
|
||||||
|
LoadSections;
|
||||||
|
|
||||||
|
FTargetInfo := fElfFile.FTargetInfo;
|
||||||
|
end;
|
||||||
|
|
||||||
destructor TElfDbgSource.Destroy;
|
destructor TElfDbgSource.Destroy;
|
||||||
begin
|
begin
|
||||||
if fOwnSource then FFileLoader.Free;
|
if fOwnSource then FFileLoader.Free;
|
||||||
@ -543,6 +580,13 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TElfDbgSource.AddSubFilesToLoaderList(ALoaderList: TObject; PrimaryLoader: TObject);
|
||||||
|
begin
|
||||||
|
inherited AddSubFilesToLoaderList(ALoaderList, PrimaryLoader);
|
||||||
|
if FImgLoaderDbgFile <> nil then
|
||||||
|
TDbgImageLoaderList(ALoaderList).Add(FImgLoaderDbgFile);
|
||||||
|
end;
|
||||||
|
|
||||||
initialization
|
initialization
|
||||||
DBG_WARNINGS := DebugLogger.FindOrRegisterLogGroup('DBG_WARNINGS' {$IFDEF DBG_WARNINGS} , True {$ENDIF} );
|
DBG_WARNINGS := DebugLogger.FindOrRegisterLogGroup('DBG_WARNINGS' {$IFDEF DBG_WARNINGS} , True {$ENDIF} );
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user