FpDebug: test and helper apps, fixed some compile errors

git-svn-id: trunk@64555 -
This commit is contained in:
martin 2021-02-12 18:31:09 +00:00
parent 068feeb931
commit 14dc58d892
7 changed files with 91 additions and 55 deletions

View File

@ -263,7 +263,10 @@ begin
Val(P, Address, e);
if e <> 0
then begin
AContext := GController.CurrentProcess.SymbolTableInfo.FindSymbolScope(GController.CurrentThread.GetInstructionPointerRegisterValue);
AContext := GController.CurrentProcess.SymbolTableInfo.FindSymbolScope(
GController.DefaultContext,
GController.CurrentThread.GetInstructionPointerRegisterValue
);
if AContext = nil then begin
Writeln('Invalid context');
exit;
@ -593,7 +596,10 @@ begin
S := AParams;
P := GetPart([], [' ', #9], S);
AContext := GController.CurrentProcess.DbgInfo.FindSymbolScope(GController.CurrentThread.GetInstructionPointerRegisterValue);
AContext := GController.CurrentProcess.DbgInfo.FindSymbolScope(
GController.DefaultContext,
GController.CurrentThread.GetInstructionPointerRegisterValue
);
if AContext = nil then begin
Writeln('Invalid context');
exit;

View File

@ -686,7 +686,6 @@ begin
end;
Result := True;
AContext.MemManager.DefaultContext := AContext.LocationContext;
APasExpr := TFpPascalExpression.Create(FExpression, AContext);
try
APasExpr.ResultValue; // trigger full validation
@ -700,7 +699,7 @@ begin
APrettyPrinter := TFpPascalPrettyPrinter.Create(sizeof(pointer));
try
APrettyPrinter.AddressSize:=AContext.SizeOfAddress;
APrettyPrinter.MemManager := AContext.MemManager;
APrettyPrinter.Context := AContext.LocationContext;
Res := APrettyPrinter.PrintValue(FResText, ATypeInfo, APasExpr.ResultValue);
if Res then
begin

View File

@ -15,8 +15,27 @@
<i18n>
<EnableI18N LFM="False"/>
</i18n>
<BuildModes Count="1">
<BuildModes Count="2">
<Item1 Name="Default" Default="True"/>
<Item2 Name="32bit">
<CompilerOptions>
<Version Value="11"/>
<PathDelim Value="\"/>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir)"/>
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
<CodeGeneration>
<TargetCPU Value="i386"/>
<TargetOS Value="win32"/>
</CodeGeneration>
<Linking>
<Debugging>
<DebugInfoType Value="dsDwarf3"/>
</Debugging>
</Linking>
</CompilerOptions>
</Item2>
</BuildModes>
<PublishOptions>
<Version Value="2"/>

View File

@ -1,11 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectOptions>
<Version Value="9"/>
<Version Value="12"/>
<PathDelim Value="\"/>
<General>
<Flags>
<CompatibilityMode Value="True"/>
</Flags>
<SessionStorage Value="InProjectDir"/>
<MainUnit Value="0"/>
<Title Value="dwarfviewer"/>
<ResourceType Value="res"/>
<UseXPManifest Value="True"/>
@ -13,9 +15,6 @@
<i18n>
<EnableI18N LFM="False"/>
</i18n>
<VersionInfo>
<StringTable ProductVersion=""/>
</VersionInfo>
<BuildModes Count="2">
<Item1 Name="Default" Default="True"/>
<Item2 Name="opti">
@ -38,11 +37,7 @@
</Debugging>
</Linking>
<Other>
<CompilerMessages>
<UseMsgFile Value="True"/>
</CompilerMessages>
<CustomOptions Value="-WC"/>
<CompilerPath Value="$(CompPath)"/>
</Other>
</CompilerOptions>
</Item2>
@ -54,12 +49,12 @@
<PublishOptions>
<Version Value="2"/>
<DestinationDirectory Value="B:\tmp_work\dwarfviewer"/>
<UseExcludeFileFilter Value="True"/>
</PublishOptions>
<RunParams>
<local>
<FormatVersion Value="1"/>
</local>
<FormatVersion Value="2"/>
<Modes Count="1">
<Mode0 Name="default"/>
</Modes>
</RunParams>
<RequiredPackages Count="2">
<Item1>
@ -73,7 +68,6 @@
<Unit0>
<Filename Value="dwarfviewer.lpr"/>
<IsPartOfProject Value="True"/>
<UnitName Value="dwarfviewer"/>
</Unit0>
<Unit1>
<Filename Value="unit1.pas"/>

View File

@ -203,7 +203,7 @@ begin
FImageLoaderList := TDbgImageLoaderList.Create(True);
ImageLoader.AddToLoaderList(FImageLoaderList);
FDwarfInfo := TFpDwarfInfo.Create(FImageLoaderList);
FDwarfInfo := TFpDwarfInfo.Create(FImageLoaderList, nil);
FCUCount := FDwarfInfo.LoadCompilationUnits;
end;

View File

@ -5,8 +5,9 @@ unit TestMemManager;
interface
uses
FpDbgDwarf, FpDbgUtil, FpdMemoryTools, TestHelperClasses, LazLoggerBase, LazUTF8,
DbgIntfBaseTypes, sysutils, fpcunit, testregistry;
FpDbgDwarf, FpDbgUtil, FpdMemoryTools, FpDbgInfo, TestHelperClasses,
LazLoggerBase, LazUTF8, LazClasses, DbgIntfBaseTypes, sysutils, fpcunit,
testregistry;
type
@ -19,6 +20,7 @@ type
FMemConvTarget: TFpDbgMemConvertorLittleEndian;
FMemConvSelf: TFpDbgMemConvertorLittleEndian;
FMemManager: TFpDbgMemManager;
FDummyContext: TFpDbgSimpleLocationContext;
procedure InitMemMgr;
procedure SetUp; override;
@ -36,6 +38,7 @@ begin
FMemConvTarget := TFpDbgMemConvertorLittleEndian.Create;
FMemConvSelf := TFpDbgMemConvertorLittleEndian.Create;
FMemManager := TFpDbgMemManager.Create(FMemReader, FMemConvTarget, FMemConvSelf);
FDummyContext := TFpDbgSimpleLocationContext.Create(FMemManager, 0, 4, 0, 0);
end;
procedure TTestMemManager.SetUp;
@ -50,6 +53,7 @@ end;
procedure TTestMemManager.TearDown;
begin
inherited TearDown;
ReleaseRefAndNil(FDummyContext);
FreeAndNil(FMemReader);
FreeAndNil(FMemConvTarget);
FreeAndNil(FMemConvSelf);
@ -99,28 +103,28 @@ var
var
a: Cardinal;
begin
GotRes := FMemManager.ReadSignedInt(TargetLoc(TDbgPtr(@Data)), SizeVal(ReadSize), GotInt);
GotRes := FDummyContext.ReadSignedInt(TargetLoc(TDbgPtr(@Data)), SizeVal(ReadSize), GotInt);
CheckIntRes('signed target', ExpIntVal);
GotRes := FMemManager.ReadSignedInt(SelfLoc(@Data), SizeVal(ReadSize), GotInt);
GotRes := FDummyContext.ReadSignedInt(SelfLoc(@Data), SizeVal(ReadSize), GotInt);
CheckIntRes('signed self', ExpIntVal);
FMemReader.RegisterSizes[2] := ReadSize;
GotRes := FMemManager.ReadSignedInt(RegisterLoc(2), SizeVal(ReadSize), GotInt);
GotRes := FDummyContext.ReadSignedInt(RegisterLoc(2), SizeVal(ReadSize), GotInt);
CheckIntRes('signed Reg ', ExpIntVal);
for a := ReadSize+1 to 8 do begin
// expanded
FMemReader.RegisterSizes[2] := ReadSize;
GotRes := FMemManager.ReadSignedInt(RegisterLoc(2), SizeVal(a), GotInt);
GotRes := FDummyContext.ReadSignedInt(RegisterLoc(2), SizeVal(a), GotInt);
CheckIntRes('signed Reg readsize='+IntToStr(a), ExpIntVal);
FMemReader.RegisterSizes[2] := a;
GotRes := FMemManager.ReadSignedInt(RegisterLoc(2), SizeVal(ReadSize), GotInt);
GotRes := FDummyContext.ReadSignedInt(RegisterLoc(2), SizeVal(ReadSize), GotInt);
CheckIntRes('signed Reg regsize'+IntToStr(a), ExpIntVal);
end;
GotRes := FMemManager.ReadSignedInt(ConstLoc(QWord(ExpIntVal)), SizeVal(ReadSize), GotInt);
GotRes := FDummyContext.ReadSignedInt(ConstLoc(QWord(ExpIntVal)), SizeVal(ReadSize), GotInt);
CheckIntRes('signed const (pre-expanded)', ExpIntVal);
end;
@ -128,85 +132,85 @@ var
var
a: Cardinal;
begin
GotRes := FMemManager.ReadUnsignedInt(TargetLoc(TDbgPtr(@Data)), SizeVal(ReadSize), GotUInt);
GotRes := FDummyContext.ReadUnsignedInt(TargetLoc(TDbgPtr(@Data)), SizeVal(ReadSize), GotUInt);
CheckUIntRes('unsigned target', ExpIntVal);
GotRes := FMemManager.ReadUnsignedInt(SelfLoc(@Data), SizeVal(ReadSize), GotUInt);
GotRes := FDummyContext.ReadUnsignedInt(SelfLoc(@Data), SizeVal(ReadSize), GotUInt);
CheckUIntRes('unsigned self', ExpIntVal);
FMemReader.RegisterSizes[2] := ReadSize;
GotRes := FMemManager.ReadUnsignedInt(RegisterLoc(2), SizeVal(ReadSize), GotUInt);
GotRes := FDummyContext.ReadUnsignedInt(RegisterLoc(2), SizeVal(ReadSize), GotUInt);
CheckUIntRes('unsigned Reg ', ExpIntVal);
for a := ReadSize+1 to 8 do begin
// expanded
FMemReader.RegisterSizes[2] := ReadSize;
GotRes := FMemManager.ReadUnsignedInt(RegisterLoc(2), SizeVal(a), GotUInt);
GotRes := FDummyContext.ReadUnsignedInt(RegisterLoc(2), SizeVal(a), GotUInt);
CheckUIntRes('unsigned Reg readsize='+IntToStr(a), ExpIntVal);
FMemReader.RegisterSizes[2] := a;
GotRes := FMemManager.ReadUnsignedInt(RegisterLoc(2), SizeVal(ReadSize), GotUInt);
GotRes := FDummyContext.ReadUnsignedInt(RegisterLoc(2), SizeVal(ReadSize), GotUInt);
CheckUIntRes('unsigned Reg regsize'+IntToStr(a), ExpIntVal);
end;
GotRes := FMemManager.ReadUnsignedInt(ConstLoc(QWord(ExpIntVal)), SizeVal(ReadSize), GotUInt);
GotRes := FDummyContext.ReadUnsignedInt(ConstLoc(QWord(ExpIntVal)), SizeVal(ReadSize), GotUInt);
CheckUIntRes('unsigned const (pre-expanded)', ExpIntVal);
//////
// Address
GotRes := FMemManager.ReadAddress(TargetLoc(TDbgPtr(@Data)), SizeVal(ReadSize), GotAddr);
GotRes := FDummyContext.ReadAddress(TargetLoc(TDbgPtr(@Data)), SizeVal(ReadSize), GotAddr);
CheckAddrRes('addr target', ExpIntVal);
GotRes := FMemManager.ReadAddress(SelfLoc(@Data), SizeVal(ReadSize), GotAddr);
GotRes := FDummyContext.ReadAddress(SelfLoc(@Data), SizeVal(ReadSize), GotAddr);
CheckAddrRes('addr self', ExpIntVal);
FMemReader.RegisterSizes[2] := ReadSize;
GotRes := FMemManager.ReadAddress(RegisterLoc(2), SizeVal(ReadSize), GotAddr);
GotRes := FDummyContext.ReadAddress(RegisterLoc(2), SizeVal(ReadSize), GotAddr);
CheckAddrRes('addr Reg ', ExpIntVal);
for a := ReadSize+1 to 8 do begin
// expanded
FMemReader.RegisterSizes[2] := ReadSize;
GotRes := FMemManager.ReadAddress(RegisterLoc(2), SizeVal(a), GotAddr);
GotRes := FDummyContext.ReadAddress(RegisterLoc(2), SizeVal(a), GotAddr);
CheckAddrRes('addr Reg readsize='+IntToStr(a), ExpIntVal);
FMemReader.RegisterSizes[2] := a;
GotRes := FMemManager.ReadAddress(RegisterLoc(2), SizeVal(ReadSize), GotAddr);
GotRes := FDummyContext.ReadAddress(RegisterLoc(2), SizeVal(ReadSize), GotAddr);
CheckAddrRes('addr Reg regsize'+IntToStr(a), ExpIntVal);
end;
GotRes := FMemManager.ReadAddress(ConstLoc(QWord(ExpIntVal)), SizeVal(ReadSize), GotAddr);
GotRes := FDummyContext.ReadAddress(ConstLoc(QWord(ExpIntVal)), SizeVal(ReadSize), GotAddr);
CheckAddrRes('addr const (pre-expanded)', ExpIntVal);
//////
// Address
GotAddr := FMemManager.ReadAddress(TargetLoc(TDbgPtr(@Data)), SizeVal(ReadSize));
GotAddr := FDummyContext.ReadAddress(TargetLoc(TDbgPtr(@Data)), SizeVal(ReadSize));
GotRes := isValidLoc(GotAddr);
CheckAddrRes('addr target', ExpIntVal);
GotAddr := FMemManager.ReadAddress(SelfLoc(@Data), SizeVal(ReadSize));
GotAddr := FDummyContext.ReadAddress(SelfLoc(@Data), SizeVal(ReadSize));
GotRes := isValidLoc(GotAddr);
CheckAddrRes('addr self', ExpIntVal);
FMemReader.RegisterSizes[2] := ReadSize;
GotAddr := FMemManager.ReadAddress(RegisterLoc(2), SizeVal(ReadSize));
GotAddr := FDummyContext.ReadAddress(RegisterLoc(2), SizeVal(ReadSize));
GotRes := isValidLoc(GotAddr);
CheckAddrRes('addr Reg ', ExpIntVal);
for a := ReadSize+1 to 8 do begin
// expanded
FMemReader.RegisterSizes[2] := ReadSize;
GotAddr := FMemManager.ReadAddress(RegisterLoc(2), SizeVal(a));
GotAddr := FDummyContext.ReadAddress(RegisterLoc(2), SizeVal(a));
GotRes := isValidLoc(GotAddr);
CheckAddrRes('addr Reg readsize='+IntToStr(a), ExpIntVal);
FMemReader.RegisterSizes[2] := a;
GotAddr := FMemManager.ReadAddress(RegisterLoc(2), SizeVal(ReadSize));
GotAddr := FDummyContext.ReadAddress(RegisterLoc(2), SizeVal(ReadSize));
GotRes := isValidLoc(GotAddr);
CheckAddrRes('addr Reg regsize'+IntToStr(a), ExpIntVal);
end;
GotAddr := FMemManager.ReadAddress(ConstLoc(QWord(ExpIntVal)), SizeVal(ReadSize));
GotAddr := FDummyContext.ReadAddress(ConstLoc(QWord(ExpIntVal)), SizeVal(ReadSize));
GotRes := isValidLoc(GotAddr);
CheckAddrRes('addr const (pre-expanded)', ExpIntVal);
@ -246,21 +250,21 @@ begin
FCurrentTestName := 'Extended';
DataExt := 1.7722;
GotRes := FMemManager.ReadFloat(TargetLoc(TDbgPtr(@DataExt)), SizeVal(SizeOf(Extended)), GotExt);
GotRes := FDummyContext.ReadFloat(TargetLoc(TDbgPtr(@DataExt)), SizeVal(SizeOf(Extended)), GotExt);
AssertTrue(FCurrentTestName + 'Read OK', GotRes);
AssertEquals(FCurrentTestName + 'target not changed', 1.7722, DataExt);
AssertEquals(FCurrentTestName + 'Val', DataExt, GotExt);
FCurrentTestName := 'Double';
DataDouble := 1.7722;
GotRes := FMemManager.ReadFloat(TargetLoc(TDbgPtr(@DataDouble)), SizeVal(SizeOf(Double)), GotExt);
GotRes := FDummyContext.ReadFloat(TargetLoc(TDbgPtr(@DataDouble)), SizeVal(SizeOf(Double)), GotExt);
AssertTrue(FCurrentTestName + 'Read OK', GotRes);
AssertEquals(FCurrentTestName + 'target not changed', 1.7722, DataDouble);
AssertEquals(FCurrentTestName + 'Val', DataDouble, GotExt);
FCurrentTestName := 'Single';
DataSingle := 1.7722;
GotRes := FMemManager.ReadFloat(TargetLoc(TDbgPtr(@DataSingle)), SizeVal(SizeOf(Single)), GotExt);
GotRes := FDummyContext.ReadFloat(TargetLoc(TDbgPtr(@DataSingle)), SizeVal(SizeOf(Single)), GotExt);
AssertTrue(FCurrentTestName + 'Read OK', GotRes);
AssertEquals(FCurrentTestName + 'target not changed', 1.7722, DataSingle);
AssertEquals(FCurrentTestName + 'Val', DataSingle, GotExt);

View File

@ -373,13 +373,15 @@ var
sym: TFpValue;
ImgLoader: TTestLoaderSetupBasic;
TmpResVal: TFpValue;
Ctx: TFpDbgSimpleLocationContext;
begin
InitDwarf(TTestLoaderSetupBasic);
ImgLoader := TTestLoaderSetupBasic(FImageLoader);
//FMemReader.RegisterValues[5] := TDbgPtr(@ImgLoader.TestStackFrame.EndPoint);
FCurrentContext := FDwarfInfo.FindSymbolScope(0, 0, TTestSetupBasicProcMainAddr);
Ctx := TFpDbgSimpleLocationContext.Create(FMemManager, TTestSetupBasicProcMainAddr, 4, 0, 0);
FCurrentContext := FDwarfInfo.FindSymbolScope(Ctx, TTestSetupBasicProcMainAddr);
Ctx.ReleaseReference;
AssertTrue('got ctx', FCurrentContext <> nil);
sym := FCurrentContext.FindSymbol('VarEnum0');
@ -423,13 +425,16 @@ var
TmpResVal: TFpValue;
i: Integer;
s: String;
Ctx: TFpDbgSimpleLocationContext;
begin
InitDwarf(TTestLoaderSetupBasic);
ImgLoader := TTestLoaderSetupBasic(FImageLoader);
//FMemReader.RegisterValues[5] := TDbgPtr(@ImgLoader.TestStackFrame.EndPoint);
FCurrentContext := FDwarfInfo.FindSymbolScope(0, 0, TTestSetupBasicProcMainAddr);
Ctx := TFpDbgSimpleLocationContext.Create(FMemManager, TTestSetupBasicProcMainAddr, 4, 0, 0);
FCurrentContext := FDwarfInfo.FindSymbolScope(Ctx, TTestSetupBasicProcMainAddr);
Ctx.ReleaseReference;
AssertTrue('got ctx', FCurrentContext <> nil);
sym := FCurrentContext.FindSymbol('VarEnum0');
@ -488,12 +493,15 @@ var
TmpResVal: TFpValue;
i: Integer;
s: String;
Ctx: TFpDbgSimpleLocationContext;
begin
InitDwarf(TTestLoaderSetupArray);
ImgLoader := TTestLoaderSetupArray(FImageLoader);
//FMemReader.RegisterValues[5] := TDbgPtr(@ImgLoader.TestStackFrame.EndPoint);
FCurrentContext := FDwarfInfo.FindSymbolScope(0, 0, TTestSetupArrayProcMainAddr);
Ctx := TFpDbgSimpleLocationContext.Create(FMemManager, TTestSetupBasicProcMainAddr, 4, 0, 0);
FCurrentContext := FDwarfInfo.FindSymbolScope(Ctx, TTestSetupArrayProcMainAddr);
Ctx.ReleaseReference;
AssertTrue('got ctx', FCurrentContext <> nil);
sym := FCurrentContext.FindSymbol('VarDynIntArray');
@ -588,6 +596,7 @@ var
AddrExp: TDbgPtr;
s, s2: String;
ImgLoader: TTestLoaderSetup1;
Ctx: TFpDbgSimpleLocationContext;
begin
InitDwarf(TTestLoaderSetup1);
ImgLoader := TTestLoaderSetup1(FImageLoader);
@ -598,7 +607,9 @@ begin
ImgLoader.TestStackFrame.Int1 := -299;
ImgLoader.TestStackFrame.Obj1 := obj1;
try
FCurrentContext := FDwarfInfo.FindSymbolScope(0, 0, TTestSetup1ProcBarAddr);
Ctx := TFpDbgSimpleLocationContext.Create(FMemManager, TTestSetupBasicProcMainAddr, 4, 0, 0);
FCurrentContext := FDwarfInfo.FindSymbolScope(Ctx, TTestSetup1ProcBarAddr);
Ctx.ReleaseReference;
AssertTrue('got ctx', FCurrentContext <> nil);
sym := FCurrentContext.FindSymbol('Int1');
@ -1244,13 +1255,16 @@ var
sym: TFpValue;
ImgLoader: TTestLoaderSetupBasic;
TmpResVal: TFpValue;
Ctx: TFpDbgSimpleLocationContext;
begin
InitDwarf(TTestLoaderSetupBasic);
ImgLoader := TTestLoaderSetupBasic(FImageLoader);
//FMemReader.RegisterValues[5] := TDbgPtr(@ImgLoader.TestStackFrame.EndPoint);
FCurrentContext := FDwarfInfo.FindSymbolScope(0, 0, TTestSetupBasicProcMainAddr);
Ctx := TFpDbgSimpleLocationContext.Create(FMemManager, TTestSetupBasicProcMainAddr, 4, 0, 0);
FCurrentContext := FDwarfInfo.FindSymbolScope(Ctx, TTestSetupBasicProcMainAddr);
Ctx.ReleaseReference;
AssertTrue('got ctx', FCurrentContext <> nil);
sym := FCurrentContext.FindSymbol('VarEnum0');