Microsoft MVP성태의 닷넷 이야기
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
 

ICorProfilerInfo::GetILToNativeMapping 메서드가 0x80131358을 반환하는 경우

아래의 예제 코드가 있음에도 불구하고,

How do you map a native to IL instruction pointer in-process
; http://stackoverflow.com/questions/198754/how-do-you-map-a-native-to-il-instruction-pointer-in-process

제 경우에는 GetILToNativeMapping 메서드를 아무리 호출해도 0x80131358 값만을 반환하는 군요. ^^;

ULONG32 cNeedMap = 1024;
COR_DEBUG_IL_TO_NATIVE_MAP zeroBuf[1024];

cNeedMap = 0;
hr = pInfo->GetILToNativeMapping(funcId, 0, &cNeedMap, NULL);

// hr == 0x80131358

Error Lookup 프로그램에서 0x80131358 값이 뭔지 조회해도 그런 값을 찾을 수 없다고 나옵니다.

그러다가, 혹시 SSCLI에서 이 답을 구할 수 도 있지 않을까 싶었는데요.

shared-source-cli-2.0 / clr / src / vm / proftoeeinterfaceimpl.cpp
; https://github.com/gbarnett/shared-source-cli-2.0/blob/master/clr/src/vm/proftoeeinterfaceimpl.cpp

GetILToNativeMapping 구현 코드에서 오류로 인해 중간에 return 하는 것을 보니 답이 나옵니다. 바로 CORPROF_E_JITMAPS_NOT_ENABLED의 값이었던 것입니다.

2979 /* 
2980  * GetILToNativeMapping returns a map from IL offsets to native 
2981  * offsets for this code. An array of COR_DEBUG_IL_TO_NATIVE_MAP 
2982  * structs will be returned, and some of the ilOffsets in this array 
2983  * may be the values specified in CorDebugIlToNativeMappingTypes. 
2984  */ 
2985 HRESULT ProfToEEInterfaceImpl::GetILToNativeMapping( 
2986             /* [in] */  CodeID codeId, 
2987             /* [in] */  ULONG32 cMap, 
2988             /* [out] */ ULONG32 *pcMap, 
2989             /* [out, size_is(cMap), length_is(*pcMap)] */ 
2990                 COR_DEBUG_IL_TO_NATIVE_MAP map[]) 
2991 { 
2992     CONTRACTL 
2993     { 
2994         SO_NOT_MAINLINE; 
2995         THROWS;                     // MethodDesc::FindOrCreateInstantiationAtObject throws 
2996         GC_TRIGGERS;                // MethodDesc::FindOrCreateInstantiationAtObject triggers 
2997     } CONTRACTL_END; 
2998 
 
2999     LOG((LF_CORPROF, LL_INFO1000, "**PROF: GetILToNativeMapping 0x%p.\n", codeId)); 
3000      
3001     ENSURE_CALLBACK_STATE_FLAGS_SET(COR_PRF_CALLBACKSTATE_INCALLBACK); 
3002      
3003     // If JIT maps are not enabled, then we can't provide it 
3004     if (!CORProfilerJITMapEnabled()) 
3005         return (CORPROF_E_JITMAPS_NOT_ENABLED); 
3006 
 
3007 #ifdef DEBUGGING_SUPPORTED 
3008     // Cast to proper type 
3009     MethodDesc *pMD = CodeIDToMethodDesc(codeId); 
3010 
 
3011     // If the code is generic, then GetCodeInfo is not really supported and may not give 
3012     // accurate results.  This is better than always failing, 
3013     // though we may prejudice profiling by which 
3014     // copy of the code we return, so we just return none. 
3015     if (pMD->HasClassOrMethodInstantiation() && pMD->IsTypicalMethodDefinition()) 
3016         pMD = pMD->FindOrCreateInstantiationAtObject();  // Can we pass allowCreate=FALSE to make this no trigger? 
3017 
 
3018     return (g_pDebugInterface->GetILToNativeMapping(pMD, cMap, pcMap, map)); 
3019 #else 
3020     return E_NOTIMPL; 
3021 #endif 
3022 } 

이 값의 정의는 Visual C++의 CorError.h 헤더 파일에서 찾을 수 있습니다.

#define CORPROF_E_JITMAPS_NOT_ENABLED EMAKEHR(0x1358)

CORPROF_E_JITMAPS_NOT_ENABLED의 원인은 .NET Profiler를 만져본 분들이라면 금방 눈치챌 수 있습니다. .NET Profiler는 callback 이벤트를 받을 유형을 지정할 수가 있는데요. 제 경우에는 해당 옵션을 활성화시키지 않았기 때문이었습니다. 그 옵션의 이름은 COR_PRF_MONITOR::COR_PRF_ENABLE_JIT_MAPS입니다.

COR_PRF_MONITOR Enumeration
; https://docs.microsoft.com/en-us/dotnet/framework/unmanaged-api/profiling/cor-prf-monitor-enumeration

재미있는 것은 문서의 내용입니다. 위의 글에 보면 COR_PRF_ENABLE_JIT_MAPS 옵션에 다음과 같은 내용이 있습니다.

Deprecated.
Allows the profiler to obtain IL-to-native maps by using GetILToNativeMapping. Starting with the .NET Framework 2.0, the runtime always tracks IL-to-native maps; therefore, this flag is always considered to be set.


하지만, 문서의 내용과는 달리 .NET 2.0 이후에도 여전히 해당 옵션을 명시적으로 설정해줘야 하는 것입니다. 결국, 다음과 같이 ICorProfilerInfo2의 SetEventMask를 설정해 주는 것으로 문제 해결!

m_dwEventMask = ...;
m_dwEventMask |= COR_PRF_ENABLE_JIT_MAPS;

m_pICorProfilerInfo2->SetEventMask(m_dwEventMask);




[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]







[최초 등록일: ]
[최종 수정일: 7/17/2021]

Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
by SeongTae Jeong, mailto:techsharer at outlook.com

비밀번호

댓글 작성자
 




... 121  122  123  124  125  126  127  128  129  130  131  132  133  [134]  135  ...
NoWriterDateCnt.TitleFile(s)
1704정성태7/2/201421618.NET Framework: 447. w3wp.exe AppPool 재생(recycle)하는 방법 정리
1703정성태7/2/201422463.NET Framework: 446. Assembly.Load를 이용해 GAC에 등록된 어셈블리를 로드하는 방법 [1]파일 다운로드1
1702정성태6/23/201422167Phone: 11. Xamarin.Forms - 2. XAML을 이용한 페이지 개발파일 다운로드1
1701정성태6/23/201434349개발 환경 구성: 229. .NET Reflector + Reflexil 도구를 이용해 DLL 코드 변경 [4]
1700정성태6/23/201421169VS.NET IDE: 89. Visual Studio에서 기본 제공되는 성능 프로파일 [2]
1699정성태6/22/201423973Phone: 10. Xamarin.Forms - 1. Forms 시작하기 [2]파일 다운로드1
1698정성태6/22/201425947.NET Framework: 445. [부연 설명] 쉬운 C# 코드를 어럽게 이해하기 [2]
1697정성태6/22/201421231VS.NET IDE: 88. Visual Studio에서 직접 컴파일하는 IL 언어 확장 도구 - IL Support
1696정성태6/22/201421045.NET Framework: 444. clojure와 C#을 통해 이해하는 Sequence와 Vector 형식의 차이점 [1]
1695정성태6/21/201420041개발 환경 구성: 228. PowerShell ISE에서 (입력 기능이 있는) 콘솔 응용 프로그램을 시작하는 방법
1694정성태6/21/201421185개발 환경 구성: 227. 닷넷 용 ClojureCLR 개발환경 설정
1693정성태6/20/201421510개발 환경 구성: 226. Clojure 언어의 윈도우 개발환경 설정
1692정성태6/19/201432112오류 유형: 231. Visual Studio 2013 한글 버전 설치 오류 - The form specified for the subject is not one supported or known by the specified trust provider
1691정성태6/18/201427339개발 환경 구성: 225. 유닉스 계열의 tail 명령어가 제공되는 PowerShell [1]
1690정성태6/18/201430131개발 환경 구성: 224. DirectShow 예제 구하는 방법 [3]
1689정성태6/18/201426919오류 유형: 230. C++ 가변 인자 사용시 va_start 파라미터 전달 방법 [2]
1688정성태6/15/201420556오류 유형: 229. 갤럭시 노트 3 환경에서 Xamarin 앱 배포 충돌
1687정성태6/15/201426540개발 환경 구성: 223. PowerShell로 Visual Studio 빌드 스크립트 작성파일 다운로드1
1686정성태6/12/201424264Windows: 96. 윈도우 8 - 그림 암호를 이용해 로그인 시 지연 현상을 해결하는 방법 [1]
1685정성태6/10/201430990.NET Framework: 443. 자바 8과 C#의 람다(Lambda) 지원에 대한 비교 [12]
1684정성태6/9/201441129.NET Framework: 442. C# - 시스템의 CPU 사용량 및 프로세스(EXE)의 CPU 사용량 알아내는 방법 [5]파일 다운로드1
1683정성태6/2/201420687오류 유형: 228. CLR4 보안 - yield 구문 내에서 SecurityCritical 메서드 사용 불가 [2]파일 다운로드1
1682정성태6/1/201425924.NET Framework: 441. .NET CLR4 보안 모델 - 3. CLR4 보안 모델에서의 APTCA 역할파일 다운로드2
1681정성태6/1/201421790.NET Framework: 440. .NET CLR4 보안 모델 - 2. 샌드박스(Sandbox)을 이용한 보안 [2]파일 다운로드1
1680정성태6/1/201421297.NET Framework: 439. .NET CLR4 보안 모델 - 1. "Security Level 2"란?파일 다운로드1
1679정성태5/31/201420407.NET Framework: 438. .NET CLR2 보안 모델에서의 APTCA 역할파일 다운로드1
... 121  122  123  124  125  126  127  128  129  130  131  132  133  [134]  135  ...