From 0063164c7775058090c03f434449ceb7585162e7 Mon Sep 17 00:00:00 2001 From: LPeter1997 Date: Fri, 20 Sep 2024 16:06:30 +0200 Subject: [PATCH] Update InstrumentationWeaver.cs --- src/Draco.Coverage/InstrumentationWeaver.cs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/Draco.Coverage/InstrumentationWeaver.cs b/src/Draco.Coverage/InstrumentationWeaver.cs index 6e7089bd2..fd77cb102 100644 --- a/src/Draco.Coverage/InstrumentationWeaver.cs +++ b/src/Draco.Coverage/InstrumentationWeaver.cs @@ -320,11 +320,19 @@ private Instruction AddInstrumentationCode(ILProcessor ilProcessor, Instruction private void PatchExceptionHandler(ExceptionHandler exceptionHandler, IReadOnlyDictionary jumpTargetPatches) { - this.PatchJumpTarget(exceptionHandler.TryStart, jumpTargetPatches); - this.PatchJumpTarget(exceptionHandler.TryEnd, jumpTargetPatches); - this.PatchJumpTarget(exceptionHandler.HandlerStart, jumpTargetPatches); - this.PatchJumpTarget(exceptionHandler.HandlerEnd, jumpTargetPatches); - if (exceptionHandler.FilterStart is not null) this.PatchJumpTarget(exceptionHandler.FilterStart, jumpTargetPatches); + exceptionHandler.TryStart = GetPatchedJumpTarget(exceptionHandler.TryStart); + exceptionHandler.TryEnd = GetPatchedJumpTarget(exceptionHandler.TryEnd); + exceptionHandler.HandlerStart = GetPatchedJumpTarget(exceptionHandler.HandlerStart); + exceptionHandler.HandlerEnd = GetPatchedJumpTarget(exceptionHandler.HandlerEnd); + exceptionHandler.FilterStart = GetPatchedJumpTarget(exceptionHandler.FilterStart); + + Instruction? GetPatchedJumpTarget(Instruction? instruction) + { + if (instruction is null) return null; + return jumpTargetPatches.TryGetValue(instruction.Offset, out var newTarget) + ? newTarget + : instruction; + } } private void PatchJumpTarget(Instruction instruction, IReadOnlyDictionary jumpTargetPatches)