microsoft / microsoft/CLRInstrumentationEngine
Raw profiler hook fails because of a null ref
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 102
- Forks
- 52
- Avg merge
- 13h 11m
- Merged PRs (30d)
- 6
Description
This is somewhat relate to https://github.com/microsoft/CLRInstrumentationEngine/issues/370, as it seems impossible to test them separately, but I believe it a separate issue.
It seems if a raw profiler chooses to rewrite a method but it hasn't been rewritten by an instrumentation method then an null ref will occur, or rather the functions will start to return fail HRESULTs because of a null ref.
For an existing method that has been instrumented by the raw profiler but not an instrumentation method CCorProfilerInfoWrapper::GetILFunctionBody will call pMethodInfo->GetIntermediateRenderedFunctionBody. This because pMethodInfo->IsInstrumented() has been set when CMethodInfo::SetFinalRenderedFunctionBody was called.
This means that we're in a state where m_bIsInstrumented is true, m_pIntermediateRenderedMethod is null and m_pFinalRenderedMethod is set to a valid method body.
So, our CMethodInfo has a valid method body, but I'm not sure what the correct way to retrieve it.
One possible fix is to update CMethodInfo::SetFinalRenderedFunctionBody so that it sets m_pIntermediateRenderedMethod if it is not already set. I believe this works, but can't test it properly because of the other issue: https://github.com/robertpi/CLRInstrumentationEngine/commit/22b96b56ec69b1cdb74e9d0d5f3a73169385a923#diff-9025cfc4efbe6666f69f6103e8d4aca595e5107e7c0ec46d644b3f34345717c9R1314
There maybe other better ways to fix this.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at CCorProfilerInfoWrapper::GetILFunctionBody and trace the CMethodInfo state after SetFinalRenderedFunctionBody, especially the relationship between m_bIsInstrumented, m_pIntermediateRenderedMethod, and m_pFinalRenderedMethod. Compare the proposed SetFinalRenderedFunctionBody change with issue 370 and the referenced commit. Done means raw-profiler rewriting no longer produces a null reference or fail HRESULT and retrieves the valid method body.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100