mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-18 07:19:22 +02:00
FpDebug: On Windows the RelocationOffset can only be calculated after the file-header has been read. So the whole logic to obtain the RelocationOffset out of the LoadedTargetImageAddr and ImageBase is refactored
This commit is contained in:
parent
e71c784ab0
commit
8205a04199
@ -466,7 +466,7 @@ type
|
|||||||
procedure SetFileName(const AValue: String);
|
procedure SetFileName(const AValue: String);
|
||||||
procedure SetMode(AMode: TFPDMode); experimental; // for testcase
|
procedure SetMode(AMode: TFPDMode); experimental; // for testcase
|
||||||
public
|
public
|
||||||
constructor Create(const AProcess: TDbgProcess; ARelocationOffset: TDBGPtr = 0); virtual;
|
constructor Create(const AProcess: TDbgProcess); virtual;
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
|
|
||||||
// Returns the addresses at the given source-filename and line-number.
|
// Returns the addresses at the given source-filename and line-number.
|
||||||
@ -498,15 +498,10 @@ type
|
|||||||
TDbgLibrary = class(TDbgInstance)
|
TDbgLibrary = class(TDbgInstance)
|
||||||
private
|
private
|
||||||
FModuleHandle: THandle;
|
FModuleHandle: THandle;
|
||||||
FRelocationOffset: TDBGPtr;
|
|
||||||
public
|
public
|
||||||
constructor Create(const AProcess: TDbgProcess; const ADefaultName: String; const AModuleHandle: THandle; const ARelocationAddress: TDbgPtr);
|
constructor Create(const AProcess: TDbgProcess; const ADefaultName: String; const AModuleHandle: THandle);
|
||||||
property Name: String read FFileName;
|
property Name: String read FFileName;
|
||||||
property ModuleHandle: THandle read FModuleHandle;
|
property ModuleHandle: THandle read FModuleHandle;
|
||||||
// The relocationoffset is the offset at which the binary (most likely
|
|
||||||
// library) is loaded into memory. It is not part of the binary itself, unlike
|
|
||||||
// the BaseAddr.
|
|
||||||
property RelocationOffset: TDBGPtr read FRelocationOffset;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
TStartInstanceFlag = (siRediretOutput, siForceNewConsole);
|
TStartInstanceFlag = (siRediretOutput, siForceNewConsole);
|
||||||
@ -1637,11 +1632,11 @@ begin
|
|||||||
Result := SymbolTableInfo.FindProcSymbol(AName);
|
Result := SymbolTableInfo.FindProcSymbol(AName);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
constructor TDbgInstance.Create(const AProcess: TDbgProcess; ARelocationOffset: TDBGPtr);
|
constructor TDbgInstance.Create(const AProcess: TDbgProcess);
|
||||||
begin
|
begin
|
||||||
FProcess := AProcess;
|
FProcess := AProcess;
|
||||||
FMemManager := AProcess.MemManager;
|
FMemManager := AProcess.MemManager;
|
||||||
FLoaderList := TDbgImageLoaderList.Create(True, ARelocationOffset);
|
FLoaderList := TDbgImageLoaderList.Create(True);
|
||||||
|
|
||||||
inherited Create;
|
inherited Create;
|
||||||
end;
|
end;
|
||||||
@ -1725,12 +1720,11 @@ end;
|
|||||||
|
|
||||||
{ TDbgLibrary }
|
{ TDbgLibrary }
|
||||||
|
|
||||||
constructor TDbgLibrary.Create(const AProcess: TDbgProcess; const ADefaultName: String; const AModuleHandle: THandle; const ARelocationAddress: TDbgPtr);
|
constructor TDbgLibrary.Create(const AProcess: TDbgProcess; const ADefaultName: String; const AModuleHandle: THandle);
|
||||||
|
|
||||||
begin
|
begin
|
||||||
inherited Create(AProcess, ARelocationAddress);
|
inherited Create(AProcess);
|
||||||
FModuleHandle:=AModuleHandle;
|
FModuleHandle:=AModuleHandle;
|
||||||
FRelocationOffset:=ARelocationAddress;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TDbgProcess }
|
{ TDbgProcess }
|
||||||
|
@ -14,6 +14,12 @@ type
|
|||||||
TByteOrder = (boNone, boLSB, boMSB);
|
TByteOrder = (boNone, boLSB, boMSB);
|
||||||
TOperatingSystem = (osNone, osBSD, osDarwin, osEmbedded, osLinux, osUnix, osMac, osWindows);
|
TOperatingSystem = (osNone, osBSD, osDarwin, osEmbedded, osLinux, osUnix, osMac, osWindows);
|
||||||
|
|
||||||
|
TDBGPtrSign = (sPositive, sNegative);
|
||||||
|
TDBGPtrOffset = record
|
||||||
|
Offset: Int64;
|
||||||
|
Sign: TDBGPtrSign;
|
||||||
|
end;
|
||||||
|
|
||||||
TTargetDescriptor = record
|
TTargetDescriptor = record
|
||||||
machineType: TMachineType;
|
machineType: TMachineType;
|
||||||
bitness: TBitness;
|
bitness: TBitness;
|
||||||
@ -32,6 +38,8 @@ procedure SetCurrentFpDebugThreadIdForAssert(AnId: TThreadID);
|
|||||||
property CurrentFpDebugThreadIdForAssert: TThreadID write SetCurrentFpDebugThreadIdForAssert;
|
property CurrentFpDebugThreadIdForAssert: TThreadID write SetCurrentFpDebugThreadIdForAssert;
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
|
|
||||||
|
Operator + (Addr : QWord; Offset : TDBGPtrOffset) Res : QWord;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
function hostDescriptor: TTargetDescriptor;
|
function hostDescriptor: TTargetDescriptor;
|
||||||
@ -58,6 +66,14 @@ begin
|
|||||||
end;
|
end;
|
||||||
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}
|
{$IFDEF FPDEBUG_THREAD_CHECK}
|
||||||
var
|
var
|
||||||
FCurrentFpDebugThreadIdForAssert: TThreadID;
|
FCurrentFpDebugThreadIdForAssert: TThreadID;
|
||||||
|
@ -45,7 +45,7 @@ uses
|
|||||||
Classes, Types, SysUtils, contnrs, Math, Maps, LazClasses, LazFileUtils,
|
Classes, Types, SysUtils, contnrs, Math, Maps, LazClasses, LazFileUtils,
|
||||||
{$ifdef FORCE_LAZLOGGER_DUMMY} LazLoggerDummy {$else} LazLoggerBase {$endif}, LazUTF8, lazCollections,
|
{$ifdef FORCE_LAZLOGGER_DUMMY} LazLoggerDummy {$else} LazLoggerBase {$endif}, LazUTF8, lazCollections,
|
||||||
// FpDebug
|
// FpDebug
|
||||||
FpDbgUtil, FpDbgInfo, FpDbgDwarfConst,
|
FpDbgUtil, FpDbgInfo, FpDbgDwarfConst, FpDbgCommon,
|
||||||
FpDbgLoader, FpImgReaderBase, FpdMemoryTools, FpErrorMessages, DbgIntfBaseTypes;
|
FpDbgLoader, FpImgReaderBase, FpdMemoryTools, FpErrorMessages, DbgIntfBaseTypes;
|
||||||
|
|
||||||
type
|
type
|
||||||
@ -757,7 +757,7 @@ type
|
|||||||
FFiles: array of TDwarfDebugFile;
|
FFiles: array of TDwarfDebugFile;
|
||||||
private
|
private
|
||||||
FImageBase: QWord;
|
FImageBase: QWord;
|
||||||
FRelocationOffset: TDBGPtr;
|
FRelocationOffset: TDBGPtrOffset;
|
||||||
function GetCompilationUnit(AIndex: Integer): TDwarfCompilationUnit; inline;
|
function GetCompilationUnit(AIndex: Integer): TDwarfCompilationUnit; inline;
|
||||||
protected
|
protected
|
||||||
function GetCompilationUnitClass: TDwarfCompilationUnitClass; virtual;
|
function GetCompilationUnitClass: TDwarfCompilationUnitClass; virtual;
|
||||||
@ -780,7 +780,7 @@ type
|
|||||||
property CompilationUnits[AIndex: Integer]: TDwarfCompilationUnit read GetCompilationUnit;
|
property CompilationUnits[AIndex: Integer]: TDwarfCompilationUnit read GetCompilationUnit;
|
||||||
|
|
||||||
property ImageBase: QWord read FImageBase;
|
property ImageBase: QWord read FImageBase;
|
||||||
property RelocationOffset: TDBGPtr read FRelocationOffset;
|
property RelocationOffset: TDBGPtrOffset read FRelocationOffset;
|
||||||
property WorkQueue: TFpGlobalThreadWorkerQueue read FWorkQueue;
|
property WorkQueue: TFpGlobalThreadWorkerQueue read FWorkQueue;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
@ -298,6 +298,8 @@ type
|
|||||||
function GetStackPointerRegisterValue: TDbgPtr; override;
|
function GetStackPointerRegisterValue: TDbgPtr; override;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
tDbgLinuxLibrary = class;
|
||||||
|
|
||||||
{ TDbgLinuxProcess }
|
{ TDbgLinuxProcess }
|
||||||
|
|
||||||
TDbgLinuxProcess = class(TDbgProcess)
|
TDbgLinuxProcess = class(TDbgProcess)
|
||||||
@ -337,7 +339,7 @@ type
|
|||||||
function SynchronizeProcMapsWithLibraryList: TFPDEvent;
|
function SynchronizeProcMapsWithLibraryList: TFPDEvent;
|
||||||
// Scan /proc/[pid]/maps and return the results
|
// Scan /proc/[pid]/maps and return the results
|
||||||
function ObtainProcMaps: TDbgLinuxMemoryMappingList;
|
function ObtainProcMaps: TDbgLinuxMemoryMappingList;
|
||||||
procedure AddLib(const ALibrary: TDbgLibrary);
|
procedure AddLib(const ALibrary: tDbgLinuxLibrary);
|
||||||
public
|
public
|
||||||
class function isSupported(ATargetInfo: TTargetDescriptor): boolean; override;
|
class function isSupported(ATargetInfo: TTargetDescriptor): boolean; override;
|
||||||
constructor Create(const AFileName: string; AnOsClasses: TOSDbgClasses; AMemManager: TFpDbgMemManager; AProcessConfig: TDbgProcessConfig = nil); override;
|
constructor Create(const AFileName: string; AnOsClasses: TOSDbgClasses; AMemManager: TFpDbgMemManager; AProcessConfig: TDbgProcessConfig = nil); override;
|
||||||
@ -372,9 +374,10 @@ type
|
|||||||
|
|
||||||
tDbgLinuxLibrary = class(TDbgLibrary)
|
tDbgLinuxLibrary = class(TDbgLibrary)
|
||||||
protected
|
protected
|
||||||
|
FLoadedTargetImageAddr: TDbgPtr;
|
||||||
procedure InitializeLoaders; override;
|
procedure InitializeLoaders; override;
|
||||||
public
|
public
|
||||||
constructor Create(const AProcess: TDbgProcess; const AFileName: string; const AModuleHandle: THandle; const ARelocationAddress: TDbgPtr);
|
constructor Create(const AProcess: TDbgProcess; const AFileName: string; const AModuleHandle: THandle; const ALoadedTargetImageAddr: TDbgPtr);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
@ -396,7 +399,7 @@ procedure tDbgLinuxLibrary.InitializeLoaders;
|
|||||||
var
|
var
|
||||||
Loader: TDbgImageLoader;
|
Loader: TDbgImageLoader;
|
||||||
begin
|
begin
|
||||||
Loader := TDbgImageLoader.Create(Name, nil, LoaderList.RelocationOffset);
|
Loader := TDbgImageLoader.Create(Name, nil, FLoadedTargetImageAddr);
|
||||||
// The dynamic-loader (dl) on Linux also loads other stuff then ELF-
|
// The dynamic-loader (dl) on Linux also loads other stuff then ELF-
|
||||||
// formatted libraries.
|
// formatted libraries.
|
||||||
// So it is reasonable likely that the loaded 'library' can not be handled
|
// So it is reasonable likely that the loaded 'library' can not be handled
|
||||||
@ -407,9 +410,10 @@ begin
|
|||||||
Loader.Free;
|
Loader.Free;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
constructor tDbgLinuxLibrary.Create(const AProcess: TDbgProcess; const AFileName: string; const AModuleHandle: THandle; const ARelocationAddress: TDbgPtr);
|
constructor tDbgLinuxLibrary.Create(const AProcess: TDbgProcess; const AFileName: string; const AModuleHandle: THandle; const ALoadedTargetImageAddr: TDbgPtr);
|
||||||
begin
|
begin
|
||||||
Inherited Create(AProcess, AFileName, AModuleHandle, ARelocationAddress);
|
FLoadedTargetImageAddr := ALoadedTargetImageAddr;
|
||||||
|
Inherited Create(AProcess, AFileName, AModuleHandle);
|
||||||
SetFileName(AFileName);
|
SetFileName(AFileName);
|
||||||
|
|
||||||
LoadInfo;
|
LoadInfo;
|
||||||
@ -1071,11 +1075,11 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TDbgLinuxProcess.AddLib(const ALibrary: TDbgLibrary);
|
procedure TDbgLinuxProcess.AddLib(const ALibrary: tDbgLinuxLibrary);
|
||||||
var
|
var
|
||||||
ID: TDbgPtr;
|
ID: TDbgPtr;
|
||||||
begin
|
begin
|
||||||
ID := ALibrary.RelocationOffset;
|
ID := ALibrary.FLoadedTargetImageAddr;
|
||||||
FLibMap.Add(ID, ALibrary);
|
FLibMap.Add(ID, ALibrary);
|
||||||
if (ALibrary.DbgInfo.HasInfo) or (ALibrary.SymbolTableInfo.HasInfo) then
|
if (ALibrary.DbgInfo.HasInfo) or (ALibrary.SymbolTableInfo.HasInfo) then
|
||||||
FSymInstances.Add(ALibrary);
|
FSymInstances.Add(ALibrary);
|
||||||
|
@ -62,6 +62,7 @@ type
|
|||||||
FImgReader: TDbgImageReader;
|
FImgReader: TDbgImageReader;
|
||||||
function GetAddressMapList: TDbgAddressMapList;
|
function GetAddressMapList: TDbgAddressMapList;
|
||||||
function GetImageBase: QWord;
|
function GetImageBase: QWord;
|
||||||
|
function GetRelocationOffset: TDBGPtrOffset;
|
||||||
function GetReaderErrors: String;
|
function GetReaderErrors: String;
|
||||||
function GetSubFiles: TStrings;
|
function GetSubFiles: TStrings;
|
||||||
function GetTargetInfo: TTargetDescriptor;
|
function GetTargetInfo: TTargetDescriptor;
|
||||||
@ -73,10 +74,10 @@ type
|
|||||||
public
|
public
|
||||||
constructor Create; virtual;
|
constructor Create; virtual;
|
||||||
constructor Create(AFileName: String; ADebugMap: TObject = nil;
|
constructor Create(AFileName: String; ADebugMap: TObject = nil;
|
||||||
ARelocationOffset: TDBGPtr = 0);
|
ALoadedTargetImageAddr: TDBGPtr = 0);
|
||||||
{$ifdef USE_WIN_FILE_MAPPING}
|
{$ifdef USE_WIN_FILE_MAPPING}
|
||||||
constructor Create(AFileHandle: THandle; ADebugMap: TObject = nil;
|
constructor Create(AFileHandle: THandle; ADebugMap: TObject = nil;
|
||||||
ARelocationOffset: TDBGPtr = 0);
|
ALoadedTargetImageAddr: TDBGPtr = 0);
|
||||||
{$endif}
|
{$endif}
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
procedure ParseSymbolTable(AFpSymbolInfo: TfpSymbolList); virtual;
|
procedure ParseSymbolTable(AFpSymbolInfo: TfpSymbolList); virtual;
|
||||||
@ -85,6 +86,7 @@ type
|
|||||||
function IsValid: Boolean;
|
function IsValid: Boolean;
|
||||||
property FileName: String read FFileName; // Empty if using USE_WIN_FILE_MAPPING
|
property FileName: String read FFileName; // Empty if using USE_WIN_FILE_MAPPING
|
||||||
property ImageBase: QWord read GetImageBase;
|
property ImageBase: QWord read GetImageBase;
|
||||||
|
property RelocationOffset: TDBGPtrOffset read GetRelocationOffset;
|
||||||
property TargetInfo: TTargetDescriptor read GetTargetInfo;
|
property TargetInfo: TTargetDescriptor read GetTargetInfo;
|
||||||
|
|
||||||
property UUID: TGuid read GetUUID;
|
property UUID: TGuid read GetUUID;
|
||||||
@ -110,16 +112,15 @@ type
|
|||||||
|
|
||||||
TDbgImageLoaderList = class(TFPObjectList)
|
TDbgImageLoaderList = class(TFPObjectList)
|
||||||
private
|
private
|
||||||
FRelocationOffset: TDBGPtr;
|
function GetRelocationOffset: TDBGPtrOffset;
|
||||||
function GetImageBase: QWord;
|
function GetImageBase: QWord;
|
||||||
function GetTargetInfo: TTargetDescriptor;
|
function GetTargetInfo: TTargetDescriptor;
|
||||||
function GetItem(Index: Integer): TDbgImageLoader;
|
function GetItem(Index: Integer): TDbgImageLoader;
|
||||||
procedure SetItem(Index: Integer; AValue: TDbgImageLoader);
|
procedure SetItem(Index: Integer; AValue: TDbgImageLoader);
|
||||||
public
|
public
|
||||||
constructor Create(FreeObjects : Boolean; ARelocationOffset: TDbgPtr);
|
|
||||||
property Items[Index: Integer]: TDbgImageLoader read GetItem write SetItem; default;
|
property Items[Index: Integer]: TDbgImageLoader read GetItem write SetItem; default;
|
||||||
property ImageBase: QWord read GetImageBase;
|
property ImageBase: QWord read GetImageBase;
|
||||||
property RelocationOffset: QWord read FRelocationOffset;
|
property RelocationOffset: TDBGPtrOffset read GetRelocationOffset;
|
||||||
property TargetInfo: TTargetDescriptor read GetTargetInfo;
|
property TargetInfo: TTargetDescriptor read GetTargetInfo;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -127,6 +128,17 @@ implementation
|
|||||||
|
|
||||||
{ TDbgImageLoaderList }
|
{ TDbgImageLoaderList }
|
||||||
|
|
||||||
|
function TDbgImageLoaderList.GetRelocationOffset: TDBGPtrOffset;
|
||||||
|
begin
|
||||||
|
if Count>0 then
|
||||||
|
result := Items[0].RelocationOffset
|
||||||
|
else
|
||||||
|
begin
|
||||||
|
Result.Offset := 0;
|
||||||
|
Result.Sign := sPositive;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
function TDbgImageLoaderList.GetImageBase: QWord;
|
function TDbgImageLoaderList.GetImageBase: QWord;
|
||||||
begin
|
begin
|
||||||
if Count>0 then
|
if Count>0 then
|
||||||
@ -153,12 +165,6 @@ begin
|
|||||||
inherited SetItem(Index, AValue);
|
inherited SetItem(Index, AValue);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
constructor TDbgImageLoaderList.Create(FreeObjects: Boolean; ARelocationOffset: TDbgPtr);
|
|
||||||
begin
|
|
||||||
inherited Create(FreeObjects);
|
|
||||||
FRelocationOffset := ARelocationOffset;
|
|
||||||
end;
|
|
||||||
|
|
||||||
{ TDbgImageLoaderLibrary }
|
{ TDbgImageLoaderLibrary }
|
||||||
|
|
||||||
procedure TDbgImageLoaderLibrary.ParseSymbolTable(AFpSymbolInfo: TfpSymbolList);
|
procedure TDbgImageLoaderLibrary.ParseSymbolTable(AFpSymbolInfo: TfpSymbolList);
|
||||||
@ -194,6 +200,17 @@ begin
|
|||||||
Result := 0;
|
Result := 0;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TDbgImageLoader.GetRelocationOffset: TDBGPtrOffset;
|
||||||
|
begin
|
||||||
|
if Assigned(FImgReader) then
|
||||||
|
Result := FImgReader.RelocationOffset
|
||||||
|
else
|
||||||
|
begin
|
||||||
|
Result.Offset := 0;
|
||||||
|
Result.Sign := sPositive;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
function TDbgImageLoader.GetReaderErrors: String;
|
function TDbgImageLoader.GetReaderErrors: String;
|
||||||
begin
|
begin
|
||||||
if FImgReader <> nil then
|
if FImgReader <> nil then
|
||||||
@ -238,21 +255,21 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
constructor TDbgImageLoader.Create(AFileName: String; ADebugMap: TObject;
|
constructor TDbgImageLoader.Create(AFileName: String; ADebugMap: TObject;
|
||||||
ARelocationOffset: TDBGPtr);
|
ALoadedTargetImageAddr: TDBGPtr);
|
||||||
begin
|
begin
|
||||||
FFileName := AFileName;
|
FFileName := AFileName;
|
||||||
FFileLoader := TDbgFileLoader.Create(AFileName);
|
FFileLoader := TDbgFileLoader.Create(AFileName);
|
||||||
FImgReader := GetImageReader(FFileLoader, ADebugMap, ARelocationOffset, False);
|
FImgReader := GetImageReader(FFileLoader, ADebugMap, ALoadedTargetImageAddr, False);
|
||||||
if not Assigned(FImgReader) then
|
if not Assigned(FImgReader) then
|
||||||
FreeAndNil(FFileLoader);
|
FreeAndNil(FFileLoader);
|
||||||
end;
|
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;
|
||||||
ARelocationOffset: TDBGPtr);
|
ALoadedTargetImageAddr: TDBGPtr);
|
||||||
begin
|
begin
|
||||||
FFileLoader := TDbgFileLoader.Create(AFileHandle);
|
FFileLoader := TDbgFileLoader.Create(AFileHandle);
|
||||||
FImgReader := GetImageReader(FFileLoader, ADebugMap, ARelocationOffset, False);
|
FImgReader := GetImageReader(FFileLoader, ADebugMap, ALoadedTargetImageAddr, False);
|
||||||
if not Assigned(FImgReader) then
|
if not Assigned(FImgReader) then
|
||||||
FreeAndNil(FFileLoader);
|
FreeAndNil(FFileLoader);
|
||||||
end;
|
end;
|
||||||
|
@ -229,7 +229,7 @@ type
|
|||||||
procedure InitializeLoaders; override;
|
procedure InitializeLoaders; override;
|
||||||
public
|
public
|
||||||
constructor Create(const AProcess: TDbgProcess; const ADefaultName: String;
|
constructor Create(const AProcess: TDbgProcess; const ADefaultName: String;
|
||||||
const AModuleHandle: THandle; const ABaseAddr: TDbgPtr; AInfo: TLoadDLLDebugInfo);
|
const AModuleHandle: THandle; AInfo: TLoadDLLDebugInfo);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
@ -451,11 +451,11 @@ end;
|
|||||||
|
|
||||||
constructor tDbgWinLibrary.Create(const AProcess: TDbgProcess;
|
constructor tDbgWinLibrary.Create(const AProcess: TDbgProcess;
|
||||||
const ADefaultName: String; const AModuleHandle: THandle;
|
const ADefaultName: String; const AModuleHandle: THandle;
|
||||||
const ABaseAddr: TDbgPtr; AInfo: TLoadDLLDebugInfo);
|
AInfo: TLoadDLLDebugInfo);
|
||||||
var
|
var
|
||||||
S: String;
|
S: String;
|
||||||
begin
|
begin
|
||||||
inherited Create(AProcess, ADefaultName, AModuleHandle, ABaseAddr);
|
inherited Create(AProcess, ADefaultName, AModuleHandle);
|
||||||
FInfo := AInfo;
|
FInfo := AInfo;
|
||||||
|
|
||||||
s := TDbgWinProcess(AProcess).GetProcFilename(AProcess, AInfo.lpImageName, AInfo.fUnicode, AInfo.hFile);
|
s := TDbgWinProcess(AProcess).GetProcFilename(AProcess, AInfo.lpImageName, AInfo.fUnicode, AInfo.hFile);
|
||||||
@ -481,7 +481,7 @@ procedure TDbgWinProcess.InitializeLoaders;
|
|||||||
var
|
var
|
||||||
Loader: TDbgImageLoader;
|
Loader: TDbgImageLoader;
|
||||||
begin
|
begin
|
||||||
Loader := TDbgImageLoader.Create(FInfo.hFile);
|
Loader := TDbgImageLoader.Create(FInfo.hFile, nil, TDbgPtr(FInfo.lpBaseOfImage));
|
||||||
if Loader.IsValid then
|
if Loader.IsValid then
|
||||||
Loader.AddToLoaderList(LoaderList)
|
Loader.AddToLoaderList(LoaderList)
|
||||||
else
|
else
|
||||||
@ -1389,7 +1389,7 @@ function TDbgWinProcess.AddLib(const AInfo: TLoadDLLDebugInfo): TDbgLibrary;
|
|||||||
var
|
var
|
||||||
ID: TDbgPtr;
|
ID: TDbgPtr;
|
||||||
begin
|
begin
|
||||||
Result := TDbgWinLibrary.Create(Self, HexValue(AInfo.lpBaseOfDll, SizeOf(Pointer), [hvfIncludeHexchar]), AInfo.hFile, TDbgPtr(AInfo.lpBaseOfDll), AInfo);
|
Result := TDbgWinLibrary.Create(Self, HexValue(AInfo.lpBaseOfDll, SizeOf(Pointer), [hvfIncludeHexchar]), AInfo.hFile, AInfo);
|
||||||
ID := TDbgPtr(AInfo.lpBaseOfDll);
|
ID := TDbgPtr(AInfo.lpBaseOfDll);
|
||||||
FLibMap.Add(ID, Result);
|
FLibMap.Add(ID, Result);
|
||||||
if (Result.DbgInfo.HasInfo) or (Result.SymbolTableInfo.HasInfo)
|
if (Result.DbgInfo.HasInfo) or (Result.SymbolTableInfo.HasInfo)
|
||||||
|
@ -97,7 +97,8 @@ type
|
|||||||
private
|
private
|
||||||
FImageBase: QWord;
|
FImageBase: QWord;
|
||||||
FImageSize: QWord;
|
FImageSize: QWord;
|
||||||
FRelocationOffset: TDBGPtr;
|
FRelocationOffset: TDBGPtrOffset;
|
||||||
|
FLoadedTargetImageAddr: TDBGPtr;
|
||||||
FReaderErrors: String;
|
FReaderErrors: String;
|
||||||
FUUID: TGuid;
|
FUUID: TGuid;
|
||||||
protected
|
protected
|
||||||
@ -109,15 +110,17 @@ type
|
|||||||
procedure SetUUID(AGuid: TGuid);
|
procedure SetUUID(AGuid: TGuid);
|
||||||
procedure SetImageBase(ABase: QWord);
|
procedure SetImageBase(ABase: QWord);
|
||||||
procedure SetImageSize(ASize: QWord);
|
procedure SetImageSize(ASize: QWord);
|
||||||
|
procedure SetRelocationOffset(AnOffset: TDBGPtr; Sign: TDBGPtrSign);
|
||||||
procedure AddReaderError(AnError: String);
|
procedure AddReaderError(AnError: String);
|
||||||
function ReadGnuDebugLinkSection(out AFileName: String; out ACrc: Cardinal): Boolean;
|
function ReadGnuDebugLinkSection(out AFileName: String; out ACrc: Cardinal): Boolean;
|
||||||
function LoadGnuDebugLink(ASearchPath, AFileName: String; ACrc: Cardinal): TDbgFileLoader;
|
function LoadGnuDebugLink(ASearchPath, AFileName: String; ACrc: Cardinal): TDbgFileLoader;
|
||||||
|
property LoadedTargetImageAddr: TDBGPtr read FLoadedTargetImageAddr;
|
||||||
public
|
public
|
||||||
class function isValid(ASource: TDbgFileLoader): Boolean; virtual; abstract;
|
class function isValid(ASource: TDbgFileLoader): Boolean; virtual; abstract;
|
||||||
class function UserName: AnsiString; virtual; abstract;
|
class function UserName: AnsiString; virtual; abstract;
|
||||||
procedure ParseSymbolTable(AFpSymbolInfo: TfpSymbolList); virtual;
|
procedure ParseSymbolTable(AFpSymbolInfo: TfpSymbolList); virtual;
|
||||||
procedure ParseLibrarySymbolTable(AFpSymbolInfo: TfpSymbolList); virtual;
|
procedure ParseLibrarySymbolTable(AFpSymbolInfo: TfpSymbolList); virtual;
|
||||||
constructor Create({%H-}ASource: TDbgFileLoader; {%H-}ADebugMap: TObject; ARelocationOffset: TDbgPtr; OwnSource: Boolean); virtual;
|
constructor Create({%H-}ASource: TDbgFileLoader; {%H-}ADebugMap: TObject; ALoadedTargetImageAddr: TDbgPtr; OwnSource: Boolean); virtual;
|
||||||
procedure AddSubFilesToLoaderList(ALoaderList: TObject; PrimaryLoader: TObject); virtual;
|
procedure AddSubFilesToLoaderList(ALoaderList: TObject; PrimaryLoader: TObject); virtual;
|
||||||
// The ImageBase is the address at which the linker assumed the binary will be
|
// The ImageBase is the address at which the linker assumed the binary will be
|
||||||
// loaded. So it is stored inside the binary itself, in contrast to the
|
// loaded. So it is stored inside the binary itself, in contrast to the
|
||||||
@ -125,6 +128,10 @@ type
|
|||||||
// been loaded into another position.
|
// been loaded into another position.
|
||||||
property ImageBase: QWord read FImageBase;
|
property ImageBase: QWord read FImageBase;
|
||||||
property ImageSize: QWord read FImageSize;
|
property ImageSize: QWord read FImageSize;
|
||||||
|
// The relocationoffset is the offset at which the binary (most likely
|
||||||
|
// library) is loaded into memory. It is not part of the binary itself, unlike
|
||||||
|
// the BaseAddr.
|
||||||
|
property RelocationOffset: TDBGPtrOffset read FRelocationOffset;
|
||||||
|
|
||||||
property TargetInfo: TTargetDescriptor read FTargetInfo;
|
property TargetInfo: TTargetDescriptor read FTargetInfo;
|
||||||
|
|
||||||
@ -134,15 +141,10 @@ type
|
|||||||
property SubFiles: TStrings read GetSubFiles;
|
property SubFiles: TStrings read GetSubFiles;
|
||||||
property AddressMapList: TDbgAddressMapList read GetAddressMapList;
|
property AddressMapList: TDbgAddressMapList read GetAddressMapList;
|
||||||
property ReaderErrors: String read FReaderErrors;
|
property ReaderErrors: String read FReaderErrors;
|
||||||
|
|
||||||
// The relocationoffset is the offset at which the binary (most likely
|
|
||||||
// library) is loaded into memory. It is not part of the binary itself, unlike
|
|
||||||
// the BaseAddr.
|
|
||||||
property RelocationOffset: TDBGPtr read FRelocationOffset;
|
|
||||||
end;
|
end;
|
||||||
TDbgImageReaderClass = class of TDbgImageReader;
|
TDbgImageReaderClass = class of TDbgImageReader;
|
||||||
|
|
||||||
function GetImageReader(ASource: TDbgFileLoader; ADebugMap: TObject; ARelocationOffset: TDbgPtr; OwnSource: Boolean): TDbgImageReader; overload;
|
function GetImageReader(ASource: TDbgFileLoader; ADebugMap: TObject; ALoadedTargetImageAddr: TDbgPtr; OwnSource: Boolean): TDbgImageReader; overload;
|
||||||
procedure RegisterImageReaderClass(DataSource: TDbgImageReaderClass);
|
procedure RegisterImageReaderClass(DataSource: TDbgImageReaderClass);
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
@ -184,7 +186,7 @@ end;
|
|||||||
result := (r1.OrgAddr=r2.OrgAddr) and (r1.Length=r2.Length) and (r1.NewAddr=r2.NewAddr);
|
result := (r1.OrgAddr=r2.OrgAddr) and (r1.Length=r2.Length) and (r1.NewAddr=r2.NewAddr);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function GetImageReader(ASource: TDbgFileLoader; ADebugMap: TObject; ARelocationOffset: TDbgPtr; OwnSource: Boolean): TDbgImageReader;
|
function GetImageReader(ASource: TDbgFileLoader; ADebugMap: TObject; ALoadedTargetImageAddr: TDbgPtr; OwnSource: Boolean): TDbgImageReader;
|
||||||
var
|
var
|
||||||
i : Integer;
|
i : Integer;
|
||||||
cls : TDbgImageReaderClass;
|
cls : TDbgImageReaderClass;
|
||||||
@ -196,7 +198,7 @@ begin
|
|||||||
cls := TDbgImageReaderClass(RegisteredImageReaderClasses[i]);
|
cls := TDbgImageReaderClass(RegisteredImageReaderClasses[i]);
|
||||||
try
|
try
|
||||||
if cls.isValid(ASource) then begin
|
if cls.isValid(ASource) then begin
|
||||||
Result := cls.Create(ASource, ADebugMap, ARelocationOffset, OwnSource);
|
Result := cls.Create(ASource, ADebugMap, ALoadedTargetImageAddr, OwnSource);
|
||||||
ASource.Close;
|
ASource.Close;
|
||||||
Exit;
|
Exit;
|
||||||
end
|
end
|
||||||
@ -418,6 +420,12 @@ begin
|
|||||||
FImageSize := ASize;
|
FImageSize := ASize;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TDbgImageReader.SetRelocationOffset(AnOffset: TDBGPtr; Sign: TDBGPtrSign);
|
||||||
|
begin
|
||||||
|
FRelocationOffset.Offset := AnOffset;
|
||||||
|
FRelocationOffset.Sign := Sign;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TDbgImageReader.AddReaderError(AnError: String);
|
procedure TDbgImageReader.AddReaderError(AnError: String);
|
||||||
begin
|
begin
|
||||||
if FReaderErrors <> '' then
|
if FReaderErrors <> '' then
|
||||||
@ -503,10 +511,10 @@ begin
|
|||||||
//
|
//
|
||||||
end;
|
end;
|
||||||
|
|
||||||
constructor TDbgImageReader.Create(ASource: TDbgFileLoader; ADebugMap: TObject; ARelocationOffset: TDbgPtr; OwnSource: Boolean);
|
constructor TDbgImageReader.Create(ASource: TDbgFileLoader; ADebugMap: TObject; ALoadedTargetImageAddr: TDbgPtr; OwnSource: Boolean);
|
||||||
begin
|
begin
|
||||||
inherited Create;
|
inherited Create;
|
||||||
FRelocationOffset := ARelocationOffset;
|
FLoadedTargetImageAddr := ALoadedTargetImageAddr;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TDbgImageReader.AddSubFilesToLoaderList(ALoaderList: TObject;
|
procedure TDbgImageReader.AddSubFilesToLoaderList(ALoaderList: TObject;
|
||||||
|
@ -411,6 +411,8 @@ begin
|
|||||||
//FSections.Duplicates := dupError;
|
//FSections.Duplicates := dupError;
|
||||||
FSections.CaseSensitive := False;
|
FSections.CaseSensitive := False;
|
||||||
|
|
||||||
|
SetRelocationOffset(ALoadedTargetImageAddr, sPositive);
|
||||||
|
|
||||||
FFileLoader := ASource;
|
FFileLoader := ASource;
|
||||||
fOwnSource := OwnSource;
|
fOwnSource := OwnSource;
|
||||||
fElfFile := TElfFile.Create;
|
fElfFile := TElfFile.Create;
|
||||||
|
@ -66,7 +66,7 @@ type
|
|||||||
class function isValid(ASource: TDbgFileLoader): Boolean; override;
|
class function isValid(ASource: TDbgFileLoader): Boolean; override;
|
||||||
class function UserName: AnsiString; override;
|
class function UserName: AnsiString; override;
|
||||||
public
|
public
|
||||||
constructor Create(ASource: TDbgFileLoader; ADebugMap: TObject; ARelocationOffset: TDbgPtr; OwnSource: Boolean); override;
|
constructor Create(ASource: TDbgFileLoader; ADebugMap: TObject; ALoadedTargetImageAddr: TDbgPtr; OwnSource: Boolean); override;
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
procedure ParseSymbolTable(AfpSymbolInfo: TfpSymbolList); override;
|
procedure ParseSymbolTable(AfpSymbolInfo: TfpSymbolList); override;
|
||||||
procedure ParseLibrarySymbolTable(AFpSymbolInfo: TfpSymbolList); override;
|
procedure ParseLibrarySymbolTable(AFpSymbolInfo: TfpSymbolList); override;
|
||||||
@ -105,13 +105,13 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
constructor TPEFileSource.Create(ASource: TDbgFileLoader; ADebugMap: TObject; ARelocationOffset: TDbgPtr; OwnSource: Boolean);
|
constructor TPEFileSource.Create(ASource: TDbgFileLoader; ADebugMap: TObject; ALoadedTargetImageAddr: TDbgPtr; OwnSource: Boolean);
|
||||||
var
|
var
|
||||||
crc: cardinal;
|
crc: cardinal;
|
||||||
DbgFileName, SourceFileName: String;
|
DbgFileName, SourceFileName: String;
|
||||||
NewFileLoader: TDbgFileLoader;
|
NewFileLoader: TDbgFileLoader;
|
||||||
begin
|
begin
|
||||||
inherited Create(ASource, ADebugMap, ARelocationOffset, OwnSource);
|
inherited Create(ASource, ADebugMap, ALoadedTargetImageAddr, OwnSource);
|
||||||
FSections := TStringListUTF8Fast.Create;
|
FSections := TStringListUTF8Fast.Create;
|
||||||
FSections.Sorted := False; // need sections in original order / Symbols use "SectionNumber"
|
FSections.Sorted := False; // need sections in original order / Symbols use "SectionNumber"
|
||||||
//FSections.Duplicates := dupError;
|
//FSections.Duplicates := dupError;
|
||||||
@ -231,7 +231,6 @@ begin
|
|||||||
if ImageBase = 0 then
|
if ImageBase = 0 then
|
||||||
exit;
|
exit;
|
||||||
|
|
||||||
SetImageBase(ImageBase);
|
|
||||||
FFileLoader.LoadMemory(0, 1, hBase); // size does not matter, only obtain address
|
FFileLoader.LoadMemory(0, 1, hBase); // size does not matter, only obtain address
|
||||||
if (hBase = nil) or (hBase^.e_magic <> IMAGE_DOS_SIGNATURE) then
|
if (hBase = nil) or (hBase^.e_magic <> IMAGE_DOS_SIGNATURE) then
|
||||||
exit;
|
exit;
|
||||||
@ -457,6 +456,10 @@ begin
|
|||||||
SetImageBase(NtHeaders.W32.OptionalHeader.ImageBase);
|
SetImageBase(NtHeaders.W32.OptionalHeader.ImageBase);
|
||||||
SetImageSize(NtHeaders.W32.OptionalHeader.SizeOfImage);
|
SetImageSize(NtHeaders.W32.OptionalHeader.SizeOfImage);
|
||||||
end;
|
end;
|
||||||
|
if LoadedTargetImageAddr >= ImageBase then
|
||||||
|
SetRelocationOffset(LoadedTargetImageAddr-ImageBase, sPositive)
|
||||||
|
else
|
||||||
|
SetRelocationOffset(ImageBase-LoadedTargetImageAddr, sNegative);
|
||||||
FCodeBase := NtHeaders.W32.OptionalHeader.BaseOfCode;
|
FCodeBase := NtHeaders.W32.OptionalHeader.BaseOfCode;
|
||||||
SectionMax := FFileLoader.LoadMemory(
|
SectionMax := FFileLoader.LoadMemory(
|
||||||
DosHeader.e_lfanew +
|
DosHeader.e_lfanew +
|
||||||
|
Loading…
Reference in New Issue
Block a user