From 14dc58d892f321ba7f1a0a47c4d906ebe2541db9 Mon Sep 17 00:00:00 2001 From: martin Date: Fri, 12 Feb 2021 18:31:09 +0000 Subject: [PATCH] FpDebug: test and helper apps, fixed some compile errors git-svn-id: trunk@64555 - --- components/fpdebug/app/fpd/fpdcommand.pas | 10 ++- .../app/fpdserver/debugthreadcommand.pas | 3 +- components/fpdebug/test/FpTest.lpi | 21 ++++++- .../fpdebug/test/dwarfviewer/dwarfviewer.lpi | 22 +++---- components/fpdebug/test/dwarfviewer/unit1.pas | 2 +- components/fpdebug/test/testmemmanager.pas | 62 ++++++++++--------- components/fpdebug/test/testtypeinfo.pas | 26 ++++++-- 7 files changed, 91 insertions(+), 55 deletions(-) diff --git a/components/fpdebug/app/fpd/fpdcommand.pas b/components/fpdebug/app/fpd/fpdcommand.pas index ef92019173..7ddd9cac02 100644 --- a/components/fpdebug/app/fpd/fpdcommand.pas +++ b/components/fpdebug/app/fpd/fpdcommand.pas @@ -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; diff --git a/components/fpdebug/app/fpdserver/debugthreadcommand.pas b/components/fpdebug/app/fpdserver/debugthreadcommand.pas index 444da12919..19b9422506 100644 --- a/components/fpdebug/app/fpdserver/debugthreadcommand.pas +++ b/components/fpdebug/app/fpdserver/debugthreadcommand.pas @@ -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 diff --git a/components/fpdebug/test/FpTest.lpi b/components/fpdebug/test/FpTest.lpi index b56547421e..b68b98ec19 100644 --- a/components/fpdebug/test/FpTest.lpi +++ b/components/fpdebug/test/FpTest.lpi @@ -15,8 +15,27 @@ - + + + + + + + + + + + + + + + + + + + + diff --git a/components/fpdebug/test/dwarfviewer/dwarfviewer.lpi b/components/fpdebug/test/dwarfviewer/dwarfviewer.lpi index abefac784e..5cb809bdbe 100644 --- a/components/fpdebug/test/dwarfviewer/dwarfviewer.lpi +++ b/components/fpdebug/test/dwarfviewer/dwarfviewer.lpi @@ -1,11 +1,13 @@ - + + + + - <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"/> diff --git a/components/fpdebug/test/dwarfviewer/unit1.pas b/components/fpdebug/test/dwarfviewer/unit1.pas index 9058b8aea2..6725da2c97 100644 --- a/components/fpdebug/test/dwarfviewer/unit1.pas +++ b/components/fpdebug/test/dwarfviewer/unit1.pas @@ -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; diff --git a/components/fpdebug/test/testmemmanager.pas b/components/fpdebug/test/testmemmanager.pas index 6a0558d83a..b93a30ff98 100644 --- a/components/fpdebug/test/testmemmanager.pas +++ b/components/fpdebug/test/testmemmanager.pas @@ -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); diff --git a/components/fpdebug/test/testtypeinfo.pas b/components/fpdebug/test/testtypeinfo.pas index 03d8c21203..e583804882 100644 --- a/components/fpdebug/test/testtypeinfo.pas +++ b/components/fpdebug/test/testtypeinfo.pas @@ -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');