1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
|
unit fpDbgSymTableContext;
{$mode objfpc}{$H+}
interface
uses
Classes,
SysUtils,
FpDbgLoader,
FpImgReaderBase,
DbgIntfBaseTypes,
fpDbgSymTable,
FpdMemoryTools,
FpDbgInfo;
type
TFpSymbolInfo = class;
{ TFpSymbolContext }
TFpSymbolContext = class(TFpDbgInfoContext)
private
FFpSymbolInfo: TFpSymbolInfo;
FSizeOfAddress: integer;
protected
function GetAddress: TDbgPtr; override;
function GetStackFrame: Integer; override;
function GetThreadId: Integer; override;
function GetSizeOfAddress: Integer; override;
public
constructor Create(AFpSymbolInfo: TFpSymbolInfo);
function FindSymbol(const AName: String): TFpDbgValue; override;
end;
{ TFpSymbolInfo }
TFpSymbolInfo = class(TDbgInfo)
private
FSymbolList: TfpSymbolList;
FContext: TFpSymbolContext;
FImage64Bit: boolean;
public
constructor Create(ALoaderList: TDbgImageLoaderList); override;
destructor Destroy; override;
function FindContext(AThreadId, AStackFrame: Integer; AAddress: TDbgPtr = 0): TFpDbgInfoContext; override;
function FindContext(AAddress: TDbgPtr): TFpDbgInfoContext; override;
function FindSymbol(AAddress: TDbgPtr): TFpDbgSymbol; override;
function FindSymbol(const AName: String): TFpDbgSymbol; override;
property Image64Bit: boolean read FImage64Bit;
end;
implementation
{ TFpSymbolContext }
function TFpSymbolContext.GetAddress: TDbgPtr;
begin
result := 0;
end;
function TFpSymbolContext.GetStackFrame: Integer;
begin
result := 0;
end;
function TFpSymbolContext.GetThreadId: Integer;
begin
result := 1;
end;
function TFpSymbolContext.GetSizeOfAddress: Integer;
begin
result := FSizeOfAddress;
end;
constructor TFpSymbolContext.Create(AFpSymbolInfo: TFpSymbolInfo);
begin
inherited create;
FFpSymbolInfo:=AFpSymbolInfo;
if AFpSymbolInfo.Image64Bit then
FSizeOfAddress:=8
else
FSizeOfAddress:=4;
end;
function TFpSymbolContext.FindSymbol(const AName: String): TFpDbgValue;
var
i: integer;
val: TFpDbgMemLocation;
begin
i := FFpSymbolInfo.FSymbolList.IndexOf(AName);
if i > -1 then
begin
val.Address:=FFpSymbolInfo.FSymbolList.Data[i];
val.MType:=mlfTargetMem;
result := TFpDbgValueConstAddress.Create(val);
end
else
result := nil;
end;
{ TFpSymbolInfo }
constructor TFpSymbolInfo.Create(ALoaderList: TDbgImageLoaderList);
var
i: Integer;
begin
inherited Create(ALoaderList);
FContext := TFpSymbolContext.Create(self);
FSymbolList := TfpSymbolList.Create;
for i := 0 to ALoaderList.Count-1 do
ALoaderList[i].ParseSymbolTable(FSymbolList);
FImage64Bit := ALoaderList.Image64Bit;
end;
destructor TFpSymbolInfo.Destroy;
begin
FSymbolList.Free;
FContext.Free;
inherited Destroy;
end;
function TFpSymbolInfo.FindContext(AThreadId, AStackFrame: Integer;
AAddress: TDbgPtr): TFpDbgInfoContext;
begin
Result:=FContext;
end;
function TFpSymbolInfo.FindContext(AAddress: TDbgPtr): TFpDbgInfoContext;
begin
Result:=FContext;
end;
function TFpSymbolInfo.FindSymbol(AAddress: TDbgPtr): TFpDbgSymbol;
begin
Result:=inherited FindSymbol(AAddress);
end;
function TFpSymbolInfo.FindSymbol(const AName: String): TFpDbgSymbol;
begin
result := nil;
//Result:=FContext.FindSymbol(AName);
end;
end.
|