Skip to content

Commit 31b959b

Browse files
authored
[Dynamic Instrumentation] Fixed instrumentation error (InvalidProgramException) related retargeting of EH clauses (#5774)
## Summary of changes Fixed `InvalidProgramException` thrown due to malformed bytecode born from DI Line Probe instrumentation, discovered by Exploration Testing of Method + Line Probes. ## Reason for change When a customer chooses a line for instrumentation through DI, a bunch of bytecode is being placed in front of the chosen line, to capture the method state. When the original line was a target of an exception handling clauses (e.g the line was the beginning of a catch/finally blocks, the line was the end of a try block, etc) - in those cases, we retarget the exception handling pointers to point to the new bytecode being placed. The code that handled it missed two assignment: TryEnd and HandlerEnd. Meaning, when the target line was an end of finally/catch block or at the end of a try block, we missed fixing the pointers, resulting in `InvalidProgramException`. ## Implementation details Correctly assinging `TryEnd` & `HandlerEnd` EH clauses. ## Test coverage Four new tests were added, that previously were broken with `InvalidProgramException`: - `TryFinallyTest`. - `AsyncTryFinallyTest` - `TryCatchTest` - `AsyncTryCatchTest`
1 parent b5fd279 commit 31b959b

File tree

13 files changed

+1532
-3
lines changed

13 files changed

+1532
-3
lines changed

tracer/src/Datadog.Tracer.Native/debugger_method_rewriter.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2497,19 +2497,24 @@ void DebuggerMethodRewriter::AdjustExceptionHandlingClauses(ILInstr* pFromInstr,
24972497
{
24982498
if (ehClauses[ehIndex].m_pTryBegin == pFromInstr)
24992499
{
2500-
// TODO log
2500+
ehClauses[ehIndex].m_pTryBegin = pToInstr;
2501+
}
2502+
else if (ehClauses[ehIndex].m_pTryEnd == pFromInstr)
2503+
{
25012504
ehClauses[ehIndex].m_pTryEnd = pToInstr;
25022505
}
25032506

25042507
if (ehClauses[ehIndex].m_pHandlerBegin == pFromInstr)
25052508
{
2506-
// TODO log
25072509
ehClauses[ehIndex].m_pHandlerBegin = pToInstr;
25082510
}
2511+
else if (ehClauses[ehIndex].m_pHandlerEnd == pFromInstr)
2512+
{
2513+
ehClauses[ehIndex].m_pHandlerEnd = pToInstr;
2514+
}
25092515

25102516
if (ehClauses[ehIndex].m_pFilter == pFromInstr)
25112517
{
2512-
// TODO log
25132518
ehClauses[ehIndex].m_pFilter = pToInstr;
25142519
}
25152520
}

0 commit comments

Comments
 (0)