mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-13 07:49:25 +02:00
FpDebug: Replaced some Pascalish code to perform pointer calculations without range-overflows with code with range-checking disabled
This commit is contained in:
parent
a05f75154d
commit
c8feb2d0e8
@ -14,12 +14,6 @@ type
|
||||
TByteOrder = (boNone, boLSB, boMSB);
|
||||
TOperatingSystem = (osNone, osBSD, osDarwin, osEmbedded, osLinux, osUnix, osMac, osWindows);
|
||||
|
||||
TDBGPtrSign = (sPositive, sNegative);
|
||||
TDBGPtrOffset = record
|
||||
Offset: Int64;
|
||||
Sign: TDBGPtrSign;
|
||||
end;
|
||||
|
||||
TTargetDescriptor = record
|
||||
machineType: TMachineType;
|
||||
bitness: TBitness;
|
||||
@ -38,8 +32,6 @@ procedure SetCurrentFpDebugThreadIdForAssert(AnId: TThreadID);
|
||||
property CurrentFpDebugThreadIdForAssert: TThreadID write SetCurrentFpDebugThreadIdForAssert;
|
||||
{$ENDIF}
|
||||
|
||||
Operator + (Addr : QWord; Offset : TDBGPtrOffset) Res : QWord;
|
||||
|
||||
implementation
|
||||
|
||||
function hostDescriptor: TTargetDescriptor;
|
||||
@ -66,14 +58,6 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
operator+(Addr: QWord; Offset: TDBGPtrOffset) Res: QWord;
|
||||
begin
|
||||
if Offset.Sign=sPositive then
|
||||
Res := Addr + Offset.Offset
|
||||
else
|
||||
Res := Addr - Offset.Offset;
|
||||
end;
|
||||
|
||||
{$IFDEF FPDEBUG_THREAD_CHECK}
|
||||
var
|
||||
FCurrentFpDebugThreadIdForAssert: TThreadID;
|
||||
|
@ -758,7 +758,7 @@ type
|
||||
FFiles: array of TDwarfDebugFile;
|
||||
private
|
||||
FImageBase: QWord;
|
||||
FRelocationOffset: TDBGPtrOffset;
|
||||
FRelocationOffset: QWord;
|
||||
function GetCompilationUnit(AIndex: Integer): TDwarfCompilationUnit; inline;
|
||||
protected
|
||||
function GetCompilationUnitClass: TDwarfCompilationUnitClass; virtual;
|
||||
@ -781,7 +781,7 @@ type
|
||||
property CompilationUnits[AIndex: Integer]: TDwarfCompilationUnit read GetCompilationUnit;
|
||||
|
||||
property ImageBase: QWord read FImageBase;
|
||||
property RelocationOffset: TDBGPtrOffset read FRelocationOffset;
|
||||
property RelocationOffset: QWord read FRelocationOffset;
|
||||
property WorkQueue: TFpGlobalThreadWorkerQueue read FWorkQueue;
|
||||
end;
|
||||
|
||||
@ -4957,7 +4957,10 @@ end;
|
||||
|
||||
function TDwarfCompilationUnit.CalculateRelocatedAddress(AValue: QWord): QWord;
|
||||
begin
|
||||
{$push}
|
||||
{$Q-}{$R-}
|
||||
Result := AValue + FOwner.RelocationOffset;
|
||||
{$pop}
|
||||
end;
|
||||
|
||||
function TDwarfCompilationUnit.GetProcStartEnd(const AAddress: TDBGPtr; out
|
||||
|
@ -62,7 +62,7 @@ type
|
||||
FImgReader: TDbgImageReader;
|
||||
function GetAddressMapList: TDbgAddressMapList;
|
||||
function GetImageBase: QWord;
|
||||
function GetRelocationOffset: TDBGPtrOffset;
|
||||
function GetRelocationOffset: QWord;
|
||||
function GetReaderErrors: String;
|
||||
function GetSubFiles: TStrings;
|
||||
function GetTargetInfo: TTargetDescriptor;
|
||||
@ -88,7 +88,7 @@ type
|
||||
|
||||
property FileName: String read FFileName; // Empty if using USE_WIN_FILE_MAPPING
|
||||
property ImageBase: QWord read GetImageBase;
|
||||
property RelocationOffset: TDBGPtrOffset read GetRelocationOffset;
|
||||
property RelocationOffset: QWord read GetRelocationOffset;
|
||||
property TargetInfo: TTargetDescriptor read GetTargetInfo;
|
||||
|
||||
property UUID: TGuid read GetUUID;
|
||||
@ -114,7 +114,7 @@ type
|
||||
|
||||
TDbgImageLoaderList = class(TFPObjectList)
|
||||
private
|
||||
function GetRelocationOffset: TDBGPtrOffset;
|
||||
function GetRelocationOffset: QWord;
|
||||
function GetImageBase: QWord;
|
||||
function GetTargetInfo: TTargetDescriptor;
|
||||
function GetItem(Index: Integer): TDbgImageLoader;
|
||||
@ -124,7 +124,7 @@ type
|
||||
|
||||
property Items[Index: Integer]: TDbgImageLoader read GetItem write SetItem; default;
|
||||
property ImageBase: QWord read GetImageBase;
|
||||
property RelocationOffset: TDBGPtrOffset read GetRelocationOffset;
|
||||
property RelocationOffset: QWord read GetRelocationOffset;
|
||||
property TargetInfo: TTargetDescriptor read GetTargetInfo;
|
||||
end;
|
||||
|
||||
@ -132,15 +132,12 @@ implementation
|
||||
|
||||
{ TDbgImageLoaderList }
|
||||
|
||||
function TDbgImageLoaderList.GetRelocationOffset: TDBGPtrOffset;
|
||||
function TDbgImageLoaderList.GetRelocationOffset: QWord;
|
||||
begin
|
||||
if Count>0 then
|
||||
result := Items[0].RelocationOffset
|
||||
else
|
||||
begin
|
||||
Result.Offset := 0;
|
||||
Result.Sign := sPositive;
|
||||
end;
|
||||
Result := 0;
|
||||
end;
|
||||
|
||||
function TDbgImageLoaderList.GetImageBase: QWord;
|
||||
@ -214,15 +211,12 @@ begin
|
||||
Result := 0;
|
||||
end;
|
||||
|
||||
function TDbgImageLoader.GetRelocationOffset: TDBGPtrOffset;
|
||||
function TDbgImageLoader.GetRelocationOffset: QWord;
|
||||
begin
|
||||
if Assigned(FImgReader) then
|
||||
Result := FImgReader.RelocationOffset
|
||||
else
|
||||
begin
|
||||
Result.Offset := 0;
|
||||
Result.Sign := sPositive;
|
||||
end;
|
||||
Result := 0;
|
||||
end;
|
||||
|
||||
function TDbgImageLoader.GetReaderErrors: String;
|
||||
|
@ -97,7 +97,7 @@ type
|
||||
private
|
||||
FImageBase: QWord;
|
||||
FImageSize: QWord;
|
||||
FRelocationOffset: TDBGPtrOffset;
|
||||
FRelocationOffset: QWord;
|
||||
FLoadedTargetImageAddr: TDBGPtr;
|
||||
FReaderErrors: String;
|
||||
FUUID: TGuid;
|
||||
@ -110,7 +110,7 @@ type
|
||||
procedure SetUUID(AGuid: TGuid);
|
||||
procedure SetImageBase(ABase: QWord);
|
||||
procedure SetImageSize(ASize: QWord);
|
||||
procedure SetRelocationOffset(AnOffset: TDBGPtr; Sign: TDBGPtrSign);
|
||||
procedure SetRelocationOffset(AnOffset: QWord);
|
||||
procedure AddReaderError(AnError: String);
|
||||
function ReadGnuDebugLinkSection(out AFileName: String; out ACrc: Cardinal): Boolean;
|
||||
function LoadGnuDebugLink(ASearchPath, AFileName: String; ACrc: Cardinal): TDbgFileLoader;
|
||||
@ -144,7 +144,7 @@ type
|
||||
// On linux it is equal to the LoadedTargetImageAddr.
|
||||
// On Windows it is 0, except for libraries which are re-located. In that
|
||||
// case the offset is LoadedTargetImageAddr-ImageBase.
|
||||
property RelocationOffset: TDBGPtrOffset read FRelocationOffset;
|
||||
property RelocationOffset: QWord read FRelocationOffset;
|
||||
|
||||
property TargetInfo: TTargetDescriptor read FTargetInfo;
|
||||
|
||||
@ -433,10 +433,9 @@ begin
|
||||
FImageSize := ASize;
|
||||
end;
|
||||
|
||||
procedure TDbgImageReader.SetRelocationOffset(AnOffset: TDBGPtr; Sign: TDBGPtrSign);
|
||||
procedure TDbgImageReader.SetRelocationOffset(AnOffset: QWord);
|
||||
begin
|
||||
FRelocationOffset.Offset := AnOffset;
|
||||
FRelocationOffset.Sign := Sign;
|
||||
FRelocationOffset := AnOffset;
|
||||
end;
|
||||
|
||||
procedure TDbgImageReader.AddReaderError(AnError: String);
|
||||
|
@ -414,7 +414,7 @@ begin
|
||||
// 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, sPositive);
|
||||
SetRelocationOffset(ALoadedTargetImageAddr);
|
||||
|
||||
FFileLoader := ASource;
|
||||
fOwnSource := OwnSource;
|
||||
@ -495,6 +495,7 @@ begin
|
||||
continue; // not loaded, symbol not in memory
|
||||
|
||||
SymbolName:=pchar(SymbolStr+SymbolArr64^[i].st_name);
|
||||
{$Q-}
|
||||
AfpSymbolInfo.Add(SymbolName, TDbgPtr(SymbolArr64^[i].st_value+RelocationOffset),
|
||||
Sect^.Address + Sect^.Size + RelocationOffset);
|
||||
end;
|
||||
@ -519,8 +520,11 @@ begin
|
||||
continue; // not loaded, symbol not in memory
|
||||
|
||||
SymbolName:=pchar(SymbolStr+SymbolArr32^[i].st_name);
|
||||
{$push}
|
||||
{$Q-}{$R-}
|
||||
AfpSymbolInfo.Add(SymbolName, TDBGPtr(SymbolArr32^[i].st_value+RelocationOffset),
|
||||
Sect^.Address + Sect^.Size+RelocationOffset);
|
||||
{$pop}
|
||||
end;
|
||||
end
|
||||
end;
|
||||
|
@ -463,10 +463,9 @@ begin
|
||||
// relocated) all addresses need a correction.
|
||||
// The difference between the LoadedTargetImageAddr and ImageBase is the offset
|
||||
// that has to be used to calculate the actual addresses in memory.
|
||||
if LoadedTargetImageAddr >= ImageBase then
|
||||
SetRelocationOffset(LoadedTargetImageAddr-ImageBase, sPositive)
|
||||
else
|
||||
SetRelocationOffset(ImageBase-LoadedTargetImageAddr, sNegative);
|
||||
{$PUSH}{$Q-}{$R-}
|
||||
SetRelocationOffset(LoadedTargetImageAddr-ImageBase);
|
||||
{$POP}
|
||||
FCodeBase := NtHeaders.W32.OptionalHeader.BaseOfCode;
|
||||
SectionMax := FFileLoader.LoadMemory(
|
||||
DosHeader.e_lfanew +
|
||||
|
Loading…
Reference in New Issue
Block a user