FpDebug: Refactor TFpDbgInfoCallContext (add "AddParam" / remove Dbg-Process from "CreateParamSymbol")

This commit is contained in:
Martin 2022-06-19 12:18:30 +02:00
parent bba0a43742
commit ae8bbb1cd6
3 changed files with 49 additions and 21 deletions

View File

@ -10,7 +10,7 @@ uses
FpdMemoryTools,
FpDbgDwarfDataClasses,
FpDbgDwarf,
FpDbgClasses;
FpDbgClasses, FpErrorMessages;
type
{ TFpSymbolDwarfFunctionResult }
@ -28,8 +28,17 @@ type
{ TFpDbgInfoCallContext }
TFpDbgInfoCallContext = class(TFpDbgAbstractCallContext)
private
FDbgProcess: TDbgProcess;
FLastError: TFpError;
public
function CreateParamSymbol(AParamIndex: Integer; ASymbolType: TFpSymbol; ADbgProcess: TDbgProcess; AName: String = ''): TFpValue; virtual;
constructor Create(const ABaseContext: TFpDbgLocationContext;
AMemReader: TFpDbgMemReaderBase;
AMemConverter: TFpDbgMemConvertor;
ADbgProcess: TDbgProcess);
function CreateParamSymbol(AParamIndex: Integer; ASymbolType: TFpSymbol; AName: String = ''): TFpValue; virtual;
function AddParam(AParamIndex: Integer; AParamSymbolType: TFpSymbol; AValue: TFpValue): Boolean;
property LastError: TFpError read FLastError;
end;
implementation
@ -58,13 +67,21 @@ end;
{ TFpDbgInfoCallContext }
constructor TFpDbgInfoCallContext.Create(
const ABaseContext: TFpDbgLocationContext; AMemReader: TFpDbgMemReaderBase;
AMemConverter: TFpDbgMemConvertor; ADbgProcess: TDbgProcess);
begin
inherited Create(ABaseContext, AMemReader, AMemConverter);
FDbgProcess := ADbgProcess;
end;
function TFpDbgInfoCallContext.CreateParamSymbol(AParamIndex: Integer;
ASymbolType: TFpSymbol; ADbgProcess: TDbgProcess; AName: String): TFpValue;
ASymbolType: TFpSymbol; AName: String): TFpValue;
var
ParameterMemLocation: TFpDbgMemLocation;
ParamSymbol: TFpSymbol;// TFpSymbolDwarfFunctionResult;
begin
ParameterMemLocation := ADbgProcess.CallParamDefaultLocation(AParamIndex);
ParameterMemLocation := FDbgProcess.CallParamDefaultLocation(AParamIndex);
if AName = '' then
AName := ASymbolType.Name;
ParamSymbol := TFpSymbolDwarfFunctionResult.Create(AName, ParameterMemLocation, ASymbolType.TypeInfo);
@ -76,5 +93,21 @@ begin
TFpValueDwarf(Result).Context := Self;
end;
function TFpDbgInfoCallContext.AddParam(AParamIndex: Integer;
AParamSymbolType: TFpSymbol; AValue: TFpValue): Boolean;
var
ParamSymbol: TFpValue;
begin
Result := False;
ParamSymbol := CreateParamSymbol(AParamIndex, AParamSymbolType);
try
ParamSymbol.AsCardinal := AValue.AsCardinal;
Result := not IsError(ParamSymbol.LastError);
FLastError := ParamSymbol.LastError;
finally
ParamSymbol.ReleaseReference;
end;
end;
end.

View File

@ -1939,7 +1939,7 @@ function TDbgController.Call(const FunctionAddress: TFpDbgMemLocation;
var
Context: TFpDbgInfoCallContext;
begin
Context := TFpDbgInfoCallContext.Create(ABaseContext, AMemReader, AMemConverter);
Context := TFpDbgInfoCallContext.Create(ABaseContext, AMemReader, AMemConverter, FCurrentProcess);
Context.AddReference;
InitializeCommand(TDbgControllerCallRoutineCmd.Create(self, FunctionAddress, Context));
Result := Context;

View File

@ -781,7 +781,7 @@ function TFpThreadWorkerEvaluate.DoWatchFunctionCall(
var
FunctionSymbolData, FunctionSymbolType, FunctionResultSymbolType,
TempSymbol: TFpSymbol;
ParamSymbol, ExprParamVal: TFpValue;
ExprParamVal: TFpValue;
ProcAddress: TFpDbgMemLocation;
FunctionResultDataSize: TFpDbgValueSize;
ParameterSymbolArr: array of TFpSymbol;
@ -903,20 +903,16 @@ begin
try
for i := 0 to High(ParameterSymbolArr) do begin
ParamSymbol := CallContext.CreateParamSymbol(i, ParameterSymbolArr[i], FDebugger.FDbgController.CurrentProcess);
try
if (ASelfValue <> nil) and (i = 0) then
ParamSymbol.AsCardinal := ASelfValue.AsCardinal
ExprParamVal := ASelfValue
else
ParamSymbol.AsCardinal := AParams.Items[i + ItemsOffs].ResultValue.AsCardinal;
if IsError(ParamSymbol.LastError) then begin
ExprParamVal := AParams.Items[i + ItemsOffs].ResultValue;
if not CallContext.AddParam(i, ParameterSymbolArr[i], ExprParamVal) then begin
DebugLn('Internal error for arg %d ', [i]);
AnError := ParamSymbol.LastError;
AnError := CallContext.LastError;
exit;
end;
finally
ParamSymbol.ReleaseReference;
end;
end;
FDebugger.FDbgController.ProcessLoop;
@ -927,8 +923,7 @@ begin
exit;
end;
AResult := CallContext.CreateParamSymbol(-1, FunctionSymbolType,
FDebugger.FDbgController.CurrentProcess, FunctionSymbolData.Name);
AResult := CallContext.CreateParamSymbol(-1, FunctionSymbolType, FunctionSymbolData.Name);
Result := AResult <> nil;
finally
CallContext.ReleaseReference;