Skip to content

Commit

Permalink
Added function data cache to improve conditional breakpoint evaluation
Browse files Browse the repository at this point in the history
  • Loading branch information
WheretIB committed May 30, 2020
1 parent 755161c commit 9602f23
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
23 changes: 23 additions & 0 deletions LuaDkmDebuggerComponent/Bytecode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,29 @@ public void ReadLocals(DkmProcess process, int instructionPointer)
}
}

public void UpdateLocals(DkmProcess process, int instructionPointer)
{
if (locals == null)
ReadLocals(process, -1);

activeLocals.Clear();

for (int i = 0; i < localVariableSize; i++)
{
LuaLocalVariableData local = locals[i];

if (i < argumentCount || instructionPointer == -1)
{
activeLocals.Add(local);
}
else
{
if (instructionPointer >= local.lifetimeStartInstruction && instructionPointer < local.lifetimeEndInstruction)
activeLocals.Add(local);
}
}
}

public void ReadLocalFunctions(DkmProcess process)
{
if (localFunctions != null)
Expand Down
22 changes: 19 additions & 3 deletions LuaDkmDebuggerComponent/RemoteComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ internal class LuaRemoteProcessData : DkmDataItem
public bool pauseBreakpoints = false;

public DkmStepper activeStepper = null;

public Dictionary<ulong, LuaFunctionData> functionDataCache = new Dictionary<ulong, LuaFunctionData>();
}

public class RemoteComponent : IDkmProcessExecutionNotification, IDkmRuntimeInstanceLoadCompleteNotification, IDkmCustomMessageForwardReceiver, IDkmRuntimeBreakpointReceived, IDkmRuntimeMonitorBreakpointHandler, IDkmRuntimeStepper, IDkmLanguageConditionEvaluator
Expand Down Expand Up @@ -552,6 +554,7 @@ void IDkmLanguageConditionEvaluator.EvaluateCondition(DkmEvaluationBreakpointCon
LuaFunctionCallInfoData callInfoData = new LuaFunctionCallInfoData();

callInfoData.ReadFrom(process, callInfoAddress); // TODO: cache?

callInfoData.ReadFunction(process);

if (callInfoData.func.extendedType != LuaExtendedType.LuaFunction)
Expand All @@ -567,7 +570,21 @@ void IDkmLanguageConditionEvaluator.EvaluateCondition(DkmEvaluationBreakpointCon

LuaClosureData closureData = currCallLuaFunction.value;

LuaFunctionData functionData = closureData.ReadFunction(process);
LuaFunctionData functionData = null;

if (processData.functionDataCache.ContainsKey(closureData.functionAddress))
{
functionData = processData.functionDataCache[closureData.functionAddress];
}
else
{
functionData = closureData.ReadFunction(process);

functionData.ReadUpvalues(process);
functionData.ReadLocals(process, -1);

processData.functionDataCache.Add(closureData.functionAddress, functionData);
}

// Possible in bad break locations
if (callInfoData.savedInstructionPointerAddress < functionData.codeDataAddress)
Expand All @@ -584,8 +601,7 @@ void IDkmLanguageConditionEvaluator.EvaluateCondition(DkmEvaluationBreakpointCon
// If the call was already made, savedpc will be offset by 1 (return location)
int prevInstructionPointer = currInstructionPointer == 0 ? 0 : (int)currInstructionPointer - 1;

functionData.ReadUpvalues(process);
functionData.ReadLocals(process, prevInstructionPointer);
functionData.UpdateLocals(process, prevInstructionPointer);

ExpressionEvaluation evaluation = new ExpressionEvaluation(process, functionData, callInfoData.stackBaseAddress, closureData);

Expand Down

0 comments on commit 9602f23

Please sign in to comment.