mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-18 18:59:21 +02:00
LazDebuggerFp (pure): Parse symbol-table on Windows. (Enables software-exceptions support)
git-svn-id: trunk@45162 -
This commit is contained in:
parent
f31423f2de
commit
3d95b919cf
@ -39,7 +39,8 @@ unit FpImgReaderWinPE;
|
|||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
Classes, SysUtils, math, FpImgReaderBase, FpImgReaderWinPETypes, LazLoggerBase;
|
Classes, SysUtils, math, FpImgReaderBase, FpImgReaderWinPETypes, LazLoggerBase,
|
||||||
|
fpDbgSymTable;
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
||||||
@ -50,6 +51,7 @@ type
|
|||||||
FSections: TStringList;
|
FSections: TStringList;
|
||||||
FFileLoader : TDbgFileLoader;
|
FFileLoader : TDbgFileLoader;
|
||||||
FOwnLoader : Boolean;
|
FOwnLoader : Boolean;
|
||||||
|
FCodeBase : DWord;
|
||||||
protected
|
protected
|
||||||
function GetSection(const AName: String): PDbgImageSection; override;
|
function GetSection(const AName: String): PDbgImageSection; override;
|
||||||
|
|
||||||
@ -60,10 +62,20 @@ type
|
|||||||
public
|
public
|
||||||
constructor Create(ASource: TDbgFileLoader; OwnSource: Boolean); override;
|
constructor Create(ASource: TDbgFileLoader; OwnSource: Boolean); override;
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
|
procedure ParseSymbolTable(AfpSymbolInfo: TfpSymbolList); override;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
|
const
|
||||||
|
// Symbol-map section name
|
||||||
|
_symbol = '.symbols';
|
||||||
|
_symbolstrings = '.symbolsstrings';
|
||||||
|
|
||||||
|
type
|
||||||
|
PImageSymbolArray = ^TImageSymbolArray;
|
||||||
|
TImageSymbolArray = array[0..maxSmallint] of TImageSymbol;
|
||||||
|
|
||||||
function isValidPEStream(ASource: TDbgFileLoader): Boolean;
|
function isValidPEStream(ASource: TDbgFileLoader): Boolean;
|
||||||
var
|
var
|
||||||
DosHeader: TImageDosHeader;
|
DosHeader: TImageDosHeader;
|
||||||
@ -104,6 +116,47 @@ begin
|
|||||||
inherited Destroy;
|
inherited Destroy;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TPEFileSource.ParseSymbolTable(AfpSymbolInfo: TfpSymbolList);
|
||||||
|
var
|
||||||
|
p: PDbgImageSection;
|
||||||
|
ps: PDbgImageSection;
|
||||||
|
SymbolArr: PImageSymbolArray;
|
||||||
|
SymbolStr: pointer;
|
||||||
|
i,j: integer;
|
||||||
|
SymbolCount: integer;
|
||||||
|
SymbolName: AnsiString;
|
||||||
|
begin
|
||||||
|
p := Section[_symbol];
|
||||||
|
ps := Section[_symbolstrings];
|
||||||
|
if assigned(p) and assigned(ps) then
|
||||||
|
begin
|
||||||
|
SymbolArr:=PDbgImageSectionEx(p)^.Sect.RawData;
|
||||||
|
SymbolStr:=PDbgImageSectionEx(ps)^.Sect.RawData;
|
||||||
|
SymbolCount := PDbgImageSectionEx(p)^.Sect.Size div sizeof(TImageSymbol);
|
||||||
|
for i := 0 to SymbolCount-1 do
|
||||||
|
begin
|
||||||
|
begin
|
||||||
|
// Section-index is ignored for now...
|
||||||
|
if SymbolArr^[i].N.Name.Short=0 then
|
||||||
|
SymbolName:=pchar(SymbolStr+SymbolArr^[i].N.Name.Long)
|
||||||
|
else
|
||||||
|
begin
|
||||||
|
SymbolName:='';
|
||||||
|
if SymbolArr^[i].N.Name.Long<>0 then
|
||||||
|
begin
|
||||||
|
for j := 0 to sizeof(SymbolArr^[i].N.ShortName)-1 do
|
||||||
|
begin
|
||||||
|
if SymbolArr^[i].N.ShortName[j]=#0 then break;
|
||||||
|
SymbolName:=SymbolName+SymbolArr^[i].N.ShortName[j];
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
AfpSymbolInfo.AddObject(SymbolName, TObject(PtrUInt(SymbolArr^[i].Value+ImageBase+FCodeBase)));
|
||||||
|
end
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
function TPEFileSource.GetSection(const AName: String): PDbgImageSection;
|
function TPEFileSource.GetSection(const AName: String): PDbgImageSection;
|
||||||
var
|
var
|
||||||
i: Integer;
|
i: Integer;
|
||||||
@ -150,6 +203,8 @@ var
|
|||||||
SectionName: array[0..IMAGE_SIZEOF_SHORT_NAME] of Char;
|
SectionName: array[0..IMAGE_SIZEOF_SHORT_NAME] of Char;
|
||||||
SectionMax: QWord;
|
SectionMax: QWord;
|
||||||
s: string[255];
|
s: string[255];
|
||||||
|
StringTableLen: DWord;
|
||||||
|
StringTableStart: QWord;
|
||||||
begin
|
begin
|
||||||
FFileLoader.Read(0, sizeof(DosHeader), @DosHeader);
|
FFileLoader.Read(0, sizeof(DosHeader), @DosHeader);
|
||||||
if (DosHeader.e_magic <> IMAGE_DOS_SIGNATURE)
|
if (DosHeader.e_magic <> IMAGE_DOS_SIGNATURE)
|
||||||
@ -171,7 +226,7 @@ begin
|
|||||||
if Image64Bit
|
if Image64Bit
|
||||||
then SetImageBase(NtHeaders.W64.OptionalHeader.ImageBase)
|
then SetImageBase(NtHeaders.W64.OptionalHeader.ImageBase)
|
||||||
else SetImageBase(NtHeaders.W32.OptionalHeader.ImageBase);
|
else SetImageBase(NtHeaders.W32.OptionalHeader.ImageBase);
|
||||||
|
FCodeBase := NtHeaders.W32.OptionalHeader.BaseOfCode;
|
||||||
SectionMax := FFileLoader.LoadMemory(
|
SectionMax := FFileLoader.LoadMemory(
|
||||||
DosHeader.e_lfanew +
|
DosHeader.e_lfanew +
|
||||||
(@NtHeaders.Sys.OptionalHeader - @NtHeaders.Sys) +
|
(@NtHeaders.Sys.OptionalHeader - @NtHeaders.Sys) +
|
||||||
@ -208,6 +263,15 @@ begin
|
|||||||
end
|
end
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
// Create a fake-sections for the symbol-table:
|
||||||
|
if NtHeaders.Sys.FileHeader.PointerToSymbolTable<>0 then
|
||||||
|
begin
|
||||||
|
Add(_symbol,NtHeaders.Sys.FileHeader.PointerToSymbolTable, NtHeaders.Sys.FileHeader.NumberOfSymbols*IMAGE_SIZEOF_SYMBOL,0);
|
||||||
|
StringTableStart:=NtHeaders.Sys.FileHeader.PointerToSymbolTable+NtHeaders.Sys.FileHeader.NumberOfSymbols*IMAGE_SIZEOF_SYMBOL;
|
||||||
|
FFileLoader.Read(StringTableStart, sizeof(DWord), @StringTableLen);
|
||||||
|
Add(_symbolstrings,StringTableStart, StringTableLen, 0);
|
||||||
|
end;
|
||||||
|
|
||||||
FFileLoader.UnloadMemory(SectionHeader);
|
FFileLoader.UnloadMemory(SectionHeader);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user